Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7a7dd70c authored by Jann Horn's avatar Jann Horn Committed by Greg Kroah-Hartman
Browse files

dccp: Fix out of bounds access in DCCP error handler



commit 977ad86c2a1bcaf58f01ab98df5cc145083c489c upstream.

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: 6706a97f ("dccp: fix out of bound access in dccp_v4_err()")
Fixes: 1aa9d1a0 ("ipv6: dccp: fix out of bound access in dccp_v6_err()")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJann Horn <jannh@google.com>
Reviewed-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1c675c93
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -243,12 +243,17 @@ static int dccp_v4_err(struct sk_buff *skb, u32 info)
	int err;
	struct net *net = dev_net(skb->dev);

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

	sk = __inet_lookup_established(net, &dccp_hashinfo,
+10 −5
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ static inline __u64 dccp_v6_init_sequence(struct sk_buff *skb)
static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
			u8 type, u8 code, int offset, __be32 info)
{
	const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data;
	const struct ipv6hdr *hdr;
	const struct dccp_hdr *dh;
	struct dccp_sock *dp;
	struct ipv6_pinfo *np;
@@ -76,12 +76,17 @@ static int dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
	__u64 seq;
	struct net *net = dev_net(skb->dev);

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

	sk = __inet6_lookup_established(net, &dccp_hashinfo,