diff options
author | Eric Dumazet <edumazet@google.com> | 2025-06-20 13:30:00 +0000 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2025-06-23 17:04:03 -0700 |
commit | e84a4927a404f369c842c19de93b216627fcc690 (patch) | |
tree | 901784e2f1bbcbcfbc36eff81b0d685abd7140e6 /net/socket.c | |
parent | b630c781bcf6ff87657146661816d0d30a902139 (diff) |
net: annotate races around sk->sk_uid
sk->sk_uid can be read while another thread changes its
value in sockfs_setattr().
Add sk_uid(const struct sock *sk) helper to factorize the needed
READ_ONCE() annotations, and add corresponding WRITE_ONCE()
where needed.
Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Reviewed-by: Maciej Żenczykowski <maze@google.com>
Link: https://patch.msgid.link/20250620133001.4090592-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/net/socket.c b/net/socket.c index 2cab805943c0..682969deaed3 100644 --- a/net/socket.c +++ b/net/socket.c @@ -592,10 +592,12 @@ static int sockfs_setattr(struct mnt_idmap *idmap, if (!err && (iattr->ia_valid & ATTR_UID)) { struct socket *sock = SOCKET_I(d_inode(dentry)); - if (sock->sk) - sock->sk->sk_uid = iattr->ia_uid; - else + if (sock->sk) { + /* Paired with READ_ONCE() in sk_uid() */ + WRITE_ONCE(sock->sk->sk_uid, iattr->ia_uid); + } else { err = -ENOENT; + } } return err; |