]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commit
bpf: test_maps: fix possible out of bound access warning
authorBreno Leitao <leitao@debian.org>
Tue, 5 Feb 2019 17:12:34 +0000 (15:12 -0200)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 14 May 2019 18:55:24 +0000 (20:55 +0200)
commite68c1006ba52e3b0c2a328368226c3ddb3ce2a93
tree2efca41d6b7473b1bff5922e1b3b6161758e4423
parent02f545e8492c6106b1902ae43897e3619d688a88
bpf: test_maps: fix possible out of bound access warning

BugLink: https://bugs.launchpad.net/bugs/1828410
[ Upstream commit dd9cef43c222df7c0d76d34451808e789952379d ]

When compiling test_maps selftest with GCC-8, it warns that an array
might be indexed with a negative value, which could cause a negative
out of bound access, depending on parameters of the function. This
is the GCC-8 warning:

gcc -Wall -O2 -I../../../include/uapi -I../../../lib -I../../../lib/bpf -I../../../../include/generated -DHAVE_GENHDR -I../../../include    test_maps.c /home/breno/Devel/linux/tools/testing/selftests/bpf/libbpf.a -lcap -lelf -lrt -lpthread -o /home/breno/Devel/linux/tools/testing/selftests/bpf/test_maps
In file included from test_maps.c:16:
test_maps.c: In function ‘run_all_tests’:
test_maps.c:1079:10: warning: array subscript -1 is below array bounds of ‘pid_t[<Ube20> + 1]’ [-Warray-bounds]
   assert(waitpid(pid[i], &status, 0) == pid[i]);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
test_maps.c:1059:6: warning: array subscript -1 is below array bounds of ‘pid_t[<Ube20> + 1]’ [-Warray-bounds]
   pid[i] = fork();
   ~~~^~~

This patch simply guarantees that the task(s) variables are unsigned,
thus, they could never be a negative number (which they are not in
current code anyway), hence avoiding an out of bound access warning.

Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
tools/testing/selftests/bpf/test_maps.c