Skip to contentSkip to conversation

uprobes: guard against kmemdup() failing in dup_return_instance()

PATCH Applied Andrii Nakryiko 3 participants 5 messages Dec 6, 2024 – Dec 9, 2024

Subsystems (4)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 uprobes: guard against kmemdup() failing in dup_return_instance()

If kmemdup() failed to alloc memory, don't proceed with extra_consumers copy.

Fixes e62f2d492728 ("uprobes: Simplify session consumer tracking")
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
index 1af950208c2b..1f75a2f91206 100644
@@ -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,
Signature · 1 line
2.43.5
#1 lore raw

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

The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     64fb80679287a6dd0acd9c8afa259054a2479a52
Gitweb:        https://git.kernel.org/tip/64fb80679287a6dd0acd9c8afa259054a2479a52
Author:        Andrii Nakryiko <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 10:34:36 -08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 06 Dec 2024 19:52:47 +01:00

uprobes: Guard against kmemdup() failing in dup_return_instance()

If kmemdup() failed to alloc memory, don't proceed with extra_consumers copy.

Fixes e62f2d492728 ("uprobes: Simplify session consumer tracking")
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
index 1af9502..1f75a2f 100644
@@ -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 lore raw

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

In reply to Andrii Nakryiko
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     638331f34c3f19f5bf14611ec6092ca1ba0ceb51
Gitweb:        https://git.kernel.org/tip/638331f34c3f19f5bf14611ec6092ca1ba0ceb51
Author:        Andrii Nakryiko <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 10:34:36 -08:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 09 Dec 2024 11:18:08 +01:00

uprobes: Guard against kmemdup() failing in dup_return_instance()

If kmemdup() failed to alloc memory, don't proceed with extra_consumers copy.

Fixes e62f2d492728 ("uprobes: Simplify session consumer tracking")
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
index 1af9502..1f75a2f 100644
@@ -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,
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Andrii Nakryiko
Quoted 5 lines · On Fri, 6 Dec 2024 10:34:36 -0800 Andrii Nakryiko <[email protected]> wrote:

If kmemdup() failed to alloc memory, don't proceed with extra_consumers copy.

Fixes e62f2d492728 ("uprobes: Simplify session consumer tracking")

Looks good to me.

Thanks!

Quoted 20 lines
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
index 1af950208c2b..1f75a2f91206 100644
@@ -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,
Signature · 1 line
2.43.5
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#4 lore raw

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

In reply to Andrii Nakryiko
The following commit has been merged into the perf/core branch of tip:

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     02c56362a7d3eccc209d5c00d73a06513d2504d5
Gitweb:        https://git.kernel.org/tip/02c56362a7d3eccc209d5c00d73a06513d2504d5
Author:        Andrii Nakryiko <[email protected]>
AuthorDate:    Fri, 06 Dec 2024 10:34:36 -08:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Mon, 09 Dec 2024 15:50:32 +01:00

uprobes: Guard against kmemdup() failing in dup_return_instance()

If kmemdup() failed to alloc memory, don't proceed with extra_consumers copy.

Fixes e62f2d492728 ("uprobes: Simplify session consumer tracking")
---
 kernel/events/uprobes.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/events/uprobes.c +2 -0
index 1af9502..1f75a2f 100644
@@ -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,