From: glider@google.com
To: walter-zh.wu@mediatek.com, dvyukov@google.com,
gregkh@linuxfoundation.org, akpm@linux-foundation.org
Cc: matthias.bgg@gmail.com, tglx@linutronix.de, jpoimboe@redhat.com,
kstewart@linuxfoundation.org, linux-mm@kvack.org,
Alexander Potapenko <glider@google.com>
Subject: [PATCH] lib/stackdepot: fix global out-of-bounds in stack_slabs
Date: Mon, 3 Feb 2020 11:29:53 +0100 [thread overview]
Message-ID: <20200203102953.17349-1-glider@google.com> (raw)
Walter Wu has reported a potential case in which init_stack_slab() is
called after stack_slabs[STACK_ALLOC_MAX_SLABS - 1] has already been
initialized. In that case init_stack_slab() will overwrite
stack_slabs[STACK_ALLOC_MAX_SLABS], which may result in a memory
corruption.
Fixes: cd11016e5f521 ("mm, kasan: stackdepot implementation. Enable stackdepot for SLAB")
Reported-by: Walter Wu <walter-zh.wu@mediatek.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Alexander Potapenko <glider@google.com>
---
lib/stackdepot.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index ed717dd08ff3..3580e92cac99 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -84,7 +84,9 @@ static bool init_stack_slab(void **prealloc)
if (stack_slabs[depot_index] == NULL) {
stack_slabs[depot_index] = *prealloc;
} else {
- stack_slabs[depot_index + 1] = *prealloc;
+ /* If this is the last depot slab, do not touch the next one. */
+ if (depot_index + 1 < STACK_ALLOC_MAX_SLABS)
+ stack_slabs[depot_index + 1] = *prealloc;
/*
* This smp_store_release pairs with smp_load_acquire() from
* |next_slab_inited| above and in stack_depot_save().
--
2.25.0.341.g760bfbb309-goog
next reply other threads:[~2020-02-03 10:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-03 10:29 glider [this message]
2020-02-03 11:02 ` [PATCH] lib/stackdepot: fix global out-of-bounds in stack_slabs Tetsuo Handa
2020-02-03 11:10 ` Alexander Potapenko
-- strict thread matches above, loose matches on Subject: below --
2020-02-18 10:29 glider
2020-02-19 21:37 ` Andrew Morton
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=20200203102953.17349-1-glider@google.com \
--to=glider@google.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jpoimboe@redhat.com \
--cc=kstewart@linuxfoundation.org \
--cc=linux-mm@kvack.org \
--cc=matthias.bgg@gmail.com \
--cc=tglx@linutronix.de \
--cc=walter-zh.wu@mediatek.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 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.