samples/bpf: Fix Segmentation fault for xdp_redirect command
authorWang Hai <wanghai38@huawei.com>
Wed, 16 Jun 2021 04:23:24 +0000 (12:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Jul 2021 14:56:23 +0000 (16:56 +0200)
commit79bf8f04cececfe0c0ff9c07023e04c91f31c7f1
tree817de11d6bf7a2a9832380110deee7d4dfbca8f6
parentfcd8d6371a469aae96367f82a14870e4beef8b2f
samples/bpf: Fix Segmentation fault for xdp_redirect command

[ Upstream commit 85102ba58b4125ebad941d7555c3c248b23efd16 ]

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>
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>
samples/bpf/xdp_redirect_user.c