mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-16 04:04:06 +00:00
net: add sock_init_data_uid()
[ Upstream commit584f374289
] Add sock_init_data_uid() to explicitly initialize the socket uid. To initialise the socket uid, sock_init_data() assumes a the struct socket* sock is always embedded in a struct socket_alloc, used to access the corresponding inode uid. This may not be true. Examples are sockets created in tun_chr_open() and tap_open(). Fixes:86741ec254
("net: core: Add a UID field to struct sock.") Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
a6a7b73d75
commit
9ce999b4c7
2 changed files with 18 additions and 4 deletions
|
@ -1847,7 +1847,12 @@ void sk_common_release(struct sock *sk);
|
|||
* Default socket callbacks and setup code
|
||||
*/
|
||||
|
||||
/* Initialise core socket variables */
|
||||
/* Initialise core socket variables using an explicit uid. */
|
||||
void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid);
|
||||
|
||||
/* Initialise core socket variables.
|
||||
* Assumes struct socket *sock is embedded in a struct socket_alloc.
|
||||
*/
|
||||
void sock_init_data(struct socket *sock, struct sock *sk);
|
||||
|
||||
/*
|
||||
|
|
|
@ -3118,7 +3118,7 @@ void sk_stop_timer_sync(struct sock *sk, struct timer_list *timer)
|
|||
}
|
||||
EXPORT_SYMBOL(sk_stop_timer_sync);
|
||||
|
||||
void sock_init_data(struct socket *sock, struct sock *sk)
|
||||
void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid)
|
||||
{
|
||||
sk_init_common(sk);
|
||||
sk->sk_send_head = NULL;
|
||||
|
@ -3137,11 +3137,10 @@ void sock_init_data(struct socket *sock, struct sock *sk)
|
|||
sk->sk_type = sock->type;
|
||||
RCU_INIT_POINTER(sk->sk_wq, &sock->wq);
|
||||
sock->sk = sk;
|
||||
sk->sk_uid = SOCK_INODE(sock)->i_uid;
|
||||
} else {
|
||||
RCU_INIT_POINTER(sk->sk_wq, NULL);
|
||||
sk->sk_uid = make_kuid(sock_net(sk)->user_ns, 0);
|
||||
}
|
||||
sk->sk_uid = uid;
|
||||
|
||||
rwlock_init(&sk->sk_callback_lock);
|
||||
if (sk->sk_kern_sock)
|
||||
|
@ -3199,6 +3198,16 @@ void sock_init_data(struct socket *sock, struct sock *sk)
|
|||
refcount_set(&sk->sk_refcnt, 1);
|
||||
atomic_set(&sk->sk_drops, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(sock_init_data_uid);
|
||||
|
||||
void sock_init_data(struct socket *sock, struct sock *sk)
|
||||
{
|
||||
kuid_t uid = sock ?
|
||||
SOCK_INODE(sock)->i_uid :
|
||||
make_kuid(sock_net(sk)->user_ns, 0);
|
||||
|
||||
sock_init_data_uid(sock, sk, uid);
|
||||
}
|
||||
EXPORT_SYMBOL(sock_init_data);
|
||||
|
||||
void lock_sock_nested(struct sock *sk, int subclass)
|
||||
|
|
Loading…
Add table
Reference in a new issue