Skip to content

Commit 4cdc0e4

Browse files
visitorckwanakryiko
authored andcommitted
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 12707b9 commit 4cdc0e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/bpf/bpftool/net.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev,
486486
if (prog_flags[i] || json_output) {
487487
NET_START_ARRAY("prog_flags", "%s ");
488488
for (j = 0; prog_flags[i] && j < 32; j++) {
489-
if (!(prog_flags[i] & (1 << j)))
489+
if (!(prog_flags[i] & (1U << j)))
490490
continue;
491-
NET_DUMP_UINT_ONLY(1 << j);
491+
NET_DUMP_UINT_ONLY(1U << j);
492492
}
493493
NET_END_ARRAY("");
494494
}
@@ -497,9 +497,9 @@ static void __show_dev_tc_bpf(const struct ip_devname_ifindex *dev,
497497
if (link_flags[i] || json_output) {
498498
NET_START_ARRAY("link_flags", "%s ");
499499
for (j = 0; link_flags[i] && j < 32; j++) {
500-
if (!(link_flags[i] & (1 << j)))
500+
if (!(link_flags[i] & (1U << j)))
501501
continue;
502-
NET_DUMP_UINT_ONLY(1 << j);
502+
NET_DUMP_UINT_ONLY(1U << j);
503503
}
504504
NET_END_ARRAY("");
505505
}

0 commit comments

Comments
 (0)