ipv4: start using dst_dev_rcu()
Subsystems (3)
PATCH 1/1 ipv4: start using dst_dev_rcu()
From: Eric Dumazet <[email protected]>
[ Upstream commit 6ad8de3cefdb6ffa6708b21c567df0dbf82c43a8 ]
Change icmpv4_xrlim_allow(), ip_defrag() to prevent possible UAF.
Change ipmr_prepare_xmit(), ipmr_queue_fwd_xmit(), ip_mr_output(), ipv4_neigh_lookup() to use lockdep enabled dst_dev_rcu().
Fixes 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()")
Signed-off-by Eric Dumazet <[email protected]>
Reviewed-by David Ahern <[email protected]>
Signed-off-by Jakub Kicinski <[email protected]>
[ Minor modifications made to adapt current code. ]
Signed-off-by Robert Garcia <[email protected]>
--- net/ipv4/icmp.c | 4 ++-- net/ipv4/ip_fragment.c | 6 ++++-- net/ipv4/ipmr.c | 4 ++-- net/ipv4/route.c | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-)
net/ipv4/icmp.c +2 -2
@@ -319,16 +319,16 @@ static bool icmpv4_xrlim_allow(struct net *net, struct rtable *rt,return true;/* No rate limit on loopback */ +rcu_read_lock ();if (dst->dev && (dst->dev->flags&IFF_LOOPBACK )) goto out; -rcu_read_lock (); peer =inet_getpeer_v4 (net->ipv4.peers, fl4->daddr,l3mdev_master_ifindex_rcu (dst->dev)); rc =inet_peer_xrlim_allow (peer,READ_ONCE (net->ipv4.sysctl_icmp_ratelimit)); -rcu_read_unlock (); out: +rcu_read_unlock ();if (!rc)__ICMP_INC_STATS (net,ICMP_MIB_RATELIMITHOST );else
net/ipv4/ip_fragment.c +4 -2
@@ -488,13 +488,15 @@ static int ip_frag_reasm(struct ipq *qp, struct sk_buff *skb,/* Process an incoming IP datagram fragment. */ int ip_defrag (struct net *net,struct sk_buff *skb,u32 user) { -struct net_device *dev = skb->dev ? :skb_dst (skb)->dev; -int vif =l3mdev_master_ifindex_rcu (dev); +struct net_device *dev;struct ipq *qp; +int vif;__IP_INC_STATS (net,IPSTATS_MIB_REASMREQDS );/* Lookup (or create) queue header */ + dev = skb->dev ? :skb_dst_dev_rcu (skb); + vif =l3mdev_master_ifindex_rcu (dev); qp =ip_find (net,ip_hdr (skb), user, vif);if (qp) {int ret;
net/ipv4/ipmr.c +2 -2
@@ -1905,7 +1905,7 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, goto out_free; } - encap +=LL_RESERVED_SPACE (dev) + rt->dst.header_len; + encap +=LL_RESERVED_SPACE (dst_dev_rcu (&rt->dst)) + rt->dst.header_len;if (skb_cow (skb, encap)) {ip_rt_put (rt);
@@ -1942,7 +1942,7 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,* result in receiving multiple packets. */ NF_HOOK (NFPROTO_IPV4 ,NF_INET_FORWARD , - net,NULL , skb, skb->dev, dev, + net,NULL , skb, skb->dev,dst_dev_rcu (&rt->dst), ipmr_forward_finish);return ;
net/ipv4/route.c +2 -2
@@ -416,11 +416,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst, const void *daddr) { const struct rtable *rt = container_of(dst, struct rtable, dst); -struct net_device *dev = dst->dev; +struct net_device *dev;struct neighbour *n;rcu_read_lock (); - + dev =dst_dev_rcu (dst);if (likely (rt->rt_gw_family ==AF_INET )) { n =ip_neigh_gw4 (dev, rt->rt_gw4); }else if (rt->rt_gw_family ==AF_INET6 ) {
Signature · 1 line
2.34.1
Sasha Levin
maintainerQuoted 3 lines
[PATCH 6.6.y] ipv4: start using
dst_dev_rcu()
[ Upstream commit6ad8de3cefdb6ffa6708b21c567df0dbf82c43a8] [ Minor modifications made to adapt current code. ]
Thanks for the backport. I think as proposed this introduces a bug: in 6.6.y the predecessor a74fc62eec155c (which adds dst_dev_rcu()) is missing, so skb_dst_dev_rcu() / dst_dev_rcu() ends up being called outside an RCU read-side section here.
Signature · 2 lines
Thanks, Sasha