linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake
@ 2021-03-28  9:11 lyl2019
  2021-03-29 13:57 ` Jan Kara
  0 siblings, 1 reply; 3+ messages in thread
From: lyl2019 @ 2021-03-28  9:11 UTC (permalink / raw)
  To: jack, amir73il; +Cc: linux-fsdevel, linux-kernel

Hi,
    My static analyzer tool reported a use after free in fsnotify_put_mark_wake
of the file: fs/notify/mark.c.

In fsnotify_put_mark_wake, it calls fsnotify_put_mark(mark). Inside the function
fsnotify_put_mark(), if conn is NULL, it will call fsnotify_final_mark_destroy(mark)
to free mark->group by fsnotify_put_group(group) and return. I also had inspected
the implementation of fsnotify_put_group() and found that there is no cleanup operation
about group->user_waits.

But after fsnotify_put_mark_wake() returned, mark->group is still used by 
if (atomic_dec_and_test(&group->user_waits) && group->shutdown) and later.

Is this an issue?

Thanks.






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake
  2021-03-28  9:11 [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake lyl2019
@ 2021-03-29 13:57 ` Jan Kara
  2021-03-29 14:07   ` lyl2019
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2021-03-29 13:57 UTC (permalink / raw)
  To: lyl2019; +Cc: jack, amir73il, linux-fsdevel, linux-kernel

Hello!


On Sun 28-03-21 17:11:43, lyl2019@mail.ustc.edu.cn wrote:
>     My static analyzer tool reported a use after free in fsnotify_put_mark_wake
> of the file: fs/notify/mark.c.
> 
> In fsnotify_put_mark_wake, it calls fsnotify_put_mark(mark). Inside the function
> fsnotify_put_mark(), if conn is NULL, it will call fsnotify_final_mark_destroy(mark)
> to free mark->group by fsnotify_put_group(group) and return. I also had inspected
> the implementation of fsnotify_put_group() and found that there is no cleanup operation
> about group->user_waits.
> 
> But after fsnotify_put_mark_wake() returned, mark->group is still used by 
> if (atomic_dec_and_test(&group->user_waits) && group->shutdown) and later.
> 
> Is this an issue?

I don't think this scenario is possible. fsnotify_put_mark_wake() can be
called only for marks attached to objects and these have mark->conn !=
NULL and we are sure that fsnotify_destroy_group() will wait for all such
marks to be torn down and freed before dropping last group reference and
freeing the group.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake
  2021-03-29 13:57 ` Jan Kara
@ 2021-03-29 14:07   ` lyl2019
  0 siblings, 0 replies; 3+ messages in thread
From: lyl2019 @ 2021-03-29 14:07 UTC (permalink / raw)
  To: Jan Kara; +Cc: amir73il, linux-fsdevel, linux-kernel




> -----原始邮件-----
> 发件人: "Jan Kara" <jack@suse.cz>
> 发送时间: 2021-03-29 21:57:40 (星期一)
> 收件人: lyl2019@mail.ustc.edu.cn
> 抄送: jack@suse.cz, amir73il@gmail.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
> 主题: Re: [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake
> 
> Hello!
> 
> 
> On Sun 28-03-21 17:11:43, lyl2019@mail.ustc.edu.cn wrote:
> >     My static analyzer tool reported a use after free in fsnotify_put_mark_wake
> > of the file: fs/notify/mark.c.
> > 
> > In fsnotify_put_mark_wake, it calls fsnotify_put_mark(mark). Inside the function
> > fsnotify_put_mark(), if conn is NULL, it will call fsnotify_final_mark_destroy(mark)
> > to free mark->group by fsnotify_put_group(group) and return. I also had inspected
> > the implementation of fsnotify_put_group() and found that there is no cleanup operation
> > about group->user_waits.
> > 
> > But after fsnotify_put_mark_wake() returned, mark->group is still used by 
> > if (atomic_dec_and_test(&group->user_waits) && group->shutdown) and later.
> > 
> > Is this an issue?
> 
> I don't think this scenario is possible. fsnotify_put_mark_wake() can be
> called only for marks attached to objects and these have mark->conn !=
> NULL and we are sure that fsnotify_destroy_group() will wait for all such
> marks to be torn down and freed before dropping last group reference and
> freeing the group.
> 
> 								Honza
> -- 
> Jan Kara <jack@suse.com>
> SUSE Labs, CR


Ok, thanks for your answer.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-29 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-28  9:11 [BUG] fs/notify/mark: A potential use after free in fsnotify_put_mark_wake lyl2019
2021-03-29 13:57 ` Jan Kara
2021-03-29 14:07   ` lyl2019

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).