Skip to content

Commit 977ad86

Browse files
thejhdavem330
authored andcommitted
dccp: Fix out of bounds access in DCCP error handler
There was a previous attempt to fix an out-of-bounds access in the DCCP error handlers, but that fix assumed that the error handlers only want to access the first 8 bytes of the DCCP header. Actually, they also look at the DCCP sequence number, which is stored beyond 8 bytes, so an explicit pskb_may_pull() is required. Fixes: 6706a97 ("dccp: fix out of bound access in dccp_v4_err()") Fixes: 1aa9d1a ("ipv6: dccp: fix out of bound access in dccp_v6_err()") Cc: stable@vger.kernel.org Signed-off-by: Jann Horn <jannh@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 72dd7e4 commit 977ad86

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

net/dccp/ipv4.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ static int dccp_v4_err(struct sk_buff *skb, u32 info)
255255
int err;
256256
struct net *net = dev_net(skb->dev);
257257

258-
/* Only need dccph_dport & dccph_sport which are the first
259-
* 4 bytes in dccp header.
258+
/* For the first __dccp_basic_hdr_len() check, we only need dh->dccph_x,
259+
* which is in byte 7 of the dccp header.
260260
* Our caller (icmp_socket_deliver()) already pulled 8 bytes for us.
261+
*
262+
* Later on, we want to access the sequence number fields, which are
263+
* beyond 8 bytes, so we have to pskb_may_pull() ourselves.
261264
*/
262-
BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_sport) > 8);
263-
BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_dport) > 8);
265+
dh = (struct dccp_hdr *)(skb->data + offset);
266+
if (!pskb_may_pull(skb, offset + __dccp_basic_hdr_len(dh)))
267+
return -EINVAL;
268+
iph = (struct iphdr *)skb->data;
264269
dh = (struct dccp_hdr *)(skb->data + offset);
265270

266271
sk = __inet_lookup_established(net, &dccp_hashinfo,

net/dccp/ipv6.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static inline __u64 dccp_v6_init_sequence(struct sk_buff *skb)
7474
static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
7575
u8 type, u8 code, int offset, __be32 info)
7676
{
77-
const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
77+
const struct ipv6hdr *hdr;
7878
const struct dccp_hdr *dh;
7979
struct dccp_sock *dp;
8080
struct ipv6_pinfo *np;
@@ -83,12 +83,17 @@ static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
8383
__u64 seq;
8484
struct net *net = dev_net(skb->dev);
8585

86-
/* Only need dccph_dport & dccph_sport which are the first
87-
* 4 bytes in dccp header.
86+
/* For the first __dccp_basic_hdr_len() check, we only need dh->dccph_x,
87+
* which is in byte 7 of the dccp header.
8888
* Our caller (icmpv6_notify()) already pulled 8 bytes for us.
89+
*
90+
* Later on, we want to access the sequence number fields, which are
91+
* beyond 8 bytes, so we have to pskb_may_pull() ourselves.
8992
*/
90-
BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_sport) > 8);
91-
BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_dport) > 8);
93+
dh = (struct dccp_hdr *)(skb->data + offset);
94+
if (!pskb_may_pull(skb, offset + __dccp_basic_hdr_len(dh)))
95+
return -EINVAL;
96+
hdr = (const struct ipv6hdr *)skb->data;
9297
dh = (struct dccp_hdr *)(skb->data + offset);
9398

9499
sk = __inet6_lookup_established(net, &dccp_hashinfo,

0 commit comments

Comments
 (0)