diff mbox series

[bpf] samples/bpf: Fix Segmentation fault for xdp_redirect command

Message ID 20210616042324.314832-1-wanghai38@huawei.com (mailing list archive)
State Accepted
Commit 85102ba58b4125ebad941d7555c3c248b23efd16
Delegated to: BPF
Headers show
Series [bpf] samples/bpf: Fix Segmentation fault for xdp_redirect command | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf
netdev/subject_prefix success Link
netdev/cc_maintainers fail 1 blamed authors not CCed: andy@greyhouse.net; 1 maintainers not CCed: andy@greyhouse.net
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

wanghai (M) June 16, 2021, 4:23 a.m. UTC
A Segmentation fault error is caused when the following command
is executed.

$ sudo ./samples/bpf/xdp_redirect lo
Segmentation fault

This command is missing a device <IFNAME|IFINDEX> as an argument, resulting
in out-of-bounds access from argv.

If the number of devices for the xdp_redirect parameter is not 2,
we should report an error and exit.

Fixes: 24251c264798 ("samples/bpf: add option for native and skb mode for redirect apps")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 samples/bpf/xdp_redirect_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org June 18, 2021, 6:20 p.m. UTC | #1
Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

On Wed, 16 Jun 2021 12:23:24 +0800 you wrote:
> A Segmentation fault error is caused when the following command
> is executed.
> 
> $ sudo ./samples/bpf/xdp_redirect lo
> Segmentation fault
> 
> This command is missing a device <IFNAME|IFINDEX> as an argument, resulting
> in out-of-bounds access from argv.
> 
> [...]

Here is the summary with links:
  - [bpf] samples/bpf: Fix Segmentation fault for xdp_redirect command
    https://git.kernel.org/bpf/bpf-next/c/85102ba58b41

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/samples/bpf/xdp_redirect_user.c b/samples/bpf/xdp_redirect_user.c
index c903f1ccc15e..93854e135134 100644
--- a/samples/bpf/xdp_redirect_user.c
+++ b/samples/bpf/xdp_redirect_user.c
@@ -130,7 +130,7 @@  int main(int argc, char **argv)
 	if (!(xdp_flags & XDP_FLAGS_SKB_MODE))
 		xdp_flags |= XDP_FLAGS_DRV_MODE;
 
-	if (optind == argc) {
+	if (optind + 2 != argc) {
 		printf("usage: %s <IFNAME|IFINDEX>_IN <IFNAME|IFINDEX>_OUT\n", argv[0]);
 		return 1;
 	}