Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9180140pxu; Mon, 28 Dec 2020 08:34:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGb3fWffgYGwERnZsMeUjIztLpq3DXbI7g22w6D+pjiLnaBFZn7ahRNABUv3LMMk4upcs4 X-Received: by 2002:a17:906:2b1a:: with SMTP id a26mr23617403ejg.23.1609173253593; Mon, 28 Dec 2020 08:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173253; cv=none; d=google.com; s=arc-20160816; b=hXBUQUXFR/4pvCP6VeumRtY2qkQPTqLy4KepAaXv60CPOSqHWwdeKDDBWh7bDOQ0rh Z+5zBbouujaX4ljSsj7SYOH0pOOAm6V6KpHuBabokNOSoz4lu2z0zB9cVj1XhxnNO+v8 rkS3MpqNXYEoc09qsxCiwyLjC9xRNFtFi+/vMGCRrDxM3L7oj+7ldVv4Ur5Sm6Mpc7zO l28TDiZSM/ABjl0NMClCoxrrdi9zQxM33qSP0jT4zyzHUB+cIqKXxczJwaOlxQGppqd+ S3VdLkfzz9E80jncxRb6LzniOgjSlJWu5Rcjwkp9cO4DWSWj1aCL8rWhvOOH7iEwfP6i p24A== 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=DFod+FVDuXtkYTx9LdOzx1kuyrKVH8jv68pory5pcCo=; b=rrcMQpT1EWfi9aL8thsXuEyalBndRXUsCpVPPvK82h9B6wFy+59HsPzVexwvVkyJZ8 Cuk6OfW96W8b98Q9/zL3TK+n218ZKPrI9+B78o9Jxw7M8n0K8X0yiGT51rG2U5UgD9E6 +I+64ieiQgjFfkJcphmW/yHnfiHO+6S4xOiX4MkiysyvwZo7owrHXuTh4rLGYXQ+Wz2i CBNjRkbyvTEdAjX1/IJco0oz6c9WplHyynNq6a3woeN3prFlbxJuvISVEsIs/GZ0UqzD Itrh7g48X3uVq6WBkcJzWU9r2BXwB/hQ7jbR88DYJq4GBHZbqhXfQ0Kp9aB/6C3KGzBZ weTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1dz1IIkQ; 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 s23si18423207ejf.192.2020.12.28.08.33.50; Mon, 28 Dec 2020 08:34:13 -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=1dz1IIkQ; 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 S2633592AbgL1Q3h (ORCPT + 99 others); Mon, 28 Dec 2020 11:29:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:34638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730695AbgL1NHM (ORCPT ); Mon, 28 Dec 2020 08:07:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B403207C9; Mon, 28 Dec 2020 13:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160816; bh=8Rwy/Rs4ImkiFEX0hYOi5VDqlNDWf8hygiylf9soHH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1dz1IIkQtOo9S/sudVBQBuLvxASwOzImAHGxKIozJYDr4Yn3efr1Qwa0pmgHXIWhB y783UqR2gV2HghXY9ZPdKgTFvCt7t2mtaFKkkYrFnoQA5yYVLTqBk7sDwsBjaTSNV+ Vaodrf1KxS32sXPCOERJq9V9NwQodzmmiB9TraIk= 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.9 158/175] ceph: fix race in concurrent __ceph_remove_cap invocations Date: Mon, 28 Dec 2020 13:50:11 +0100 Message-Id: <20201228124900.903174927@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 @@ -927,12 +927,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)