Skip to contentSkip to conversation

iptables: Make the entry offset the same type as a jump verdict.

PATCH New Grant Erickson 1 participant 1 message Nov 12

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iptables: Make the entry offset the same type as a jump verdict.

This addresses -Werror=sign-compare compilation errors surfaced by both GCC and clang/LLVM in 'update_targets_reference' when --enable-maintainer-mode is asserted and connman is configured with --with-firewall=iptables:

src/iptables.c:805:40: error: comparison of integer expressions
of different signedness: 'int' and 'unsigned int' [-Werror=sign-compare]
src/iptables.c:808:40: error: comparison of integer expressions
of different signedness: 'int' and 'unsigned int' [-Werror=sign-compare]

The 'offset' member of 'struct connman_iptables_entry' is the entry's byte offset within the table, and its one purpose beyond bookkeeping is to be the target of a standard-target jump: it is written into a 'struct xt_standard_target' 'verdict', in 'prepare_target' and for fall-through entries in 'update_targets_reference', and it is compared against existing verdicts in 'update_targets_reference' to find jumps that must be moved when an entry is inserted or removed. The kernel ABI defines 'verdict' as 'int', with non-negative values being jump offsets and negative values being standard verdicts. So, rather than casting at the comparisons, give 'offset' the same type as the verdicts it is written into and compared against.

With that, the comparisons in 'update_targets_reference' are made in the verdict's own signed domain. Previously, the usual arithmetic conversions converted the verdict to 'unsigned int'. 'is_jump' does not exclude every negative verdict (for example, -NF_STOLEN - 1), so such a verdict would have compared as a very large unsigned value and been adjusted as though it were a jump past the modified entry; it now correctly compares as less than any entry offset and is left alone.

Entry offsets are bounded by the table size, which the kernel limits to XT_MAX_TABLE_SIZE (512 MiB) in xt_alloc_table_info, so every valid offset is representable as an int, as it already must be to be written into a verdict.

---
 src/iptables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/iptables.c +1 -1
index a81a07792e9f..5b1f5650a30e 100644
@@ -151,7 +151,7 @@ static const char *hooknames[] = {
 
 struct connman_iptables_entry {
 	int type;
-	unsigned int offset;
+	int offset;
 	int builtin;
 	int counter_idx;
 
Signature · 1 line
2.52.0