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

af_unix: introduce unix_skb_to_scm helper

Instead of open-coding let's consolidate this logic in a separate
helper. This will simplify further changes.

Cc: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@google.com>
Cc: Lennart Poettering <mzxreary@0pointer.de>
Cc: Luca Boccassi <bluca@debian.org>
Cc: David Rheinsberg <david@readahead.eu>
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Link: https://lore.kernel.org/20250703222314.309967-3-aleksandr.mikhalitsyn@canonical.com
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Alexander Mikhalitsyn and committed by
Christian Brauner
ee479762 9bedee7c

+8 -4
+8 -4
net/unix/af_unix.c
··· 1955 1955 return err; 1956 1956 } 1957 1957 1958 + static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm) 1959 + { 1960 + scm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid); 1961 + unix_set_secdata(scm, skb); 1962 + } 1963 + 1958 1964 /** 1959 1965 * unix_maybe_add_creds() - Adds current task uid/gid and struct pid to skb if needed. 1960 1966 * @skb: skb to attach creds to. ··· 2571 2565 2572 2566 memset(&scm, 0, sizeof(scm)); 2573 2567 2574 - scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid); 2575 - unix_set_secdata(&scm, skb); 2568 + unix_skb_to_scm(skb, &scm); 2576 2569 2577 2570 if (!(flags & MSG_PEEK)) { 2578 2571 if (UNIXCB(skb).fp) ··· 2956 2951 break; 2957 2952 } else if (unix_may_passcred(sk)) { 2958 2953 /* Copy credentials */ 2959 - scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid); 2960 - unix_set_secdata(&scm, skb); 2954 + unix_skb_to_scm(skb, &scm); 2961 2955 check_creds = true; 2962 2956 } 2963 2957