Skip to content

Commit ba66bbe

Browse files
borkmanndavem330
authored andcommitted
udp: use sk_filter_trim_cap for udp{,6}_queue_rcv_skb
After a612769 ("udp: prevent bugcheck if filter truncates packet too much"), there followed various other fixes for similar cases such as f4979fc ("rose: limit sk_filter trim to payload"). Latter introduced a new helper sk_filter_trim_cap(), where we can pass the trim limit directly to the socket filter handling. Make use of it here as well with sizeof(struct udphdr) as lower cap limit and drop the extra skb->len test in UDP's input path. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Willem de Bruijn <willemb@google.com> Acked-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent deb1f45 commit ba66bbe

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

net/ipv4/udp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
15811581
udp_lib_checksum_complete(skb))
15821582
goto csum_error;
15831583

1584-
if (sk_filter(sk, skb))
1585-
goto drop;
1586-
if (unlikely(skb->len < sizeof(struct udphdr)))
1584+
if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr)))
15871585
goto drop;
15881586

15891587
udp_csum_pull_header(skb);

net/ipv6/udp.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
618618
udp_lib_checksum_complete(skb))
619619
goto csum_error;
620620

621-
if (sk_filter(sk, skb))
622-
goto drop;
623-
if (unlikely(skb->len < sizeof(struct udphdr)))
621+
if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr)))
624622
goto drop;
625623

626624
udp_csum_pull_header(skb);

0 commit comments

Comments
 (0)