Commit 75664d80 authored by Willem de Bruijn's avatar Willem de Bruijn Committed by Greg Kroah-Hartman

ip: on queued skb use skb_header_pointer instead of pskb_may_pull

[ Upstream commit 4a06fa67 ]

Commit 2efd4fca ("ip: in cmsg IP(V6)_ORIGDSTADDR call
pskb_may_pull") avoided a read beyond the end of the skb linear
segment by calling pskb_may_pull.

That function can trigger a BUG_ON in pskb_expand_head if the skb is
shared, which it is when when peeking. It can also return ENOMEM.

Avoid both by switching to safer skb_header_pointer.

Fixes: 2efd4fca ("ip: in cmsg IP(V6)_ORIGDSTADDR call pskb_may_pull")
Reported-by: default avatarsyzbot <syzkaller@googlegroups.com>
Suggested-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarWillem de Bruijn <willemb@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0bab9990
...@@ -146,19 +146,17 @@ static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb) ...@@ -146,19 +146,17 @@ static void ip_cmsg_recv_security(struct msghdr *msg, struct sk_buff *skb)
static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb) static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb)
{ {
__be16 _ports[2], *ports;
struct sockaddr_in sin; struct sockaddr_in sin;
__be16 *ports;
int end;
end = skb_transport_offset(skb) + 4;
if (end > 0 && !pskb_may_pull(skb, end))
return;
/* All current transport protocols have the port numbers in the /* All current transport protocols have the port numbers in the
* first four bytes of the transport header and this function is * first four bytes of the transport header and this function is
* written with this assumption in mind. * written with this assumption in mind.
*/ */
ports = (__be16 *)skb_transport_header(skb); ports = skb_header_pointer(skb, skb_transport_offset(skb),
sizeof(_ports), &_ports);
if (!ports)
return;
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = ip_hdr(skb)->daddr; sin.sin_addr.s_addr = ip_hdr(skb)->daddr;
......
...@@ -709,17 +709,15 @@ void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg, ...@@ -709,17 +709,15 @@ void ip6_datagram_recv_specific_ctl(struct sock *sk, struct msghdr *msg,
} }
if (np->rxopt.bits.rxorigdstaddr) { if (np->rxopt.bits.rxorigdstaddr) {
struct sockaddr_in6 sin6; struct sockaddr_in6 sin6;
__be16 *ports; __be16 _ports[2], *ports;
int end;
end = skb_transport_offset(skb) + 4; ports = skb_header_pointer(skb, skb_transport_offset(skb),
if (end <= 0 || pskb_may_pull(skb, end)) { sizeof(_ports), &_ports);
if (ports) {
/* All current transport protocols have the port numbers in the /* All current transport protocols have the port numbers in the
* first four bytes of the transport header and this function is * first four bytes of the transport header and this function is
* written with this assumption in mind. * written with this assumption in mind.
*/ */
ports = (__be16 *)skb_transport_header(skb);
sin6.sin6_family = AF_INET6; sin6.sin6_family = AF_INET6;
sin6.sin6_addr = ipv6_hdr(skb)->daddr; sin6.sin6_addr = ipv6_hdr(skb)->daddr;
sin6.sin6_port = ports[1]; sin6.sin6_port = ports[1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment