diff mbox series

[RFC,v2,1/2] lib, stackdepot: check stackdepot handle before accessing slabs.

Message ID 20210902000154.1096484-2-imran.f.khan@oracle.com (mailing list archive)
State New
Headers show
Series lib, stackdepot: check stackdepot handle before accessing slabs | expand

Commit Message

Imran Khan Sept. 2, 2021, 12:01 a.m. UTC
stack_depot_save allocates slabs that will be used for storing
objects in future.If this slab allocation fails we may get to
a situation where space allocation for a new stack_record fails,
causing stack_depot_save to return 0 as handle.
If user of this handle ends up invoking stack_depot_fetch with
this handle value, current implementation of stack_depot_fetch
will end up using slab from wrong index.
To avoid this check handle value at the beginning.

Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
Suggested-by: Vlastimil Babka <vbabka@suse.cz>
---
 lib/stackdepot.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Vlastimil Babka Sept. 2, 2021, 7:53 a.m. UTC | #1
On 9/2/21 02:01, Imran Khan wrote:
> stack_depot_save allocates slabs that will be used for storing
> objects in future.If this slab allocation fails we may get to
> a situation where space allocation for a new stack_record fails,
> causing stack_depot_save to return 0 as handle.
> If user of this handle ends up invoking stack_depot_fetch with
> this handle value, current implementation of stack_depot_fetch
> will end up using slab from wrong index.
> To avoid this check handle value at the beginning.
> 
> Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  lib/stackdepot.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index 0a2e417f83cb..67439c082490 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -232,6 +232,9 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
>  	struct stack_record *stack;
>  
>  	*entries = NULL;
> +	if (!handle)
> +		return 0;
> +
>  	if (parts.slabindex > depot_index) {
>  		WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
>  			parts.slabindex, depot_index, handle);
>
diff mbox series

Patch

diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index 0a2e417f83cb..67439c082490 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -232,6 +232,9 @@  unsigned int stack_depot_fetch(depot_stack_handle_t handle,
 	struct stack_record *stack;
 
 	*entries = NULL;
+	if (!handle)
+		return 0;
+
 	if (parts.slabindex > depot_index) {
 		WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n",
 			parts.slabindex, depot_index, handle);