* [PATCH] bcache: check ca->alloc_thread initialized before wake up it
@ 2017-09-19 22:11 Coly Li
2017-10-07 21:46 ` Michael Lyle
0 siblings, 1 reply; 2+ messages in thread
From: Coly Li @ 2017-09-19 22:11 UTC (permalink / raw)
To: linux-bcache, linux-block; +Cc: Coly Li, Kent Overstreet, stable
In bcache code, sysfs entries are created before all resources get
allocated, e.g. allocation thread of a cache set.
There is posibility for NULL pointer deference if a resource is accessed
but which is not initialized yet. Indeed Jorg Bornschein catches one on
cache set allocation thread and gets a kernel oops.
The reason for this bug is, when bch_bucket_alloc() is called during
cache set registration and attaching, ca->alloc_thread is not properly
allocated and initialized yet, call wake_up_process() on ca->alloc_thread
triggers NULL pointer deference failure. A simple and fast fix is, before
waking up ca->alloc_thread, checking whether it is allocated, and only
wake up ca->alloc_thread when it is not NULL.
Signed-off-by: Coly Li <colyli@suse.de>
Reported-by: Jorg Bornschein <jb@capsec.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: stable@vger.kernel.org
---
drivers/md/bcache/alloc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
index cacbe2dbd5c3..e1a4205caa2e 100644
--- a/drivers/md/bcache/alloc.c
+++ b/drivers/md/bcache/alloc.c
@@ -406,7 +406,8 @@ long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait)
finish_wait(&ca->set->bucket_wait, &w);
out:
- wake_up_process(ca->alloc_thread);
+ if (ca->alloc_thread)
+ wake_up_process(ca->alloc_thread);
trace_bcache_alloc(ca, reserve);
--
2.13.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bcache: check ca->alloc_thread initialized before wake up it
2017-09-19 22:11 [PATCH] bcache: check ca->alloc_thread initialized before wake up it Coly Li
@ 2017-10-07 21:46 ` Michael Lyle
0 siblings, 0 replies; 2+ messages in thread
From: Michael Lyle @ 2017-10-07 21:46 UTC (permalink / raw)
To: Coly Li; +Cc: linux-bcache, linux-block, Kent Overstreet, stable
On Tue, Sep 19, 2017 at 3:11 PM, Coly Li <colyli@suse.de> wrote:
> In bcache code, sysfs entries are created before all resources get
> allocated, e.g. allocation thread of a cache set.
>
> There is posibility for NULL pointer deference if a resource is accessed
> but which is not initialized yet. Indeed Jorg Bornschein catches one on
> cache set allocation thread and gets a kernel oops.
> Signed-off-by: Coly Li <colyli@suse.de>
> Reported-by: Jorg Bornschein <jb@capsec.org>
> Cc: Kent Overstreet <kent.overstreet@gmail.com>
> Cc: stable@vger.kernel.org
Reviewed-by: Michael Lyle <mlyle@lyle.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-07 21:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-19 22:11 [PATCH] bcache: check ca->alloc_thread initialized before wake up it Coly Li
2017-10-07 21:46 ` Michael Lyle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.