Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpftool: Fix undefined behavior caused by shifting into the sign bit

Replace shifts of '1' with '1U' in bitwise operations within
__show_dev_tc_bpf() to prevent undefined behavior caused by shifting
into the sign bit of a signed integer. By using '1U', the operations
are explicitly performed on unsigned integers, avoiding potential
integer overflow or sign-related issues.

Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240908140009.3149781-1-visitorckw@gmail.com

authored by

Kuan-Wei Chiu and committed by
Andrii Nakryiko
4cdc0e4c 12707b91

+4 -4
+4 -4
tools/bpf/bpftool/net.c
··· 486 486 if (prog_flags[i] || json_output) { 487 487 NET_START_ARRAY("prog_flags", "%s "); 488 488 for (j = 0; prog_flags[i] && j < 32; j++) { 489 - if (!(prog_flags[i] & (1 << j))) 489 + if (!(prog_flags[i] & (1U << j))) 490 490 continue; 491 - NET_DUMP_UINT_ONLY(1 << j); 491 + NET_DUMP_UINT_ONLY(1U << j); 492 492 } 493 493 NET_END_ARRAY(""); 494 494 } ··· 497 497 if (link_flags[i] || json_output) { 498 498 NET_START_ARRAY("link_flags", "%s "); 499 499 for (j = 0; link_flags[i] && j < 32; j++) { 500 - if (!(link_flags[i] & (1 << j))) 500 + if (!(link_flags[i] & (1U << j))) 501 501 continue; 502 - NET_DUMP_UINT_ONLY(1 << j); 502 + NET_DUMP_UINT_ONLY(1U << j); 503 503 } 504 504 NET_END_ARRAY(""); 505 505 }