linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] /net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree()
@ 2018-07-19 20:06 Tomas Bortoli
  2018-07-20  8:34 ` [V9fs-developer] " jiangyiwen
  0 siblings, 1 reply; 2+ messages in thread
From: Tomas Bortoli @ 2018-07-19 20:06 UTC (permalink / raw)
  To: ericvh, rminnich, lucho
  Cc: davem, v9fs-developer, netdev, linux-kernel, syzkaller, Tomas Bortoli

The patch adds the flush in p9_mux_poll_stop() as it the function used by
p9_conn_destroy(), in turn called by p9_fd_close() to stop the async
polling associated with the data regarding the connection.

Signed-off-by: Tomas Bortoli <tomasbortoli@gmail.com>
Reported-by: syzbot+39749ed7d9ef6dfb23f6@syzkaller.appspotmail.com
---
As shown by Syzbot, it is possible to provoke a race between p9_fd_close() 
and p9_poll_workfn() that is called to take care of the async read/write work
to do. To make sure p9_fd_close() frees "trans" when it is not used anymore, 
it has to explicitly call flush_scheduled_work() before the kfree().

 net/9p/trans_fd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index bf459ee0feab..76ae134c05d9 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -185,6 +185,8 @@ static void p9_mux_poll_stop(struct p9_conn *m)
 	spin_lock_irqsave(&p9_poll_lock, flags);
 	list_del_init(&m->poll_pending_link);
 	spin_unlock_irqrestore(&p9_poll_lock, flags);
+
+	flush_scheduled_work();
 }
 
 /**
-- 
2.11.0


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

* Re: [V9fs-developer] [PATCH] /net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree()
  2018-07-19 20:06 [PATCH] /net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree() Tomas Bortoli
@ 2018-07-20  8:34 ` jiangyiwen
  0 siblings, 0 replies; 2+ messages in thread
From: jiangyiwen @ 2018-07-20  8:34 UTC (permalink / raw)
  To: Tomas Bortoli, ericvh, rminnich, lucho
  Cc: netdev, linux-kernel, syzkaller, v9fs-developer, davem

On 2018/7/20 4:06, Tomas Bortoli wrote:
> The patch adds the flush in p9_mux_poll_stop() as it the function used by
> p9_conn_destroy(), in turn called by p9_fd_close() to stop the async
> polling associated with the data regarding the connection.
> 
> Signed-off-by: Tomas Bortoli <tomasbortoli@gmail.com>
> Reported-by: syzbot+39749ed7d9ef6dfb23f6@syzkaller.appspotmail.com
> ---
> As shown by Syzbot, it is possible to provoke a race between p9_fd_close() 
> and p9_poll_workfn() that is called to take care of the async read/write work
> to do. To make sure p9_fd_close() frees "trans" when it is not used anymore, 
> it has to explicitly call flush_scheduled_work() before the kfree().
> 
>  net/9p/trans_fd.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
> index bf459ee0feab..76ae134c05d9 100644
> --- a/net/9p/trans_fd.c
> +++ b/net/9p/trans_fd.c
> @@ -185,6 +185,8 @@ static void p9_mux_poll_stop(struct p9_conn *m)
>  	spin_lock_irqsave(&p9_poll_lock, flags);
>  	list_del_init(&m->poll_pending_link);
>  	spin_unlock_irqrestore(&p9_poll_lock, flags);
> +
> +	flush_scheduled_work();

I suggest we should use flush_work(&p9_poll_work), flush_scheduled_work is not
suitable.

Thanks.

>  }
>  
>  /**
> 


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

end of thread, other threads:[~2018-07-20  8:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-19 20:06 [PATCH] /net/9p/trans_fd.c: fix race-condition by flushing workqueue before the kfree() Tomas Bortoli
2018-07-20  8:34 ` [V9fs-developer] " jiangyiwen

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