Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp854900pxk; Thu, 17 Sep 2020 19:11:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbsdyrsKcAYmwT39rpYFF7Mf1l26rIaeBYTRCpSUeY5ZPkcKMSFegE5jYkPs9XVRIK7QES X-Received: by 2002:a17:906:8682:: with SMTP id g2mr33428158ejx.110.1600395115240; Thu, 17 Sep 2020 19:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600395115; cv=none; d=google.com; s=arc-20160816; b=Jg5BUdlmB/rZJggbXcVeCVlvmG/uOZyaUe2B9nPBC+xTTfbiysY938lR2JadZjg12L zaGfCq3f/RYAvJhXihdFXWPHz85ef9Qj40pjENSVB1CyzZL+I1Akseb154vcr6kSG+qp 8ZXctzHRrwpDn4HLpaxPEK1tR0TsCx/10FS/tK5SLw5Uwi97fV+f/MouvrWmL3/gcr/y K2Y9AXk5jqTwZISu2MwK0EHGLq7O+O/IDDY9t6FcvHcgJ9shPp4cv+SZxzyWR1uRyFZb FpzFl2G3tDjMzU9gUjMC2GR8tGR29hKiJUtjIJlKdLbstpNg48vWByRC54SY/yZzgiRA ap0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rmpxg9obQi7/i1X8o7Trp8PFPng0uTS0wOP3BCW00QE=; b=JQIHxdmE1V9eQyULeBNrncpiQN3DKRhffA+OS9vg4QFAPyp+d/FduUQpOoEAH9DSeh lekIRjKXRwN5UVgaucWAaSJXc4GC7UsU+4P7ghNCtcM/f6eRA6c0Is+a6QxETYK8M858 c1eG3iVuteX6R/TlUkJZvqYDP3tv8ii1CWQcJY50qBseF0BwrcOI5CO0rYSmECg7i7MA AzdpCmnm/p77jP4AdrvMHD8LCP6Uc/ZykdEGZ5NMLwv36JKqcivu7JfxFYfD69vOvlrY XW2Ra26hYufJdvcKh4XiRyNW9Qh1HeKxY+3h3kybBPkijIw0bTNacUAmqzFnrhx2UxfN uhkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2GtUpe1/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si1091696edv.438.2020.09.17.19.11.32; Thu, 17 Sep 2020 19:11:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="2GtUpe1/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgIRCHe (ORCPT + 99 others); Thu, 17 Sep 2020 22:07:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727280AbgIRCH3 (ORCPT ); Thu, 17 Sep 2020 22:07:29 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D5D21238E5; Fri, 18 Sep 2020 02:07:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394848; bh=Gj8OXTifKI0qrXicRK/yWep/4PdfhSThsuwHq6DVKVc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2GtUpe1/OOSQiG4kHGBnefSgdeeJPDM1ERS3xm6t0c/VzbXWknKVbadRcD6rAUS0M moY8uk5O2ZJiJAYMdhcdYKLWs4VE/O0i8l+F1MiGFKXG86dRL+jTEiKXaMTMwW6Z3j XXo10HPRaSM+9CX9wYGaEl+IgO0HDMMQJrCDgDKs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jeff Layton , Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 305/330] ceph: fix potential race in ceph_check_caps Date: Thu, 17 Sep 2020 22:00:45 -0400 Message-Id: <20200918020110.2063155-305-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 b2695919435e8..af563d73d252c 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2013,12 +2013,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; } } -- 2.25.1