From patchwork Tue Sep 29 11:00:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 263001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 331D0C4727C for ; Tue, 29 Sep 2020 12:24:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7F402076B for ; Tue, 29 Sep 2020 12:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601382271; bh=oFUnuwBODfm1xVNGIRhJSrXk9mqoYKZ92KDhQm6/BS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qyNQBoCoYiwoj43LIs/r6ZrgiMo/2SULuhuvofUztJMncOsG+XEu9+kpXzALOCXhh 8gbPqq9l87epTd9hAJFgyKd9TpEyp454ZV2AmobgxDAcvIBt9U4p16rlgkAEBXEyKf gomt/gWLSDRSSvd7uTg+SUrdJlaL1WEAfLMFwrow= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732336AbgI2MYG (ORCPT ); Tue, 29 Sep 2020 08:24:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:49220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729768AbgI2LfJ (ORCPT ); Tue, 29 Sep 2020 07:35:09 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5F04523C85; Tue, 29 Sep 2020 11:28:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378923; bh=oFUnuwBODfm1xVNGIRhJSrXk9mqoYKZ92KDhQm6/BS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K4QKLhovSbvy9KE92DoGizlbCOsJXkgcqR8FHk63aIY9MCMx5j/D0FQFWoXQgX0PB 1PW8jmOKXc/qo3Q1Sw3CvWuFHZT7nl8b0jGaE7ju7NtH9aXjCM5JjwVBHxk4zbjSuJ DZJcHAM0EWdhsXkkecz9YQ7NKF1rmno/S1wF1Gw0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Layton , Ilya Dryomov , Sasha Levin Subject: [PATCH 4.19 189/245] ceph: fix potential race in ceph_check_caps Date: Tue, 29 Sep 2020 13:00:40 +0200 Message-Id: <20200929105956.173144388@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105946.978650816@linuxfoundation.org> References: <20200929105946.978650816@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jeff Layton [ Upstream commit dc3da0461cc4b76f2d0c5b12247fcb3b520edbbf ] Nothing ensures that session will still be valid by the time we dereference the pointer. Take and put a reference. In principle, we should always be able to get a reference here, but throw a warning if that's ever not the case. Signed-off-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/caps.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index a2d4eed27f804..c0dbf8b7762b4 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2015,12 +2015,24 @@ ack: if (mutex_trylock(&session->s_mutex) == 0) { dout("inverting session/ino locks on %p\n", session); + session = ceph_get_mds_session(session); spin_unlock(&ci->i_ceph_lock); if (took_snap_rwsem) { up_read(&mdsc->snap_rwsem); took_snap_rwsem = 0; } - mutex_lock(&session->s_mutex); + if (session) { + mutex_lock(&session->s_mutex); + ceph_put_mds_session(session); + } else { + /* + * Because we take the reference while + * holding the i_ceph_lock, it should + * never be NULL. Throw a warning if it + * ever is. + */ + WARN_ON_ONCE(true); + } goto retry; } }