Skip to content

Commit 89407ad

Browse files
Wang Haigregkh
authored andcommitted
samples/bpf: Fix Segmentation fault for xdp_redirect command
[ Upstream commit 85102ba ] 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: 24251c2 ("samples/bpf: add option for native and skb mode for redirect apps") Signed-off-by: Wang Hai <wanghai38@huawei.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210616042324.314832-1-wanghai38@huawei.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 530f73e commit 89407ad

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎samples/bpf/xdp_redirect_user.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
130130
if (!(xdp_flags & XDP_FLAGS_SKB_MODE))
131131
xdp_flags |= XDP_FLAGS_DRV_MODE;
132132

133-
if (optind == argc) {
133+
if (optind + 2 != argc) {
134134
printf("usage: %s <IFNAME|IFINDEX>_IN <IFNAME|IFINDEX>_OUT\n", argv[0]);
135135
return 1;
136136
}

0 commit comments

Comments
 (0)