mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
ipv4: snapshot dst.dev in ip_rt_send_redirect() and ip_rt_get_source()
rt_flush_dev() can replace rt->dst.dev with blackhole_netdev while RCU readers are running. ip_rt_send_redirect() and ip_rt_get_source() both read rt->dst.dev more than once and use the results in one operation. If rt->dst.dev changes between those reads, the operation can use values from two devices. For example, ip_rt_send_redirect() can use in_dev from the old device and the L3 master ifindex from blackhole_netdev. Read rt->dst.dev once in these two functions and use the snapshot for the later device accesses. Signed-off-by: Xuanqiang Luo <luoxuanqiang@kylinos.cn> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20260708060537.17188-3-xuanqiang.luo@linux.dev Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
committed by
Paolo Abeni
parent
1469773b24
commit
7804eaa057
+18
-13
@@ -874,21 +874,23 @@ void ip_rt_send_redirect(struct sk_buff *skb)
|
||||
{
|
||||
struct rtable *rt = skb_rtable(skb);
|
||||
struct in_device *in_dev;
|
||||
struct net_device *dev;
|
||||
struct inet_peer *peer;
|
||||
struct net *net;
|
||||
int log_martians;
|
||||
struct net *net;
|
||||
int vif;
|
||||
|
||||
rcu_read_lock();
|
||||
in_dev = __in_dev_get_rcu(rt->dst.dev);
|
||||
dev = dst_dev_rcu(&rt->dst);
|
||||
in_dev = __in_dev_get_rcu(dev);
|
||||
if (!in_dev || !IN_DEV_TX_REDIRECTS(in_dev)) {
|
||||
rcu_read_unlock();
|
||||
return;
|
||||
}
|
||||
log_martians = IN_DEV_LOG_MARTIANS(in_dev);
|
||||
vif = l3mdev_master_ifindex_rcu(rt->dst.dev);
|
||||
vif = l3mdev_master_ifindex_rcu(dev);
|
||||
|
||||
net = dev_net(rt->dst.dev);
|
||||
net = dev_net_rcu(dev);
|
||||
peer = inet_getpeer_v4(net->ipv4.peers, ip_hdr(skb)->saddr, vif);
|
||||
if (!peer) {
|
||||
rcu_read_unlock();
|
||||
@@ -1287,29 +1289,32 @@ void ip_rt_get_source(u8 *addr, struct sk_buff *skb, struct rtable *rt)
|
||||
{
|
||||
__be32 src;
|
||||
|
||||
if (rt_is_output_route(rt))
|
||||
rcu_read_lock();
|
||||
if (rt_is_output_route(rt)) {
|
||||
src = ip_hdr(skb)->saddr;
|
||||
else {
|
||||
struct fib_result res;
|
||||
} else {
|
||||
struct net_device *dev = dst_dev_rcu(&rt->dst);
|
||||
struct net *net = dev_net_rcu(dev);
|
||||
struct iphdr *iph = ip_hdr(skb);
|
||||
struct fib_result res;
|
||||
struct flowi4 fl4 = {
|
||||
.daddr = iph->daddr,
|
||||
.saddr = iph->saddr,
|
||||
.flowi4_dscp = ip4h_dscp(iph),
|
||||
.flowi4_oif = rt->dst.dev->ifindex,
|
||||
.flowi4_oif = dev->ifindex,
|
||||
.flowi4_iif = skb->dev->ifindex,
|
||||
.flowi4_mark = skb->mark,
|
||||
};
|
||||
|
||||
rcu_read_lock();
|
||||
if (fib_lookup(dev_net(rt->dst.dev), &fl4, &res, 0) == 0)
|
||||
src = fib_result_prefsrc(dev_net(rt->dst.dev), &res);
|
||||
if (fib_lookup(net, &fl4, &res, 0) == 0)
|
||||
src = fib_result_prefsrc(net, &res);
|
||||
else
|
||||
src = inet_select_addr(rt->dst.dev,
|
||||
src = inet_select_addr(dev,
|
||||
rt_nexthop(rt, iph->daddr),
|
||||
RT_SCOPE_UNIVERSE);
|
||||
rcu_read_unlock();
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
memcpy(addr, &src, 4);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user