From: stummala@codeaurora.org
To: Junxiao Bi <junxiao.bi@oracle.com>,
Joel Becker <jlbec@evilplan.org>, Christoph Hellwig <hch@lst.de>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-kernel@vger.kernel.org, stummala@codeaurora.org
Subject: Re: [PATCH v2] configfs: Fix use-after-free when accessing sd->s_dentry
Date: Thu, 16 May 2019 18:27:53 +0530 [thread overview]
Message-ID: <0081e5c8083f5ed9f1c1e9b456739728@codeaurora.org> (raw)
In-Reply-To: <20190131032011.GC7308@codeaurora.org>
Hi Christoph, Al,
Can you please consider this patch for merging?
Thanks,
Sahitya.
On 2019-01-31 08:50, Sahitya Tummala wrote:
> 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 <stummala@codeaurora.org>
>> ---
>> 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.
>>
next prev parent reply other threads:[~2019-05-16 12:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-03 11:18 [PATCH v2] configfs: Fix use-after-free when accessing sd->s_dentry Sahitya Tummala
2019-01-31 3:20 ` Sahitya Tummala
2019-05-16 12:57 ` stummala [this message]
2019-05-17 8:23 ` Christoph Hellwig
2019-05-23 3:49 ` Sahitya Tummala
2019-05-28 6:11 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0081e5c8083f5ed9f1c1e9b456739728@codeaurora.org \
--to=stummala@codeaurora.org \
--cc=hch@lst.de \
--cc=jlbec@evilplan.org \
--cc=junxiao.bi@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).