* [PATCH] lib/stackdepot.c: fix a condition in stack_depot_fetch()
@ 2020-03-12 11:30 Dan Carpenter
2020-03-12 12:06 ` Alexander Potapenko
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-03-12 11:30 UTC (permalink / raw)
To: Alexander Potapenko
Cc: Thomas Gleixner, Andrew Morton, Josh Poimboeuf, Stephen Rothwell,
Miles Chen, linux-kernel, kernel-janitors
We should check for a NULL pointer first before adding the offset.
Otherwise if the pointer is NULL and the offset is non-zero, it will
lead to an Oops.
Fixes: d45048e65a59 ("lib/stackdepot.c: check depot_index before accessing the stack slab")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
lib/stackdepot.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index da5d1880bf34..2caffc64e4c8 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -207,18 +207,16 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
size_t offset = parts.offset << STACK_ALLOC_ALIGN;
struct stack_record *stack;
+ *entries = NULL;
if (parts.slabindex > depot_index) {
WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
parts.slabindex, depot_index, handle);
- *entries = NULL;
return 0;
}
slab = stack_slabs[parts.slabindex];
- stack = slab + offset;
- if (!stack) {
- *entries = NULL;
+ if (!slab)
return 0;
- }
+ stack = slab + offset;
*entries = stack->entries;
return stack->size;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] lib/stackdepot.c: fix a condition in stack_depot_fetch()
2020-03-12 11:30 [PATCH] lib/stackdepot.c: fix a condition in stack_depot_fetch() Dan Carpenter
@ 2020-03-12 12:06 ` Alexander Potapenko
0 siblings, 0 replies; 2+ messages in thread
From: Alexander Potapenko @ 2020-03-12 12:06 UTC (permalink / raw)
To: Dan Carpenter
Cc: Thomas Gleixner, Andrew Morton, Josh Poimboeuf, Stephen Rothwell,
Miles Chen, LKML, kernel-janitors
On Thu, Mar 12, 2020 at 12:30 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> We should check for a NULL pointer first before adding the offset.
> Otherwise if the pointer is NULL and the offset is non-zero, it will
> lead to an Oops.
Thanks!
> Fixes: d45048e65a59 ("lib/stackdepot.c: check depot_index before accessing the stack slab")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Alexander Potapenko <glider@google.com>
> ---
> lib/stackdepot.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index da5d1880bf34..2caffc64e4c8 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -207,18 +207,16 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
> size_t offset = parts.offset << STACK_ALLOC_ALIGN;
> struct stack_record *stack;
>
> + *entries = NULL;
> if (parts.slabindex > depot_index) {
> WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
> parts.slabindex, depot_index, handle);
> - *entries = NULL;
> return 0;
> }
> slab = stack_slabs[parts.slabindex];
> - stack = slab + offset;
> - if (!stack) {
> - *entries = NULL;
> + if (!slab)
> return 0;
> - }
> + stack = slab + offset;
>
> *entries = stack->entries;
> return stack->size;
> --
> 2.20.1
>
--
Alexander Potapenko
Software Engineer
Google Germany GmbH
Erika-Mann-Straße, 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-12 12:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-12 11:30 [PATCH] lib/stackdepot.c: fix a condition in stack_depot_fetch() Dan Carpenter
2020-03-12 12:06 ` Alexander Potapenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox