Skip to content

Commit e3b5e1e

Browse files
Florian Westphalummakynes
authored andcommitted
Revert "netfilter: x_tables: ensure last rule in base chain matches underflow/policy"
This reverts commit 0d7df90. Valdis Kletnieks reported that xtables is broken in linux-next since 0d7df90 ("netfilter: x_tables: ensure last rule in base chain matches underflow/policy"), as kernel rejects the (well-formed) ruleset: [ 64.402790] ip6_tables: last base chain position 1136 doesn't match underflow 1344 (hook 1) mark_source_chains is not the correct place for such a check, as it terminates evaluation of a chain once it sees an unconditional verdict (following rules are known to be unreachable). It seems preferrable to fix libiptc instead, so remove this check again. Fixes: 0d7df90 ("netfilter: x_tables: ensure last rule in base chain matches underflow/policy") Reported-by: Valdis Kletnieks <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 9ba5c40 commit e3b5e1e

File tree

3 files changed

+3
-48
lines changed

3 files changed

+3
-48
lines changed

net/ipv4/netfilter/arp_tables.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,10 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
309309
for (hook = 0; hook < NF_ARP_NUMHOOKS; hook++) {
310310
unsigned int pos = newinfo->hook_entry[hook];
311311
struct arpt_entry *e = entry0 + pos;
312-
unsigned int last_pos, depth;
313312

314313
if (!(valid_hooks & (1 << hook)))
315314
continue;
316315

317-
depth = 0;
318-
last_pos = pos;
319316
/* Set initial back pointer. */
320317
e->counters.pcnt = pos;
321318

@@ -346,8 +343,6 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
346343
pos = e->counters.pcnt;
347344
e->counters.pcnt = 0;
348345

349-
if (depth)
350-
--depth;
351346
/* We're at the start. */
352347
if (pos == oldpos)
353348
goto next;
@@ -372,9 +367,6 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
372367
if (!xt_find_jump_offset(offsets, newpos,
373368
newinfo->number))
374369
return 0;
375-
376-
if (entry0 + newpos != arpt_next_entry(e))
377-
++depth;
378370
} else {
379371
/* ... this is a fallthru */
380372
newpos = pos + e->next_offset;
@@ -385,15 +377,8 @@ static int mark_source_chains(const struct xt_table_info *newinfo,
385377
e->counters.pcnt = pos;
386378
pos = newpos;
387379
}
388-
if (depth == 0)
389-
last_pos = pos;
390-
}
391-
next:
392-
if (last_pos != newinfo->underflow[hook]) {
393-
pr_err_ratelimited("last base chain position %u doesn't match underflow %u (hook %u)\n",
394-
last_pos, newinfo->underflow[hook], hook);
395-
return 0;
396380
}
381+
next: ;
397382
}
398383
return 1;
399384
}

net/ipv4/netfilter/ip_tables.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
378378
for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) {
379379
unsigned int pos = newinfo->hook_entry[hook];
380380
struct ipt_entry *e = entry0 + pos;
381-
unsigned int last_pos, depth;
382381

383382
if (!(valid_hooks & (1 << hook)))
384383
continue;
385384

386-
depth = 0;
387-
last_pos = pos;
388385
/* Set initial back pointer. */
389386
e->counters.pcnt = pos;
390387

@@ -413,8 +410,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
413410
pos = e->counters.pcnt;
414411
e->counters.pcnt = 0;
415412

416-
if (depth)
417-
--depth;
418413
/* We're at the start. */
419414
if (pos == oldpos)
420415
goto next;
@@ -439,9 +434,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
439434
if (!xt_find_jump_offset(offsets, newpos,
440435
newinfo->number))
441436
return 0;
442-
443-
if (entry0 + newpos != ipt_next_entry(e))
444-
++depth;
445437
} else {
446438
/* ... this is a fallthru */
447439
newpos = pos + e->next_offset;
@@ -452,15 +444,8 @@ mark_source_chains(const struct xt_table_info *newinfo,
452444
e->counters.pcnt = pos;
453445
pos = newpos;
454446
}
455-
if (depth == 0)
456-
last_pos = pos;
457-
}
458-
next:
459-
if (last_pos != newinfo->underflow[hook]) {
460-
pr_err_ratelimited("last base chain position %u doesn't match underflow %u (hook %u)\n",
461-
last_pos, newinfo->underflow[hook], hook);
462-
return 0;
463447
}
448+
next: ;
464449
}
465450
return 1;
466451
}

net/ipv6/netfilter/ip6_tables.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,10 @@ mark_source_chains(const struct xt_table_info *newinfo,
396396
for (hook = 0; hook < NF_INET_NUMHOOKS; hook++) {
397397
unsigned int pos = newinfo->hook_entry[hook];
398398
struct ip6t_entry *e = entry0 + pos;
399-
unsigned int last_pos, depth;
400399

401400
if (!(valid_hooks & (1 << hook)))
402401
continue;
403402

404-
depth = 0;
405-
last_pos = pos;
406403
/* Set initial back pointer. */
407404
e->counters.pcnt = pos;
408405

@@ -431,8 +428,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
431428
pos = e->counters.pcnt;
432429
e->counters.pcnt = 0;
433430

434-
if (depth)
435-
--depth;
436431
/* We're at the start. */
437432
if (pos == oldpos)
438433
goto next;
@@ -457,9 +452,6 @@ mark_source_chains(const struct xt_table_info *newinfo,
457452
if (!xt_find_jump_offset(offsets, newpos,
458453
newinfo->number))
459454
return 0;
460-
461-
if (entry0 + newpos != ip6t_next_entry(e))
462-
++depth;
463455
} else {
464456
/* ... this is a fallthru */
465457
newpos = pos + e->next_offset;
@@ -470,15 +462,8 @@ mark_source_chains(const struct xt_table_info *newinfo,
470462
e->counters.pcnt = pos;
471463
pos = newpos;
472464
}
473-
if (depth == 0)
474-
last_pos = pos;
475-
}
476-
next:
477-
if (last_pos != newinfo->underflow[hook]) {
478-
pr_err_ratelimited("last base chain position %u doesn't match underflow %u (hook %u)\n",
479-
last_pos, newinfo->underflow[hook], hook);
480-
return 0;
481465
}
466+
next: ;
482467
}
483468
return 1;
484469
}

0 commit comments

Comments
 (0)