* [PATCH] af_unix: introduce unix_sk_const helper
@ 2015-10-06 20:52 Arnd Bergmann
2015-10-08 11:03 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2015-10-06 20:52 UTC (permalink / raw)
To: netdev
Cc: Aaron Conole, Eric Dumazet, David Miller, James Morris,
linux-security-module, Serge E. Hallyn, linux-kernel
Commit 124613012db1 ("af_unix: Convert the unix_sk macro to an inline
function for type safety") was recently added to catch incorrect
uses of the unix_sk helper using compiler warnings.
It has now caught one such case in lsm_audit.c. The code is technically
correct, but as it converts a const pointer to a non-const pointer,
the annotation got lost, which gcc now warns about.
This patch avoids the warning by introducing an additional helper
that has const input and output, which makes the lsm_audit code build
cleanly again.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I'm not entirely happy with this workaround myself, but could not come
up with a better one.
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index cb1b9bbda332..1871b6436ee9 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -69,6 +69,11 @@ static inline struct unix_sock *unix_sk(struct sock *sk)
return (struct unix_sock *)sk;
}
+static inline const struct unix_sock *unix_sk_const(const struct sock *sk)
+{
+ return (const struct unix_sock *)sk;
+}
+
#define peer_wait peer_wq.wait
long unix_inq_len(struct sock *sk);
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 2deace208db2..cb07f1318a27 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -307,7 +307,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
case LSM_AUDIT_DATA_NET:
if (a->u.net->sk) {
const struct sock *sk = a->u.net->sk;
- struct unix_sock *u;
+ const struct unix_sock *u;
int len = 0;
char *p = NULL;
@@ -337,7 +337,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
}
#endif
case AF_UNIX:
- u = unix_sk(sk);
+ u = unix_sk_const(sk);
if (u->path.dentry) {
audit_log_d_path(ab, " path=", &u->path);
break;
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] af_unix: introduce unix_sk_const helper
2015-10-06 20:52 [PATCH] af_unix: introduce unix_sk_const helper Arnd Bergmann
@ 2015-10-08 11:03 ` David Miller
2015-10-08 12:11 ` Arnd Bergmann
0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2015-10-08 11:03 UTC (permalink / raw)
To: arnd
Cc: netdev, aconole, edumazet, james.l.morris, linux-security-module,
serge, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
Date: Tue, 06 Oct 2015 22:52:46 +0200
> Commit 124613012db1 ("af_unix: Convert the unix_sk macro to an inline
> function for type safety") was recently added to catch incorrect
> uses of the unix_sk helper using compiler warnings.
>
> It has now caught one such case in lsm_audit.c. The code is technically
> correct, but as it converts a const pointer to a non-const pointer,
> the annotation got lost, which gcc now warns about.
>
> This patch avoids the warning by introducing an additional helper
> that has const input and output, which makes the lsm_audit code build
> cleanly again.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I'm not entirely happy with this workaround myself, but could not come
> up with a better one.
You can make the argument unconditionally const, as Paul Moore has done
in a separate patch submission.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] af_unix: introduce unix_sk_const helper
2015-10-08 11:03 ` David Miller
@ 2015-10-08 12:11 ` Arnd Bergmann
0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2015-10-08 12:11 UTC (permalink / raw)
To: David Miller
Cc: netdev, aconole, edumazet, james.l.morris, linux-security-module,
serge, linux-kernel
On Thursday 08 October 2015 04:03:32 David Miller wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> Date: Tue, 06 Oct 2015 22:52:46 +0200
>
> > Commit 124613012db1 ("af_unix: Convert the unix_sk macro to an inline
> > function for type safety") was recently added to catch incorrect
> > uses of the unix_sk helper using compiler warnings.
> >
> > It has now caught one such case in lsm_audit.c. The code is technically
> > correct, but as it converts a const pointer to a non-const pointer,
> > the annotation got lost, which gcc now warns about.
> >
> > This patch avoids the warning by introducing an additional helper
> > that has const input and output, which makes the lsm_audit code build
> > cleanly again.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > I'm not entirely happy with this workaround myself, but could not come
> > up with a better one.
>
> You can make the argument unconditionally const, as Paul Moore has done
> in a separate patch submission.
Ok, I see now how Paul's "audit: constify parts of common_audit_data and lsm_network_audit" patch caused the problem and is now gone from linux-next.
That seems nicer indeed.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-08 12:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06 20:52 [PATCH] af_unix: introduce unix_sk_const helper Arnd Bergmann
2015-10-08 11:03 ` David Miller
2015-10-08 12:11 ` Arnd Bergmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox