Skip to contentSkip to conversation

bpf: Fix incorrect use of strlen in xdp_redirect_cpu

PATCH Applied Kumar Kartikeya Dwivedi 3 participants 3 messages Nov 12, 2021

Subsystems (2)
lore
Share & tools
lore

Kumar Kartikeya Dwivedi

author maintainer
#0 lore raw

PATCH 1/1 bpf: Fix incorrect use of strlen in xdp_redirect_cpu

Commit b599015f044d tried to fix a bug where sizeof was incorrectly applied to a pointer instead of the array string was being copied to, to find the destination buffer size, but ended up using strlen, which is still incorrect. However, on closer look ifname_buf has no other use, hence directly use optarg.

Fixes b599015f044d ("samples/bpf: Fix application of sizeof to pointer")
Fixes e531a220cc59 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper")
---
 samples/bpf/xdp_redirect_cpu_user.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
samples/bpf/xdp_redirect_cpu_user.c +2 -3
index d84e6949007c..a81704d3317b 100644
@@ -309,7 +309,6 @@ int main(int argc, char **argv)
 	const char *mprog_filename = NULL, *mprog_name = NULL;
 	struct xdp_redirect_cpu *skel;
 	struct bpf_map_info info = {};
-	char ifname_buf[IF_NAMESIZE];
 	struct bpf_cpumap_val value;
 	__u32 infosz = sizeof(info);
 	int ret = EXIT_FAIL_OPTION;
@@ -390,10 +389,10 @@ int main(int argc, char **argv)
 		case 'd':
 			if (strlen(optarg) >= IF_NAMESIZE) {
 				fprintf(stderr, "-d/--dev name too long\n");
+				usage(argv, long_options, __doc__, mask, true, skel->obj);
 				goto end_cpu;
 			}
-			safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
-			ifindex = if_nametoindex(ifname_buf);
+			ifindex = if_nametoindex(optarg);
 			if (!ifindex)
 				ifindex = strtoul(optarg, NULL, 0);
 			if (!ifindex) {
Signature · 1 line
2.33.1
#1 lore raw

From: Kumar Kartikeya Dwivedi <[email protected]>
Date: Fri, 12 Nov 2021 07:33:01 +0530

Quoted 10 lines

Commit b599015f044d tried to fix a bug where sizeof was incorrectly applied to a pointer instead of the array string was being copied to, to find the destination buffer size, but ended up using strlen, which is still incorrect. However, on closer look ifname_buf has no other use, hence directly use optarg.

Fixes b599015f044d ("samples/bpf: Fix application of sizeof to pointer")
Fixes e531a220cc59 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper")

---

Works, thanks!

Thanks,
Al

#2 lore raw
In reply to Kumar Kartikeya Dwivedi
This patch was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:

Hello:

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

Quoted 11 lines · On Fri, 12 Nov 2021 07:33:01 +0530 you wrote:

Commit b599015f044d tried to fix a bug where sizeof was incorrectly applied to a pointer instead of the array string was being copied to, to find the destination buffer size, but ended up using strlen, which is still incorrect. However, on closer look ifname_buf has no other use, hence directly use optarg.

Fixes b599015f044d ("samples/bpf: Fix application of sizeof to pointer")
Fixes e531a220cc59 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper")

[...]

Here is the summary with links:
- [bpf] bpf: Fix incorrect use of strlen in xdp_redirect_cpu

    https://git.kernel.org/bpf/bpf/c/ed95f45142fa

You are awesome, thank you!

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