linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Hillf Danton <dhillf@gmail.com>, Dave Jones <davej@redhat.com>,
	Greg Kroah-Hartman <greg@kroah.com>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: use after free in sysfs_find_dirent
Date: Sat, 16 Mar 2013 14:33:57 -0400	[thread overview]
Message-ID: <5144BB15.3020002@gmail.com> (raw)
In-Reply-To: <CACVXFVNCGBAYLbbpE1sBiXFNkJpRxVzY44y3Vok+GA9C0MKr3w@mail.gmail.com>

On 03/16/2013 11:58 AM, Ming Lei wrote:
> On Sat, Mar 16, 2013 at 11:22 PM, Ming Lei <tom.leiming@gmail.com> wrote:
>> On Sat, Mar 16, 2013 at 11:07 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
>>>
>>> Hi Ming,
>>>
>>> With your patch:
>>>
>>>
>>> [ 1525.874312] release_sysfs_dirent sysfs_dirent use after free: ptysb-uevent
>>
>> Sasha, thanks for your test.
>>
>> So is the oops always triggered on this node of 'ptysb-uevent' or the node name
>> is changed every time?
> 
> Also, we may dump stack on the release path with the below patch to see who
> did the ugly free.
> 
> --
> diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
> index 2fbdff6..993671d 100644
> --- a/fs/sysfs/dir.c
> +++ b/fs/sysfs/dir.c
> @@ -281,6 +281,12 @@ void release_sysfs_dirent(struct sysfs_dirent * sd)
>  	 */
>  	parent_sd = sd->s_parent;
> 
> +	if(!(sd->s_flags & SYSFS_FLAG_REMOVED)) {
> +		printk("%s sysfs_dirent use after free: %s-%s\n",
> +			__func__, parent_sd->s_name, sd->s_name);
> +		dump_stack();
> +	}
> +
>  	if (sysfs_type(sd) == SYSFS_KOBJ_LINK)
>  		sysfs_put(sd->s_symlink.target_sd);
>  	if (sysfs_type(sd) & SYSFS_COPY_NAME)
> @@ -962,6 +968,9 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns,
>  		int valid = !(pos->s_flags & SYSFS_FLAG_REMOVED) &&
>  			pos->s_parent == parent_sd &&
>  			hash == pos->s_hash;
> +		if (valid && (atomic_read(&pos->s_count) <= 1))
> +			printk("%s sysfs_dirent use after free: %s-%s\n",
> +				__func__, parent_sd->s_name, pos->s_name);
>  		sysfs_put(pos);
>  		if (!valid)
>  			pos = NULL;
> 

I don't think it shows what we want it to show thought:

[  327.416905] Pid: 10504, comm: trinity-child98 Tainted: G        W    3.9.0-rc2-next-20130315-sasha-00046-gecde602-dirty #301
[  327.418815] Call Trace:
[  327.419255]  [<ffffffff812f880e>] release_sysfs_dirent+0x4e/0x120
[  327.420595]  [<ffffffff812f89d2>] sysfs_dir_pos+0x92/0x130
[  327.421608]  [<ffffffff812f8b8d>] sysfs_readdir+0x11d/0x280
[  327.422562]  [<ffffffff8128b070>] ? SyS_ioctl+0xa0/0xa0
[  327.423441]  [<ffffffff8128b070>] ? SyS_ioctl+0xa0/0xa0
[  327.424314]  [<ffffffff8128b3e8>] vfs_readdir+0x78/0xc0
[  327.425263]  [<ffffffff8128b54c>] SyS_getdents+0x8c/0x110
[  327.426173]  [<ffffffff83d919d8>] tracesys+0xe1/0xe6


  reply	other threads:[~2013-03-16 18:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-07  5:28 use after free in sysfs_find_dirent Dave Jones
2013-03-07  5:33 ` sysfs_dir_cache slab corruption Dave Jones
2013-03-07  6:03   ` Greg Kroah-Hartman
2013-03-07  6:02 ` use after free in sysfs_find_dirent Greg Kroah-Hartman
2013-03-07  6:26   ` Dave Jones
2013-03-13 11:47     ` Ming Lei
2013-03-15  4:03     ` Sasha Levin
2013-03-15  5:04       ` Sasha Levin
2013-03-15  7:38         ` Ming Lei
2013-03-15 16:27           ` Sasha Levin
2013-03-16 12:39         ` Hillf Danton
2013-03-16 13:30           ` Ming Lei
2013-03-16 15:07             ` Sasha Levin
2013-03-16 15:22               ` Ming Lei
2013-03-16 15:58                 ` Ming Lei
2013-03-16 18:33                   ` Sasha Levin [this message]
2013-03-17  1:02                     ` Ming Lei
2013-03-17 14:24                       ` Sasha Levin
2013-03-17 16:23                         ` Ming Lei
2013-03-19  2:06                           ` Sasha Levin
2013-03-19  3:40                             ` Ming Lei
2013-03-19 11:54                               ` Ming Lei
2013-03-19 16:28                                 ` Sasha Levin
2013-03-20  1:02                                   ` Ming Lei
2013-03-20 14:34                                     ` Sasha Levin
2013-03-20 17:17                                       ` Greg Kroah-Hartman
2013-03-16 15:59                 ` Sasha Levin

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=5144BB15.3020002@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=davej@redhat.com \
    --cc=dhillf@gmail.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom.leiming@gmail.com \
    /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).