Skip to content

Commit d26796a

Browse files
lxinkuba-moo
authored andcommitted
udp: check udp sock encap_type in __udp_lib_err
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>
1 parent 1fb7419 commit d26796a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

net/ipv4/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
702702
sk = __udp4_lib_lookup(net, iph->daddr, uh->dest,
703703
iph->saddr, uh->source, skb->dev->ifindex,
704704
inet_sdif(skb), udptable, NULL);
705-
if (!sk) {
705+
if (!sk || udp_sk(sk)->encap_type) {
706706
/* No socket for error: try tunnels before discarding */
707707
sk = ERR_PTR(-ENOENT);
708708
if (static_branch_unlikely(&udp_encap_needed_key)) {

net/ipv6/udp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
560560

561561
sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source,
562562
inet6_iif(skb), inet6_sdif(skb), udptable, NULL);
563-
if (!sk) {
563+
if (!sk || udp_sk(sk)->encap_type) {
564564
/* No socket for error: try tunnels before discarding */
565565
sk = ERR_PTR(-ENOENT);
566566
if (static_branch_unlikely(&udpv6_encap_needed_key)) {

0 commit comments

Comments
 (0)