Re: [Nbd] [PATCH 1/1] kthread: introduce kthread_get_run() to fix __nbd_ioctl()
- To: Christoph Hellwig <hch@...1270...>
- Cc: Tejun Heo <tj@...1285...>, Andrew Morton <akpm@...133...>, nbd-general@lists.sourceforge.net, linux-kernel@...25...
- Subject: Re: [Nbd] [PATCH 1/1] kthread: introduce kthread_get_run() to fix __nbd_ioctl()
- From: Oleg Nesterov <oleg@...696...>
- Date: Wed, 28 Oct 2015 16:37:07 +0100
- Message-id: <20151028153707.GB22672@...696...>
- In-reply-to: <20151027002642.GA32444@...1270...>
- References: <20151025142655.GA30961@...696...> <20151025142713.GA30965@...696...> <20151027002642.GA32444@...1270...>
On 10/26, Christoph Hellwig wrote:
>
> On Sun, Oct 25, 2015 at 03:27:13PM +0100, Oleg Nesterov wrote:
> > It is not safe to use the task_struct returned by kthread_run(threadfn)
> > if threadfn() can exit before the "owner" does kthread_stop(), nothing
> > protects this task_struct.
> >
> > So __nbd_ioctl() looks buggy; a killed nbd_thread_send() can exit, free
> > its task_struct, and then kthread_stop() can use the freed/reused memory.
> >
> > Add the new trivial helper, kthread_get_run(). Hopefully it will have more
> > users, this patch changes __nbd_ioctl() as an example.
>
> This looks horrible.
Do you mean the helper itself?
In fact iirc people asked for this helper before. It looks natural and simple.
kthread_run() can only be used if this kthread can't exit on its own.
> I think the real problem is that nbd is totally
> abusing signals for kthreads and that needs to go away.
I agree this code needs cleanups. And of course we can fix it without
new helper, but see above.
Oleg.
Reply to: