Skip to content

Commit ee47976

Browse files
mihalicynbrauner
authored andcommitted
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>
1 parent 9bedee7 commit ee47976

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

net/unix/af_unix.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,12 @@ static int unix_scm_to_skb(struct scm_cookie *scm, struct sk_buff *skb, bool sen
19551955
return err;
19561956
}
19571957

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+
19581964
/**
19591965
* unix_maybe_add_creds() - Adds current task uid/gid and struct pid to skb if needed.
19601966
* @skb: skb to attach creds to.
@@ -2565,8 +2571,7 @@ int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
25652571

25662572
memset(&scm, 0, sizeof(scm));
25672573

2568-
scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
2569-
unix_set_secdata(&scm, skb);
2574+
unix_skb_to_scm(skb, &scm);
25702575

25712576
if (!(flags & MSG_PEEK)) {
25722577
if (UNIXCB(skb).fp)
@@ -2951,8 +2956,7 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
29512956
break;
29522957
} else if (unix_may_passcred(sk)) {
29532958
/* Copy credentials */
2954-
scm_set_cred(&scm, UNIXCB(skb).pid, UNIXCB(skb).uid, UNIXCB(skb).gid);
2955-
unix_set_secdata(&scm, skb);
2959+
unix_skb_to_scm(skb, &scm);
29562960
check_creds = true;
29572961
}
29582962

0 commit comments

Comments
 (0)