]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
udp: check udp sock encap_type in __udp_lib_err
authorXin Long <lucien.xin@gmail.com>
Thu, 29 Oct 2020 07:04:55 +0000 (15:04 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 30 Oct 2020 22:23:33 +0000 (15:23 -0700)
There is a chance that __udp4/6_lib_lookup() returns a udp encap
sock in __udp_lib_err(), like the udp encap listening sock may
use the same port as remote encap port, in which case it should
go to __udp4/6_lib_err_encap() for more validation before
processing the icmp packet.

This patch is to check encap_type in __udp_lib_err() for the
further validation for a encap sock.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/udp.c
net/ipv6/udp.c

index 09f0a23d1a01741d335ce45f25fe70a4e00698c7..ca04a8a35e52dbcff50b03da2710726dc6ee98bd 100644 (file)
@@ -702,7 +702,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
        sk = __udp4_lib_lookup(net, iph->daddr, uh->dest,
                               iph->saddr, uh->source, skb->dev->ifindex,
                               inet_sdif(skb), udptable, NULL);
-       if (!sk) {
+       if (!sk || udp_sk(sk)->encap_type) {
                /* No socket for error: try tunnels before discarding */
                sk = ERR_PTR(-ENOENT);
                if (static_branch_unlikely(&udp_encap_needed_key)) {
index 29d9691359b9c49ccb56a11f79e3658b1a76700d..cde9b8874d4bce4cdbee557d89a0be0ddf3f87df 100644 (file)
@@ -560,7 +560,7 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 
        sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source,
                               inet6_iif(skb), inet6_sdif(skb), udptable, NULL);
-       if (!sk) {
+       if (!sk || udp_sk(sk)->encap_type) {
                /* No socket for error: try tunnels before discarding */
                sk = ERR_PTR(-ENOENT);
                if (static_branch_unlikely(&udpv6_encap_needed_key)) {