Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6630409imu; Wed, 30 Jan 2019 19:21:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6IDzMfo6Hi7pEhlvxbVW1xLpQQo474Uh5UF4Gq38TDrMMouG2zotM/yXTqcWmQUCxYIJOT X-Received: by 2002:a63:504d:: with SMTP id q13mr30431917pgl.319.1548904887199; Wed, 30 Jan 2019 19:21:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548904887; cv=none; d=google.com; s=arc-20160816; b=niy8Cn2+PyYO9hWfSGhUtOkhKfz9FWLKNbeARtKzwnXZ0Nvn5iApF1jOnv08a7vfuT HHWAwVQkwCwTNxFA4bslZabMPB+BZcohUuf97Sig+OFeSeL2YZ0l8FQTXCzPg6USCYmC e5ZxgxBfRvw9ZC9lA463MpUt6STkBz3ikzVxc+ShK1atN91KRx0BvYJsFtUFYj3LocN2 9cdoaELVLuW5B4S2SIQfMayop9HLYWoWmGKbD7teOxsLVsj6K7+332ttmhVhRZLH8roP TidAgdYg+7O274sFBOTt27dQNiV5Ho4SWRSPOZydM0jRrrG8nPf7R1+hJ/emjOk8brTF Du0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dmarc-filter:dkim-signature:dkim-signature; bh=xt/XNiOkhYQIakbw1k/vZypg3xMMhV2oRcbBj5Nsm34=; b=fO72lKZqlfFSd1/F4W+I8TioNMEq0ZtRsAaNJ0Al2qrpU3TOqUVLPY/SUUqim29jSG kcCAyMTszgceh4b8DzJYTa31C5mx6ySyWy68Xo1vY+NYJPakHnEh0Weu8a8Bi889mdF5 NRMPh8QTu4dLm4jK4SGhwL+T8s89a0AO7yBj+M4FG3b3wB+zGIZwR8AgUPuBqHjIIoS5 XDPypodOFDmyA+tV8e/ZJCW1WJCPJzfFpWLbaSgHOcEI1sOM7eobSDlb9eYDqiT2XHqC BOtydhxzJXPyBSGJiuoFhcZcqUViZol+KuOGEFPj4j97kPwi8UgG3j00MgEqoEO5RKeg +YDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OryN5+08; dkim=pass header.i=@codeaurora.org header.s=default header.b=nx4HIoEJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t77si2142467pgb.51.2019.01.30.19.21.11; Wed, 30 Jan 2019 19:21:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OryN5+08; dkim=pass header.i=@codeaurora.org header.s=default header.b=nx4HIoEJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730796AbfAaDUe (ORCPT + 99 others); Wed, 30 Jan 2019 22:20:34 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:38600 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725535AbfAaDUe (ORCPT ); Wed, 30 Jan 2019 22:20:34 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 242C660C17; Thu, 31 Jan 2019 03:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1548904833; bh=NfvCSE4QRdgO2piosvYXvd9qsyd0QTthZBp4yxpJ0Io=; h=Date:From:To:Subject:References:In-Reply-To:From; b=OryN5+088/2+PS3ObLVOJveqKV227wfzJ4uBgXPQwiV0D8Q1OO0RLLwXzdxAkzGRH /QTL7pek4Z2jVcZEq4Og2Iu323lMxhrT9Lg+1q1g4nPK+VAS3rqUJxLeVx20AY57zi iPNfXx5pbduXcfvT83XwUJLTQmZyY2pGM54wW/Q0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3984660C02; Thu, 31 Jan 2019 03:20:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1548904820; bh=NfvCSE4QRdgO2piosvYXvd9qsyd0QTthZBp4yxpJ0Io=; h=Date:From:To:Subject:References:In-Reply-To:From; b=nx4HIoEJ59K1nCBL9Jei4SWR6pgiRQcgzVx46INmvm8WNP4hA57uWL9km7qV+3ih/ liQ0fU2/YSQwfXT4zOwMShkq8SCFSsvNZBBdb25QkSERkG/f6g/SPugLaY/CSjHhjx yaPGEKMjxd5PidQWRzKiOKy5F0SvItJUqMPFypwk= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3984660C02 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org Date: Thu, 31 Jan 2019 08:50:11 +0530 From: Sahitya Tummala To: Junxiao Bi , Joel Becker , Christoph Hellwig , Al Viro , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] configfs: Fix use-after-free when accessing sd->s_dentry Message-ID: <20190131032011.GC7308@codeaurora.org> References: <1546514295-24818-1-git-send-email-stummala@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1546514295-24818-1-git-send-email-stummala@codeaurora.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Al, Can we merge this patch, if there are no further comments? Thanks, Sahitya. On Thu, Jan 03, 2019 at 04:48:15PM +0530, Sahitya Tummala wrote: > In the vfs_statx() context, during path lookup, the dentry gets > added to sd->s_dentry via configfs_attach_attr(). In the end, > vfs_statx() kills the dentry by calling path_put(), which invokes > configfs_d_iput(). Ideally, this dentry must be removed from > sd->s_dentry but it doesn't if the sd->s_count >= 3. As a result, > sd->s_dentry is holding reference to a stale dentry pointer whose > memory is already freed up. This results in use-after-free issue, > when this stale sd->s_dentry is accessed later in > configfs_readdir() path. > > This issue can be easily reproduced, by running the LTP test case - > sh fs_racer_file_list.sh /config > (https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/fs/racer/fs_racer_file_list.sh) > > Fixes: 76ae281f6307 ('configfs: fix race between dentry put and lookup') > Signed-off-by: Sahitya Tummala > --- > v2: > - update comments relevant to the code. > > fs/configfs/dir.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c > index 39843fa..f113101 100644 > --- a/fs/configfs/dir.c > +++ b/fs/configfs/dir.c > @@ -58,15 +58,14 @@ static void configfs_d_iput(struct dentry * dentry, > if (sd) { > /* Coordinate with configfs_readdir */ > spin_lock(&configfs_dirent_lock); > - /* Coordinate with configfs_attach_attr where will increase > - * sd->s_count and update sd->s_dentry to new allocated one. > - * Only set sd->dentry to null when this dentry is the only > - * sd owner. > + /* > + * Set sd->s_dentry to null only when this dentry is the > + * one that is going to be killed. > * If not do so, configfs_d_iput may run just after > * configfs_attach_attr and set sd->s_dentry to null > * even it's still in use. > */ > - if (atomic_read(&sd->s_count) <= 2) > + if (sd->s_dentry == dentry) > sd->s_dentry = NULL; > > spin_unlock(&configfs_dirent_lock); > -- > Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. > Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project. > -- -- Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.