Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

af_unix: Don't pass struct socket to maybe_add_creds().

We will move SOCK_PASS{CRED,PIDFD,SEC} from struct socket.flags
to struct sock for better handling with SOCK_PASSRIGHTS.

Then, we don't need to access struct socket in maybe_add_creds().

Let's pass struct sock to maybe_add_creds() and its caller
queue_oob().

While at it, we append the unix_ prefix and fix double spaces
around the pid assignment.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Kuniyuki Iwashima and committed by
David S. Miller
3041bbbe 350d4546

+12 -11
+12 -11
net/unix/af_unix.c
··· 1869 1869 { 1870 1870 int err = 0; 1871 1871 1872 - UNIXCB(skb).pid = get_pid(scm->pid); 1872 + UNIXCB(skb).pid = get_pid(scm->pid); 1873 1873 UNIXCB(skb).uid = scm->creds.uid; 1874 1874 UNIXCB(skb).gid = scm->creds.gid; 1875 1875 UNIXCB(skb).fp = NULL; ··· 1886 1886 * We include credentials if source or destination socket 1887 1887 * asserted SOCK_PASSCRED. 1888 1888 */ 1889 - static void maybe_add_creds(struct sk_buff *skb, const struct socket *sock, 1890 - const struct sock *other) 1889 + static void unix_maybe_add_creds(struct sk_buff *skb, const struct sock *sk, 1890 + const struct sock *other) 1891 1891 { 1892 1892 if (UNIXCB(skb).pid) 1893 1893 return; 1894 1894 1895 - if (unix_may_passcred(sock->sk) || 1895 + if (unix_may_passcred(sk) || 1896 1896 !other->sk_socket || unix_may_passcred(other)) { 1897 - UNIXCB(skb).pid = get_pid(task_tgid(current)); 1897 + UNIXCB(skb).pid = get_pid(task_tgid(current)); 1898 1898 current_uid_gid(&UNIXCB(skb).uid, &UNIXCB(skb).gid); 1899 1899 } 1900 1900 } ··· 2133 2133 2134 2134 if (sock_flag(other, SOCK_RCVTSTAMP)) 2135 2135 __net_timestamp(skb); 2136 - maybe_add_creds(skb, sock, other); 2136 + 2137 + unix_maybe_add_creds(skb, sk, other); 2137 2138 scm_stat_add(other, skb); 2138 2139 skb_queue_tail(&other->sk_receive_queue, skb); 2139 2140 unix_state_unlock(other); ··· 2162 2161 #define UNIX_SKB_FRAGS_SZ (PAGE_SIZE << get_order(32768)) 2163 2162 2164 2163 #if IS_ENABLED(CONFIG_AF_UNIX_OOB) 2165 - static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other, 2164 + static int queue_oob(struct sock *sk, struct msghdr *msg, struct sock *other, 2166 2165 struct scm_cookie *scm, bool fds_sent) 2167 2166 { 2168 2167 struct unix_sock *ousk = unix_sk(other); 2169 2168 struct sk_buff *skb; 2170 2169 int err; 2171 2170 2172 - skb = sock_alloc_send_skb(sock->sk, 1, msg->msg_flags & MSG_DONTWAIT, &err); 2171 + skb = sock_alloc_send_skb(sk, 1, msg->msg_flags & MSG_DONTWAIT, &err); 2173 2172 2174 2173 if (!skb) 2175 2174 return err; ··· 2193 2192 goto out; 2194 2193 } 2195 2194 2196 - maybe_add_creds(skb, sock, other); 2195 + unix_maybe_add_creds(skb, sk, other); 2197 2196 scm_stat_add(other, skb); 2198 2197 2199 2198 spin_lock(&other->sk_receive_queue.lock); ··· 2309 2308 (other->sk_shutdown & RCV_SHUTDOWN)) 2310 2309 goto out_pipe_unlock; 2311 2310 2312 - maybe_add_creds(skb, sock, other); 2311 + unix_maybe_add_creds(skb, sk, other); 2313 2312 scm_stat_add(other, skb); 2314 2313 skb_queue_tail(&other->sk_receive_queue, skb); 2315 2314 unix_state_unlock(other); ··· 2319 2318 2320 2319 #if IS_ENABLED(CONFIG_AF_UNIX_OOB) 2321 2320 if (msg->msg_flags & MSG_OOB) { 2322 - err = queue_oob(sock, msg, other, &scm, fds_sent); 2321 + err = queue_oob(sk, msg, other, &scm, fds_sent); 2323 2322 if (err) 2324 2323 goto out_err; 2325 2324 sent++;