Skip to content

Commit 326e5cf

Browse files
q2vengregkh
authored andcommitted
smc: Use __sk_dst_get() and dst_dev_rcu() in smc_clc_prfx_match().
[ Upstream commit 235f810 ] smc_clc_prfx_match() is called from smc_listen_work() and not under RCU nor RTNL. Using sk_dst_get(sk)->dev could trigger UAF. Let's use __sk_dst_get() and dst_dev_rcu(). Note that the returned value of smc_clc_prfx_match() is not used in the caller. Fixes: a046d57 ("smc: CLC handshake (incl. preparation steps)") Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20250916214758.650211-4-kuniyu@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 956c57d commit 326e5cf

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

net/smc/smc_clc.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -657,26 +657,26 @@ static int smc_clc_prfx_match6_rcu(struct net_device *dev,
657657
int smc_clc_prfx_match(struct socket *clcsock,
658658
struct smc_clc_msg_proposal_prefix *prop)
659659
{
660-
struct dst_entry *dst = sk_dst_get(clcsock->sk);
660+
struct net_device *dev;
661+
struct dst_entry *dst;
661662
int rc;
662663

663-
if (!dst) {
664-
rc = -ENOTCONN;
665-
goto out;
666-
}
667-
if (!dst->dev) {
664+
rcu_read_lock();
665+
666+
dst = __sk_dst_get(clcsock->sk);
667+
dev = dst ? dst_dev_rcu(dst) : NULL;
668+
if (!dev) {
668669
rc = -ENODEV;
669-
goto out_rel;
670+
goto out;
670671
}
671-
rcu_read_lock();
672+
672673
if (!prop->ipv6_prefixes_cnt)
673-
rc = smc_clc_prfx_match4_rcu(dst->dev, prop);
674+
rc = smc_clc_prfx_match4_rcu(dev, prop);
674675
else
675-
rc = smc_clc_prfx_match6_rcu(dst->dev, prop);
676-
rcu_read_unlock();
677-
out_rel:
678-
dst_release(dst);
676+
rc = smc_clc_prfx_match6_rcu(dev, prop);
679677
out:
678+
rcu_read_unlock();
679+
680680
return rc;
681681
}
682682

0 commit comments

Comments
 (0)