diff mbox series

[perf/core] uprobes: guard against kmemdup() failing in dup_return_instance()

Message ID 20241206183436.968068-1-andrii@kernel.org (mailing list archive)
State Not Applicable
Headers show
Series [perf/core] uprobes: guard against kmemdup() failing in dup_return_instance() | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Andrii Nakryiko Dec. 6, 2024, 6:34 p.m. UTC
If kmemdup() failed to alloc memory, don't proceed with extra_consumers
copy.

Fixes: e62f2d492728 ("uprobes: Simplify session consumer tracking")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Masami Hiramatsu (Google) Dec. 9, 2024, 11:13 a.m. UTC | #1
On Fri,  6 Dec 2024 10:34:36 -0800
Andrii Nakryiko <andrii@kernel.org> wrote:

> If kmemdup() failed to alloc memory, don't proceed with extra_consumers
> copy.
> 
> Fixes: e62f2d492728 ("uprobes: Simplify session consumer tracking")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks!

> ---
>  kernel/events/uprobes.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> index 1af950208c2b..1f75a2f91206 100644
> --- a/kernel/events/uprobes.c
> +++ b/kernel/events/uprobes.c
> @@ -2048,6 +2048,8 @@ static struct return_instance *dup_return_instance(struct return_instance *old)
>  	struct return_instance *ri;
>  
>  	ri = kmemdup(old, sizeof(*ri), GFP_KERNEL);
> +	if (!ri)
> +		return NULL;
>  
>  	if (unlikely(old->cons_cnt > 1)) {
>  		ri->extra_consumers = kmemdup(old->extra_consumers,
> -- 
> 2.43.5
>
diff mbox series

Patch

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 1af950208c2b..1f75a2f91206 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -2048,6 +2048,8 @@  static struct return_instance *dup_return_instance(struct return_instance *old)
 	struct return_instance *ri;
 
 	ri = kmemdup(old, sizeof(*ri), GFP_KERNEL);
+	if (!ri)
+		return NULL;
 
 	if (unlikely(old->cons_cnt > 1)) {
 		ri->extra_consumers = kmemdup(old->extra_consumers,