aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorAlexander Mikhalitsyn <[email protected]>2025-07-03 22:23:06 +0000
committerChristian Brauner <[email protected]>2025-07-04 07:32:35 +0000
commitee47976264cd499426c89328827970ffb6acd406 (patch)
treee6c286eaa8611fd5ebfd62e1b9d86455266a784d /net/unix/af_unix.c
parentaf_unix: rework unix_maybe_add_creds() to allow sleep (diff)
downloadkernel-ee47976264cd499426c89328827970ffb6acd406.tar.gz
kernel-ee47976264cd499426c89328827970ffb6acd406.zip
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: [email protected] Cc: [email protected] Cc: David S. Miller <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Cc: Simon Horman <[email protected]> Cc: Leon Romanovsky <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Kuniyuki Iwashima <[email protected]> Cc: Lennart Poettering <[email protected]> Cc: Luca Boccassi <[email protected]> Cc: David Rheinsberg <[email protected]> Signed-off-by: Alexander Mikhalitsyn <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index fba50ceab42b..df2174d9904d 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1955,6 +1955,12 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
return err;
}
+static void unix_skb_to_scm(struct sk_buff *skb, struct scm_cookie *scm)
+{
+ scm_set_cred(scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
+ unix_set_secdata(scm, skb);
+}
+
/**
* unix_maybe_add_creds() - Adds current task uid/gid and struct pid to skb if needed.
* @skb: skb to attach creds to.
@@ -2565,8 +2571,7 @@ int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
memset(&scm, 0, sizeof(scm));
- scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
- unix_set_secdata(&scm, skb);
+ unix_skb_to_scm(skb, &scm);
if (!(flags & MSG_PEEK)) {
if (UNIXCB(skb).fp)
@@ -2951,8 +2956,7 @@ unlock:
break;
} else if (unix_may_passcred(sk)) {
/* Copy credentials */
- scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
- unix_set_secdata(&scm, skb);
+ unix_skb_to_scm(skb, &scm);
check_creds = true;
}