Skip to content

Commit c89477a

Browse files
edumazetkuba-moo
authored andcommitted
inet: RAW sockets using IPPROTO_RAW MUST drop incoming ICMP
Yizhou Zhao reported that simply having one RAW socket on protocol IPPROTO_RAW (255) was dangerous. socket(AF_INET, SOCK_RAW, 255); A malicious incoming ICMP packet can set the protocol field to 255 and match this socket, leading to FNHE cache changes. inner = IP(src="192.168.2.1", dst="8.8.8.8", proto=255)/Raw("TEST") pkt = IP(src="192.168.1.1", dst="192.168.2.1")/ICMP(type=3, code=4, nexthopmtu=576)/inner "man 7 raw" states: A protocol of IPPROTO_RAW implies enabled IP_HDRINCL and is able to send any IP protocol that is specified in the passed header. Receiving of all IP protocols via IPPROTO_RAW is not possible using raw sockets. Make sure we drop these malicious packets. Fixes: 1da177e ("Linux-2.6.12-rc2") Reported-by: Yizhou Zhao <[email protected]> Link: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6a65c0c commit c89477a

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

net/ipv4/icmp.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,16 +1031,22 @@ static void icmp_socket_deliver(struct sk_buff *skb, u32 info)
10311031
/* Checkin full IP header plus 8 bytes of protocol to
10321032
* avoid additional coding at protocol handlers.
10331033
*/
1034-
if (!pskb_may_pull(skb, iph->ihl * 4 + 8)) {
1035-
__ICMP_INC_STATS(dev_net_rcu(skb->dev), ICMP_MIB_INERRORS);
1036-
return;
1037-
}
1034+
if (!pskb_may_pull(skb, iph->ihl * 4 + 8))
1035+
goto out;
1036+
1037+
/* IPPROTO_RAW sockets are not supposed to receive anything. */
1038+
if (protocol == IPPROTO_RAW)
1039+
goto out;
10381040

10391041
raw_icmp_error(skb, protocol, info);
10401042

10411043
ipprot = rcu_dereference(inet_protos[protocol]);
10421044
if (ipprot && ipprot->err_handler)
10431045
ipprot->err_handler(skb, info);
1046+
return;
1047+
1048+
out:
1049+
__ICMP_INC_STATS(dev_net_rcu(skb->dev), ICMP_MIB_INERRORS);
10441050
}
10451051

10461052
static bool icmp_tag_validation(int proto)

net/ipv6/icmp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,12 @@ enum skb_drop_reason icmpv6_notify(struct sk_buff *skb, u8 type,
10661066
if (reason != SKB_NOT_DROPPED_YET)
10671067
goto out;
10681068

1069+
if (nexthdr == IPPROTO_RAW) {
1070+
/* Add a more specific reason later ? */
1071+
reason = SKB_DROP_REASON_NOT_SPECIFIED;
1072+
goto out;
1073+
}
1074+
10691075
/* BUGGG_FUTURE: we should try to parse exthdrs in this packet.
10701076
Without this we will not able f.e. to make source routed
10711077
pmtu discovery.

0 commit comments

Comments
 (0)