Skip to content

Commit d824548

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: ebtables: remove BUGPRINT messages
They are however frequently triggered by syzkaller, so remove them. ebtables userspace should never trigger any of these, so there is little value in making them pr_debug (or ratelimited). Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 4283428 commit d824548

File tree

1 file changed

+39
-92
lines changed

1 file changed

+39
-92
lines changed

net/bridge/netfilter/ebtables.c

Lines changed: 39 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
/* needed for logical [in,out]-dev filtering */
3232
#include "../br_private.h"
3333

34-
#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
35-
"report to author: "format, ## args)
36-
/* #define BUGPRINT(format, args...) */
37-
3834
/* Each cpu has its own set of counters, so there is no need for write_lock in
3935
* the softirq
4036
* For reading or updating the counters, the user context needs to
@@ -466,8 +462,6 @@ static int ebt_verify_pointers(const struct ebt_replace *repl,
466462
/* we make userspace set this right,
467463
* so there is no misunderstanding
468464
*/
469-
BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
470-
"in distinguisher\n");
471465
return -EINVAL;
472466
}
473467
if (i != NF_BR_NUMHOOKS)
@@ -485,18 +479,14 @@ static int ebt_verify_pointers(const struct ebt_replace *repl,
485479
offset += e->next_offset;
486480
}
487481
}
488-
if (offset != limit) {
489-
BUGPRINT("entries_size too small\n");
482+
if (offset != limit)
490483
return -EINVAL;
491-
}
492484

493485
/* check if all valid hooks have a chain */
494486
for (i = 0; i < NF_BR_NUMHOOKS; i++) {
495487
if (!newinfo->hook_entry[i] &&
496-
(valid_hooks & (1 << i))) {
497-
BUGPRINT("Valid hook without chain\n");
488+
(valid_hooks & (1 << i)))
498489
return -EINVAL;
499-
}
500490
}
501491
return 0;
502492
}
@@ -523,42 +513,34 @@ ebt_check_entry_size_and_hooks(const struct ebt_entry *e,
523513
/* this checks if the previous chain has as many entries
524514
* as it said it has
525515
*/
526-
if (*n != *cnt) {
527-
BUGPRINT("nentries does not equal the nr of entries "
528-
"in the chain\n");
516+
if (*n != *cnt)
529517
return -EINVAL;
530-
}
518+
531519
if (((struct ebt_entries *)e)->policy != EBT_DROP &&
532520
((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
533521
/* only RETURN from udc */
534522
if (i != NF_BR_NUMHOOKS ||
535-
((struct ebt_entries *)e)->policy != EBT_RETURN) {
536-
BUGPRINT("bad policy\n");
523+
((struct ebt_entries *)e)->policy != EBT_RETURN)
537524
return -EINVAL;
538-
}
539525
}
540526
if (i == NF_BR_NUMHOOKS) /* it's a user defined chain */
541527
(*udc_cnt)++;
542-
if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
543-
BUGPRINT("counter_offset != totalcnt");
528+
if (((struct ebt_entries *)e)->counter_offset != *totalcnt)
544529
return -EINVAL;
545-
}
546530
*n = ((struct ebt_entries *)e)->nentries;
547531
*cnt = 0;
548532
return 0;
549533
}
550534
/* a plain old entry, heh */
551535
if (sizeof(struct ebt_entry) > e->watchers_offset ||
552536
e->watchers_offset > e->target_offset ||
553-
e->target_offset >= e->next_offset) {
554-
BUGPRINT("entry offsets not in right order\n");
537+
e->target_offset >= e->next_offset)
555538
return -EINVAL;
556-
}
539+
557540
/* this is not checked anywhere else */
558-
if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
559-
BUGPRINT("target size too small\n");
541+
if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target))
560542
return -EINVAL;
561-
}
543+
562544
(*cnt)++;
563545
(*totalcnt)++;
564546
return 0;
@@ -678,18 +660,15 @@ ebt_check_entry(struct ebt_entry *e, struct net *net,
678660
if (e->bitmask == 0)
679661
return 0;
680662

681-
if (e->bitmask & ~EBT_F_MASK) {
682-
BUGPRINT("Unknown flag for bitmask\n");
663+
if (e->bitmask & ~EBT_F_MASK)
683664
return -EINVAL;
684-
}
685-
if (e->invflags & ~EBT_INV_MASK) {
686-
BUGPRINT("Unknown flag for inv bitmask\n");
665+
666+
if (e->invflags & ~EBT_INV_MASK)
687667
return -EINVAL;
688-
}
689-
if ((e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3)) {
690-
BUGPRINT("NOPROTO & 802_3 not allowed\n");
668+
669+
if ((e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3))
691670
return -EINVAL;
692-
}
671+
693672
/* what hook do we belong to? */
694673
for (i = 0; i < NF_BR_NUMHOOKS; i++) {
695674
if (!newinfo->hook_entry[i])
@@ -748,13 +727,11 @@ ebt_check_entry(struct ebt_entry *e, struct net *net,
748727
t->u.target = target;
749728
if (t->u.target == &ebt_standard_target) {
750729
if (gap < sizeof(struct ebt_standard_target)) {
751-
BUGPRINT("Standard target size too big\n");
752730
ret = -EFAULT;
753731
goto cleanup_watchers;
754732
}
755733
if (((struct ebt_standard_target *)t)->verdict <
756734
-NUM_STANDARD_TARGETS) {
757-
BUGPRINT("Invalid standard target\n");
758735
ret = -EFAULT;
759736
goto cleanup_watchers;
760737
}
@@ -813,10 +790,9 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stack
813790
if (strcmp(t->u.name, EBT_STANDARD_TARGET))
814791
goto letscontinue;
815792
if (e->target_offset + sizeof(struct ebt_standard_target) >
816-
e->next_offset) {
817-
BUGPRINT("Standard target size too big\n");
793+
e->next_offset)
818794
return -1;
819-
}
795+
820796
verdict = ((struct ebt_standard_target *)t)->verdict;
821797
if (verdict >= 0) { /* jump to another chain */
822798
struct ebt_entries *hlp2 =
@@ -825,14 +801,12 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stack
825801
if (hlp2 == cl_s[i].cs.chaininfo)
826802
break;
827803
/* bad destination or loop */
828-
if (i == udc_cnt) {
829-
BUGPRINT("bad destination\n");
804+
if (i == udc_cnt)
830805
return -1;
831-
}
832-
if (cl_s[i].cs.n) {
833-
BUGPRINT("loop\n");
806+
807+
if (cl_s[i].cs.n)
834808
return -1;
835-
}
809+
836810
if (cl_s[i].hookmask & (1 << hooknr))
837811
goto letscontinue;
838812
/* this can't be 0, so the loop test is correct */
@@ -865,24 +839,21 @@ static int translate_table(struct net *net, const char *name,
865839
i = 0;
866840
while (i < NF_BR_NUMHOOKS && !newinfo->hook_entry[i])
867841
i++;
868-
if (i == NF_BR_NUMHOOKS) {
869-
BUGPRINT("No valid hooks specified\n");
842+
if (i == NF_BR_NUMHOOKS)
870843
return -EINVAL;
871-
}
872-
if (newinfo->hook_entry[i] != (struct ebt_entries *)newinfo->entries) {
873-
BUGPRINT("Chains don't start at beginning\n");
844+
845+
if (newinfo->hook_entry[i] != (struct ebt_entries *)newinfo->entries)
874846
return -EINVAL;
875-
}
847+
876848
/* make sure chains are ordered after each other in same order
877849
* as their corresponding hooks
878850
*/
879851
for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
880852
if (!newinfo->hook_entry[j])
881853
continue;
882-
if (newinfo->hook_entry[j] <= newinfo->hook_entry[i]) {
883-
BUGPRINT("Hook order must be followed\n");
854+
if (newinfo->hook_entry[j] <= newinfo->hook_entry[i])
884855
return -EINVAL;
885-
}
856+
886857
i = j;
887858
}
888859

@@ -900,15 +871,11 @@ static int translate_table(struct net *net, const char *name,
900871
if (ret != 0)
901872
return ret;
902873

903-
if (i != j) {
904-
BUGPRINT("nentries does not equal the nr of entries in the "
905-
"(last) chain\n");
874+
if (i != j)
906875
return -EINVAL;
907-
}
908-
if (k != newinfo->nentries) {
909-
BUGPRINT("Total nentries is wrong\n");
876+
877+
if (k != newinfo->nentries)
910878
return -EINVAL;
911-
}
912879

913880
/* get the location of the udc, put them in an array
914881
* while we're at it, allocate the chainstack
@@ -942,7 +909,6 @@ static int translate_table(struct net *net, const char *name,
942909
ebt_get_udc_positions, newinfo, &i, cl_s);
943910
/* sanity check */
944911
if (i != udc_cnt) {
945-
BUGPRINT("i != udc_cnt\n");
946912
vfree(cl_s);
947913
return -EFAULT;
948914
}
@@ -1042,7 +1008,6 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
10421008
goto free_unlock;
10431009

10441010
if (repl->num_counters && repl->num_counters != t->private->nentries) {
1045-
BUGPRINT("Wrong nr. of counters requested\n");
10461011
ret = -EINVAL;
10471012
goto free_unlock;
10481013
}
@@ -1118,15 +1083,12 @@ static int do_replace(struct net *net, const void __user *user,
11181083
if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
11191084
return -EFAULT;
11201085

1121-
if (len != sizeof(tmp) + tmp.entries_size) {
1122-
BUGPRINT("Wrong len argument\n");
1086+
if (len != sizeof(tmp) + tmp.entries_size)
11231087
return -EINVAL;
1124-
}
11251088

1126-
if (tmp.entries_size == 0) {
1127-
BUGPRINT("Entries_size never zero\n");
1089+
if (tmp.entries_size == 0)
11281090
return -EINVAL;
1129-
}
1091+
11301092
/* overflow check */
11311093
if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) /
11321094
NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter))
@@ -1153,7 +1115,6 @@ static int do_replace(struct net *net, const void __user *user,
11531115
}
11541116
if (copy_from_user(
11551117
newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
1156-
BUGPRINT("Couldn't copy entries from userspace\n");
11571118
ret = -EFAULT;
11581119
goto free_entries;
11591120
}
@@ -1194,10 +1155,8 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
11941155

11951156
if (input_table == NULL || (repl = input_table->table) == NULL ||
11961157
repl->entries == NULL || repl->entries_size == 0 ||
1197-
repl->counters != NULL || input_table->private != NULL) {
1198-
BUGPRINT("Bad table data for ebt_register_table!!!\n");
1158+
repl->counters != NULL || input_table->private != NULL)
11991159
return -EINVAL;
1200-
}
12011160

12021161
/* Don't add one table to multiple lists. */
12031162
table = kmemdup(input_table, sizeof(struct ebt_table), GFP_KERNEL);
@@ -1235,13 +1194,10 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
12351194
((char *)repl->hook_entry[i] - repl->entries);
12361195
}
12371196
ret = translate_table(net, repl->name, newinfo);
1238-
if (ret != 0) {
1239-
BUGPRINT("Translate_table failed\n");
1197+
if (ret != 0)
12401198
goto free_chainstack;
1241-
}
12421199

12431200
if (table->check && table->check(newinfo, table->valid_hooks)) {
1244-
BUGPRINT("The table doesn't like its own initial data, lol\n");
12451201
ret = -EINVAL;
12461202
goto free_chainstack;
12471203
}
@@ -1252,7 +1208,6 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,
12521208
list_for_each_entry(t, &net->xt.tables[NFPROTO_BRIDGE], list) {
12531209
if (strcmp(t->name, table->name) == 0) {
12541210
ret = -EEXIST;
1255-
BUGPRINT("Table name already exists\n");
12561211
goto free_unlock;
12571212
}
12581213
}
@@ -1320,7 +1275,6 @@ static int do_update_counters(struct net *net, const char *name,
13201275
goto free_tmp;
13211276

13221277
if (num_counters != t->private->nentries) {
1323-
BUGPRINT("Wrong nr of counters\n");
13241278
ret = -EINVAL;
13251279
goto unlock_mutex;
13261280
}
@@ -1447,10 +1401,8 @@ static int copy_counters_to_user(struct ebt_table *t,
14471401
if (num_counters == 0)
14481402
return 0;
14491403

1450-
if (num_counters != nentries) {
1451-
BUGPRINT("Num_counters wrong\n");
1404+
if (num_counters != nentries)
14521405
return -EINVAL;
1453-
}
14541406

14551407
counterstmp = vmalloc(array_size(nentries, sizeof(*counterstmp)));
14561408
if (!counterstmp)
@@ -1496,15 +1448,11 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
14961448
(tmp.num_counters ? nentries * sizeof(struct ebt_counter) : 0))
14971449
return -EINVAL;
14981450

1499-
if (tmp.nentries != nentries) {
1500-
BUGPRINT("Nentries wrong\n");
1451+
if (tmp.nentries != nentries)
15011452
return -EINVAL;
1502-
}
15031453

1504-
if (tmp.entries_size != entries_size) {
1505-
BUGPRINT("Wrong size\n");
1454+
if (tmp.entries_size != entries_size)
15061455
return -EINVAL;
1507-
}
15081456

15091457
ret = copy_counters_to_user(t, oldcounters, tmp.counters,
15101458
tmp.num_counters, nentries);
@@ -1576,7 +1524,6 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
15761524
}
15771525
mutex_unlock(&ebt_mutex);
15781526
if (copy_to_user(user, &tmp, *len) != 0) {
1579-
BUGPRINT("c2u Didn't work\n");
15801527
ret = -EFAULT;
15811528
break;
15821529
}

0 commit comments

Comments
 (0)