This is a note to let you know that I've just added the patch titled ipv4: fix source address selection with route leak to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ipv4-fix-source-address-selection-with-route-leak.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit dfd009372d960dc1ccf694e7369d58e63cd133c4 Author: Nicolas Dichtel <nicolas.dichtel@xxxxxxxxx> Date: Wed Jul 10 10:14:27 2024 +0200 ipv4: fix source address selection with route leak [ Upstream commit 6807352353561187a718e87204458999dbcbba1b ] By default, an address assigned to the output interface is selected when the source address is not specified. This is problematic when a route, configured in a vrf, uses an interface from another vrf (aka route leak). The original vrf does not own the selected source address. Let's add a check against the output interface and call the appropriate function to select the source address. CC: stable@xxxxxxxxxxxxxxx Fixes: 8cbb512c923d ("net: Add source address lookup op for VRF") Signed-off-by: Nicolas Dichtel <nicolas.dichtel@xxxxxxxxx> Reviewed-by: David Ahern <dsahern@xxxxxxxxxx> Link: https://patch.msgid.link/20240710081521.3809742-2-nicolas.dichtel@xxxxxxxxx Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index 3d00253afbb8d..4f1236458c214 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2286,6 +2286,15 @@ void fib_select_path(struct net *net, struct fib_result *res, fib_select_default(fl4, res); check_saddr: - if (!fl4->saddr) - fl4->saddr = fib_result_prefsrc(net, res); + if (!fl4->saddr) { + struct net_device *l3mdev; + + l3mdev = dev_get_by_index_rcu(net, fl4->flowi4_l3mdev); + + if (!l3mdev || + l3mdev_master_dev_rcu(FIB_RES_DEV(*res)) == l3mdev) + fl4->saddr = fib_result_prefsrc(net, res); + else + fl4->saddr = inet_select_addr(l3mdev, 0, RT_SCOPE_LINK); + } }