Skip to content

Commit 198ad97

Browse files
committed
netfilter: remove BUG_ON() after skb_header_pointer()
Several conntrack helpers and the TCP tracker assume that skb_header_pointer() never fails based on upfront header validation. Even if this should not ever happen, BUG_ON() is a too drastic measure, remove them. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 5e024c3 commit 198ad97

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

net/netfilter/nf_conntrack_ftp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,10 @@ static int help(struct sk_buff *skb,
413413

414414
spin_lock_bh(&nf_ftp_lock);
415415
fb_ptr = skb_header_pointer(skb, dataoff, datalen, ftp_buffer);
416-
BUG_ON(fb_ptr == NULL);
416+
if (!fb_ptr) {
417+
spin_unlock_bh(&nf_ftp_lock);
418+
return NF_ACCEPT;
419+
}
417420

418421
ends_in_nl = (fb_ptr[datalen - 1] == '\n');
419422
seq = ntohl(th->seq) + datalen;

net/netfilter/nf_conntrack_h323_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ static int get_tpkt_data(struct sk_buff *skb, unsigned int protoff,
146146
/* Get first TPKT pointer */
147147
tpkt = skb_header_pointer(skb, tcpdataoff, tcpdatalen,
148148
h323_buffer);
149-
BUG_ON(tpkt == NULL);
149+
if (!tpkt)
150+
goto clear_out;
150151

151152
/* Validate TPKT identifier */
152153
if (tcpdatalen < 4 || tpkt[0] != 0x03 || tpkt[1] != 0) {

net/netfilter/nf_conntrack_irc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ static int help(struct sk_buff *skb, unsigned int protoff,
143143
spin_lock_bh(&irc_buffer_lock);
144144
ib_ptr = skb_header_pointer(skb, dataoff, skb->len - dataoff,
145145
irc_buffer);
146-
BUG_ON(ib_ptr == NULL);
146+
if (!ib_ptr) {
147+
spin_unlock_bh(&irc_buffer_lock);
148+
return NF_ACCEPT;
149+
}
147150

148151
data = ib_ptr;
149152
data_limit = ib_ptr + skb->len - dataoff;

net/netfilter/nf_conntrack_pptp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,9 @@ conntrack_pptp_help(struct sk_buff *skb, unsigned int protoff,
544544

545545
nexthdr_off = protoff;
546546
tcph = skb_header_pointer(skb, nexthdr_off, sizeof(_tcph), &_tcph);
547-
BUG_ON(!tcph);
547+
if (!tcph)
548+
return NF_ACCEPT;
549+
548550
nexthdr_off += tcph->doff * 4;
549551
datalen = tcplen - tcph->doff * 4;
550552

net/netfilter/nf_conntrack_proto_tcp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ static void tcp_options(const struct sk_buff *skb,
338338

339339
ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
340340
length, buff);
341-
BUG_ON(ptr == NULL);
341+
if (!ptr)
342+
return;
342343

343344
state->td_scale =
344345
state->flags = 0;
@@ -394,7 +395,8 @@ static void tcp_sack(const struct sk_buff *skb, unsigned int dataoff,
394395

395396
ptr = skb_header_pointer(skb, dataoff + sizeof(struct tcphdr),
396397
length, buff);
397-
BUG_ON(ptr == NULL);
398+
if (!ptr)
399+
return;
398400

399401
/* Fast path for timestamp-only option */
400402
if (length == TCPOLEN_TSTAMP_ALIGNED

net/netfilter/nf_conntrack_sane.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ static int help(struct sk_buff *skb,
9595

9696
spin_lock_bh(&nf_sane_lock);
9797
sb_ptr = skb_header_pointer(skb, dataoff, datalen, sane_buffer);
98-
BUG_ON(sb_ptr == NULL);
98+
if (!sb_ptr) {
99+
spin_unlock_bh(&nf_sane_lock);
100+
return NF_ACCEPT;
101+
}
99102

100103
if (dir == IP_CT_DIR_ORIGINAL) {
101104
if (datalen != sizeof(struct sane_request))

0 commit comments

Comments
 (0)