Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9095075pxu; Mon, 28 Dec 2020 06:31:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZJLJl1KBi4OGoVNB4BtL9R5s/NKPG9uwUCY0zMecS/ksH9JilxX09zQonIkxCy62MatKy X-Received: by 2002:a17:907:20f1:: with SMTP id rh17mr41931471ejb.147.1609165876246; Mon, 28 Dec 2020 06:31:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165876; cv=none; d=google.com; s=arc-20160816; b=SXMJxHaXm2LWxzqNGNnEKJLoBTvVHRTwL2PrNyXJcyjWCqGh++uAzEnhtnRY+b5jaL dRwYRFy4cYroRGwa3BehmzFZqYcVrFBwU6xjK+rjcehjMOkEcpiiOginFSGN5QjAmhmp RKpQ2zlbzP8812Ftix41nSwvYARYJ5r8vaSyWsFirpMFwVwmiQNjyxErY8WDo4e6mav3 1Zj2oVAh4I/i1LsGu4ywFAS0nLsJv4XO6DCybnHwMUX+nyQOZWnbv7SIYKJVkAW2czTv BtI3oDK8QqftBwuASdne4NJP7j9AkM0rYfZsxYGUYKwif6kIpnwDkjg5HwSTdxcuOo76 jcJA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0GLfs8RDsc8Ya8EfcQJiMSVSLvAfLvnh3bY6dvV1kbo=; b=PxhsDuquCvV7LqVgw2y/WeNKfA4lGbpAPNR3oCt78jANHKcwYk/cgKbl2AgbqpdwSm VMEQkAwIAQqJJ5JQhtVcghPxwWxxIwIvNCOZajkRQHGRMjJCuDz3BFddwcKUz4IqDrNd eM+y5eqjgSzeyHyexjV2zZAmjm60tsrEi7EEm28r0HPU1W9Jc47wrcx2xUWqQr/0gJpb LdbF5Yifs4K5jW8B5u0oEjvydQfKaQtcJgUTZc4EazjpZWibXtZMRLC//v0Uxdyd877I NSmWb5rvW81CU7gK1Q7qM+j/tOFY5lmlIlkt5aEosgPM9QhB1Ey6teMV7aqjJGPqhE+j 2TrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QIX6Yuaq; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si22200096eds.65.2020.12.28.06.30.54; Mon, 28 Dec 2020 06:31:16 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=QIX6Yuaq; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503349AbgL1O2z (ORCPT + 99 others); Mon, 28 Dec 2020 09:28:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:36736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502742AbgL1O2y (ORCPT ); Mon, 28 Dec 2020 09:28:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16B2E2242A; Mon, 28 Dec 2020 14:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165693; bh=N/PPTkCqRhjWsEqtCAkAjCHNL0w6L5yuCFGtV0jfwF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QIX6YuaqwLq80fmHwmIphyHiLHiaOrSkVX/Nvlh6iUqUnr8/sWIeIpeiGZzjme6aQ nMzdtg0l+xWzrD5jCVhxoRo1m/lcKnDaoVRvLkSxNPUcaTNTHIa47wGvE7+noMTN0i u5lbduUxa0cNkMx5lFdzMV20sJu9N7h3TBaE9518= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Layton , Luis Henriques , Ilya Dryomov Subject: [PATCH 5.10 622/717] ceph: fix race in concurrent __ceph_remove_cap invocations Date: Mon, 28 Dec 2020 13:50:20 +0100 Message-Id: <20201228125050.726538575@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luis Henriques commit e5cafce3ad0f8652d6849314d951459c2bff7233 upstream. A NULL pointer dereference may occur in __ceph_remove_cap with some of the callbacks used in ceph_iterate_session_caps, namely trim_caps_cb and remove_session_caps_cb. Those callers hold the session->s_mutex, so they are prevented from concurrent execution, but ceph_evict_inode does not. Since the callers of this function hold the i_ceph_lock, the fix is simply a matter of returning immediately if caps->ci is NULL. Cc: stable@vger.kernel.org URL: https://tracker.ceph.com/issues/43272 Suggested-by: Jeff Layton Signed-off-by: Luis Henriques Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Greg Kroah-Hartman --- fs/ceph/caps.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -1140,12 +1140,19 @@ void __ceph_remove_cap(struct ceph_cap * { struct ceph_mds_session *session = cap->session; struct ceph_inode_info *ci = cap->ci; - struct ceph_mds_client *mdsc = - ceph_sb_to_client(ci->vfs_inode.i_sb)->mdsc; + struct ceph_mds_client *mdsc; int removed = 0; + /* 'ci' being NULL means the remove have already occurred */ + if (!ci) { + dout("%s: cap inode is NULL\n", __func__); + return; + } + dout("__ceph_remove_cap %p from %p\n", cap, &ci->vfs_inode); + mdsc = ceph_inode_to_client(&ci->vfs_inode)->mdsc; + /* remove from inode's cap rbtree, and clear auth cap */ rb_erase(&cap->ci_node, &ci->i_caps); if (ci->i_auth_cap == cap) {