[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANn89i+Z5X5eEDVyAAEayLK60ziAeAs4ynwzw8XLe9bWy9GDUw@mail.gmail.com>
Date: Wed, 10 Sep 2025 23:28:03 -0700
From: Eric Dumazet <edumazet@...gle.com>
To: Kuniyuki Iwashima <kuniyu@...gle.com>
Cc: "David S. Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org,
"D. Wythe" <alibuda@...ux.alibaba.com>, Dust Li <dust.li@...ux.alibaba.com>,
Sidraya Jayagond <sidraya@...ux.ibm.com>, Wenjia Zhang <wenjia@...ux.ibm.com>,
Mahanta Jambigi <mjambigi@...ux.ibm.com>, Tony Lu <tonylu@...ux.alibaba.com>,
Wen Gu <guwen@...ux.alibaba.com>, Ursula Braun <ubraun@...ux.vnet.ibm.com>
Subject: Re: [PATCH v1 net 3/8] smc: Use sk_dst_dev_rcu() in in smc_clc_prfx_set().
On Wed, Sep 10, 2025 at 8:06 PM Kuniyuki Iwashima <kuniyu@...gle.com> wrote:
>
> smc_clc_prfx_set() is called during connect() and not under RCU
> nor RTNL.
>
> Using sk_dst_get(sk)->dev could trigger UAF.
>
> Let's use sk_dst_get_rcu() under rcu_read_lock() after
> kernel_getsockname().
>
> While at it, we change the 1st arg of smc_clc_prfx_set[46]_rcu()
> not to touch dst there.
>
> Fixes: a046d57da19f ("smc: CLC handshake (incl. preparation steps)")
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...gle.com>
> ---
> Cc: "D. Wythe" <alibuda@...ux.alibaba.com>
> Cc: Dust Li <dust.li@...ux.alibaba.com>
> Cc: Sidraya Jayagond <sidraya@...ux.ibm.com>
> Cc: Wenjia Zhang <wenjia@...ux.ibm.com>
> Cc: Mahanta Jambigi <mjambigi@...ux.ibm.com>
> Cc: Tony Lu <tonylu@...ux.alibaba.com>
> Cc: Wen Gu <guwen@...ux.alibaba.com>
> Cc: Ursula Braun <ubraun@...ux.vnet.ibm.com>
> ---
> net/smc/smc_clc.c | 39 ++++++++++++++++++++-------------------
> 1 file changed, 20 insertions(+), 19 deletions(-)
>
> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
> index 08be56dfb3f2..9aa1d75d3079 100644
> --- a/net/smc/smc_clc.c
> +++ b/net/smc/smc_clc.c
> @@ -509,10 +509,10 @@ static bool smc_clc_msg_hdr_valid(struct smc_clc_msg_hdr *clcm, bool check_trl)
> }
>
> /* find ipv4 addr on device and get the prefix len, fill CLC proposal msg */
> -static int smc_clc_prfx_set4_rcu(struct dst_entry *dst, __be32 ipv4,
> +static int smc_clc_prfx_set4_rcu(struct net_device *dev, __be32 ipv4,
> struct smc_clc_msg_proposal_prefix *prop)
> {
> - struct in_device *in_dev = __in_dev_get_rcu(dst->dev);
> + struct in_device *in_dev = __in_dev_get_rcu(dev);
> const struct in_ifaddr *ifa;
>
> if (!in_dev)
> @@ -530,12 +530,12 @@ static int smc_clc_prfx_set4_rcu(struct dst_entry *dst, __be32 ipv4,
> }
>
> /* fill CLC proposal msg with ipv6 prefixes from device */
> -static int smc_clc_prfx_set6_rcu(struct dst_entry *dst,
> +static int smc_clc_prfx_set6_rcu(struct net_device *dev,
> struct smc_clc_msg_proposal_prefix *prop,
> struct smc_clc_ipv6_prefix *ipv6_prfx)
> {
> #if IS_ENABLED(CONFIG_IPV6)
> - struct inet6_dev *in6_dev = __in6_dev_get(dst->dev);
> + struct inet6_dev *in6_dev = __in6_dev_get(dev);
> struct inet6_ifaddr *ifa;
> int cnt = 0;
>
> @@ -564,41 +564,42 @@ static int smc_clc_prfx_set(struct socket *clcsock,
> struct smc_clc_msg_proposal_prefix *prop,
> struct smc_clc_ipv6_prefix *ipv6_prfx)
> {
> - struct dst_entry *dst = sk_dst_get(clcsock->sk);
> struct sockaddr_storage addrs;
> struct sockaddr_in6 *addr6;
> struct sockaddr_in *addr;
> + struct net_device *dev;
> int rc = -ENOENT;
>
> - if (!dst) {
> - rc = -ENOTCONN;
> - goto out;
> - }
> - if (!dst->dev) {
> - rc = -ENODEV;
> - goto out_rel;
> - }
> /* get address to which the internal TCP socket is bound */
> if (kernel_getsockname(clcsock, (struct sockaddr *)&addrs) < 0)
> - goto out_rel;
> + goto out;
> +
> /* analyze IP specific data of net_device belonging to TCP socket */
> addr6 = (struct sockaddr_in6 *)&addrs;
> +
> rcu_read_lock();
> +
> + dev = sk_dst_dev_rcu(clcsock->sk);
> + if (!dev) {
> + rc = -ENODEV;
> + goto out_unlock;
> + }
> +
> if (addrs.ss_family == PF_INET) {
> /* IPv4 */
> addr = (struct sockaddr_in *)&addrs;
> - rc = smc_clc_prfx_set4_rcu(dst, addr->sin_addr.s_addr, prop);
> + rc = smc_clc_prfx_set4_rcu(dev, addr->sin_addr.s_addr, prop);
> } else if (ipv6_addr_v4mapped(&addr6->sin6_addr)) {
> /* mapped IPv4 address - peer is IPv4 only */
> - rc = smc_clc_prfx_set4_rcu(dst, addr6->sin6_addr.s6_addr32[3],
> + rc = smc_clc_prfx_set4_rcu(dev, addr6->sin6_addr.s6_addr32[3],
> prop);
> } else {
> /* IPv6 */
> - rc = smc_clc_prfx_set6_rcu(dst, prop, ipv6_prfx);
> + rc = smc_clc_prfx_set6_rcu(dev, prop, ipv6_prfx);
> }
> +
> +out_unlock:
> rcu_read_unlock();
> -out_rel:
> - dst_release(dst);
> out:
> return rc;
> }
> --
> 2.51.0.384.g4c02a37b29-goog
>
Same comment, I had a patch to fix this without a new helper.
We have hundreds of dst->dev places to fix, very few sk_dst_get().
This is why I think sk_dst_dev_rcu() is not necessary.
Powered by blists - more mailing lists