Skip to content

Commit

Permalink
af_unix: Silence randstruct GCC plugin warning
Browse files Browse the repository at this point in the history
While preparing for Clang randstruct support (which duplicated many of
the warnings the randstruct GCC plugin warned about), one strange one
remained only for the randstruct GCC plugin. Eliminating this rids
the plugin of the last exception.

It seems the plugin is happy to dereference individual members of
a cross-struct cast, but it is upset about casting to a whole object
pointer. This only manifests in one place in the kernel, so just replace
the variable with individual member accesses. There is no change in
executable instruction output.

Drop the last exception from the randstruct GCC plugin.

Cc: "David S. Miller" <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: Al Viro <[email protected]>
Cc: [email protected]
Cc: [email protected]
Acked-by: Kuniyuki Iwashima <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
Acked-by: Jakub Kicinski <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed May 16, 2022
1 parent 2dcfe9e commit b146cbf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 3 additions & 5 deletions net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,11 +1808,9 @@ static int maybe_init_creds(struct scm_cookie *scm,
static bool unix_skb_scm_eq(struct sk_buff *skb,
struct scm_cookie *scm)
{
const struct unix_skb_parms *u = &UNIXCB(skb);

return u->pid == scm->pid &&
uid_eq(u->uid, scm->creds.uid) &&
gid_eq(u->gid, scm->creds.gid) &&
return UNIXCB(skb).pid == scm->pid &&
uid_eq(UNIXCB(skb).uid, scm->creds.uid) &&
gid_eq(UNIXCB(skb).gid, scm->creds.gid) &&
unix_secdata_eq(scm, skb);
}

Expand Down
2 changes: 0 additions & 2 deletions scripts/gcc-plugins/randomize_layout_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ struct whitelist_entry {
};

static const struct whitelist_entry whitelist[] = {
/* unix_skb_parms via UNIXCB() buffer */
{ "net/unix/af_unix.c", "unix_skb_parms", "char" },
{ }
};

Expand Down

0 comments on commit b146cbf

Please sign in to comment.