Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9046672pxu; Mon, 28 Dec 2020 05:20:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJykxhBd4qxD4+ZJBY6iIF9zRa2E1wJBEes2B4XdEnrpWPkGih2XjYpaCj0Mh0VIYdf5D0ml X-Received: by 2002:a05:6402:3553:: with SMTP id f19mr28618733edd.129.1609161611015; Mon, 28 Dec 2020 05:20:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161611; cv=none; d=google.com; s=arc-20160816; b=MBz9fh38TWYgS7LemJHFtmLdUehi2e4xnXa6tl5/gmRJ5q5JCDFU1mkbAW6IzvlQdm wUXkEdJZqwQe/nTylj5D0SrxCxvzMALYAQj6RCW1kCJb2T5NOTMG8TVvYbOmUpse4zVr NO+KguAADxKQap01GuCO4p+gcofHKVikNz85H6UGafEwRcyJk3zlEKW1zpHLMcm5cLNh Xi+sdOyDtT1fKe63FuPcfQHjMly3pnJ18RwhC9tiXQeNj6whM/7faBihKTfgRO1jTyYK 3V0OMJjIe76WM4G0zo/TVsY5yvnlIxa5HAqx8/49jtDdHHQYjdrTtHkYR7FTa+IIOhD8 /lXQ== 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=naR0oYG9PMZ83DLdFoxMpDbjgHTAPzAF7aBA0xYHTYs=; b=TNX2+EUNOwet1/Nj5zzccv0x0DMLSSw3NoEmAIrfmOOPwT4lm3fmC/wQRWNdy1boNF PdiqPZZ2yy5vqgnNBOEWg8XWrF1yu9YZgqZKSojzUdGsqRD+V/wTZRlVB6/I7NVoXDuu BBtdlcN6Gy64ELlLdw65vnjhhOeJvGgbpZh68hhe/VqOu4rQ8dGxhRk1nNMuf/woD9mc xd0bsF5tpLurdNPXP/V8mGaZb1XaqpsE8XSbJP/KxhMJ0bBpuj0wRM5M5qy9Urfjrl6M Y8Hp2H+V5Lbn6U9F7T+ZltPinwsIAFTI7XNNZTr9e1duOh8cka7ZcZqmfbosNduDN48N cA6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yt4PdFOH; 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 n23si18277424ejr.321.2020.12.28.05.19.48; Mon, 28 Dec 2020 05:20:10 -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=Yt4PdFOH; 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 S2387467AbgL1NSJ (ORCPT + 99 others); Mon, 28 Dec 2020 08:18:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:46634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387455AbgL1NSG (ORCPT ); Mon, 28 Dec 2020 08:18:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E70F5208D5; Mon, 28 Dec 2020 13:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161445; bh=LUwe1fdi2pE1PUi3MMkn8G1Ehd6si62fatPzfHF8tNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yt4PdFOHYyRHT/Ik21nMzhrsAlqRu1SHF3wR6B0cC+9wq78sI07PkN6sKLgthp3j4 1dMnJUZ20wv4mb+I+a42s+ntDep7Zn9OvyuFyc2qp9Yk2dxKrZqN/vYPI6qr+2v3io m4kmb9Ii7xsNozbwdtS6BwJyu84nFCLBa5NHYdvA= 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 4.14 216/242] ceph: fix race in concurrent __ceph_remove_cap invocations Date: Mon, 28 Dec 2020 13:50:21 +0100 Message-Id: <20201228124915.302292923@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@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 @@ -929,12 +929,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)