Skip to contentSkip to conversation

libbpf: don't close(-1) in multi-uprobe feature detector

PATCH Applied Andrii Nakryiko 3 participants 3 messages May 29, 2024 – May 31, 2024

Subsystems (2)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: don't close(-1) in multi-uprobe feature detector

Guard close(link_fd) with extra link_fd >= 0 check to prevent close(-1).

Detected by Coverity static analysis.

Fixes 04d939a2ab22 ("libbpf: detect broken PID filtering logic for multi-uprobe")
---
 tools/lib/bpf/features.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/features.c +2 -1
index 3df0125ed5fa..50befe125ddc 100644
@@ -393,7 +393,8 @@ static int probe_uprobe_multi_link(int token_fd)
 	err = -errno; /* close() can clobber errno */
 
 	if (link_fd >= 0 || err != -EBADF) {
-		close(link_fd);
+		if (link_fd >= 0)
+			close(link_fd);
 		close(prog_fd);
 		return 0;
 	}
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrii Nakryiko

Guard close(link_fd) with extra link_fd >= 0 check to prevent close(-1).

Detected by Coverity static analysis.

Fixes 04d939a2ab22 ("libbpf: detect broken PID filtering logic for multi-uprobe")

jirka

Quoted 22 lines
---
 tools/lib/bpf/features.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/lib/bpf/features.c +2 -1
index 3df0125ed5fa..50befe125ddc 100644
@@ -393,7 +393,8 @@ static int probe_uprobe_multi_link(int token_fd)
 	err = -errno; /* close() can clobber errno */
 
 	if (link_fd >= 0 || err != -EBADF) {
-		close(link_fd);
+		if (link_fd >= 0)
+			close(link_fd);
 		close(prog_fd);
 		return 0;
 	}
Signature · 1 line
2.43.0
#2 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Wed, 29 May 2024 16:12:12 -0700 you wrote:

Guard close(link_fd) with extra link_fd >= 0 check to prevent close(-1).

Detected by Coverity static analysis.

Fixes 04d939a2ab22 ("libbpf: detect broken PID filtering logic for multi-uprobe")

[...]

Here is the summary with links:
- [bpf] libbpf: don't close(-1) in multi-uprobe feature detector

    https://git.kernel.org/bpf/bpf/c/7d0b3953f6d8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html