Skip to contentSkip to conversation

af_unix: Silence randstruct GCC plugin warning

PATCH In review Kees Cook 3 participants 3 messages May 11, 2022

Subsystems (4)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 af_unix: Silence randstruct GCC plugin warning

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 Jakub Kicinski <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Cong Wang <[email protected]>
Cc Al Viro <[email protected]>

---
If someone can Ack this, I can carry it in the gcc-plugins tree, as I'm trying to remove all its exceptions so I can drop that code.

---
 net/unix/af_unix.c                            | 8 +++-----
 scripts/gcc-plugins/randomize_layout_plugin.c | 2 --
 2 files changed, 3 insertions(+), 7 deletions(-)
net/unix/af_unix.c +3 -5
index e71a312faa1e..36367e7e3e0a 100644
@@ -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);
 }
 
scripts/gcc-plugins/randomize_layout_plugin.c +0 -2
index c9d345a91c41..2ca768d88a68 100644
@@ -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" },
 	{ }
 };
 
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
From:   Kees Cook <[email protected]>
Date:   Tue, 10 May 2022 17:01:09 -0700
Quoted 13 lines

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.

Quoted 11 lines
Cc "David S. Miller" <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Cong Wang <[email protected]>
Cc Al Viro <[email protected]>

LGTM, thank you.

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Kees Cook
Quoted 24 lines · On Tue, 10 May 2022 17:01:09 -0700 Kees Cook wrote:

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 Jakub Kicinski <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Cong Wang <[email protected]>
Cc Al Viro <[email protected]>
Quoted 3 lines

---
If someone can Ack this, I can carry it in the gcc-plugins tree, as I'm trying to remove all its exceptions so I can drop that code.