public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Sahitya Tummala <stummala@codeaurora.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>,
	Joel Becker <jlbec@evilplan.org>, Christoph Hellwig <hch@lst.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] configfs: Fix use-after-free when accessing sd->s_dentry
Date: Thu, 3 Jan 2019 08:48:10 +0000	[thread overview]
Message-ID: <20190103084810.GK2217@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1546503064-12695-1-git-send-email-stummala@codeaurora.org>

On Thu, Jan 03, 2019 at 01:41:04PM +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)
> 
> Signed-off-by: Sahitya Tummala <stummala@codeaurora.org>
> ---
>  fs/configfs/dir.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
> index 39843fa..a5906c5 100644
> --- a/fs/configfs/dir.c
> +++ b/fs/configfs/dir.c
> @@ -66,7 +66,7 @@ static void configfs_d_iput(struct dentry * dentry,
>  		 * 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);

Please, update the comment above as well - it refers the increment of
sd->s_count, which becomes stale.  I agree that the problem is real
and the fix is sane (and that's what should've been done in the first
place, back in "configfs: fix race between dentry put and lookup",
which has introduced that logics).

      reply	other threads:[~2019-01-03  8:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03  8:11 [PATCH] configfs: Fix use-after-free when accessing sd->s_dentry Sahitya Tummala
2019-01-03  8:48 ` Al Viro [this message]

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=20190103084810.GK2217@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=hch@lst.de \
    --cc=jlbec@evilplan.org \
    --cc=junxiao.bi@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stummala@codeaurora.org \
    /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