diff mbox series

[net-next,06/10] af_unix: preserve const qualifier in unix_sk()

Message ID 20230317155539.2552954-7-edumazet@google.com (mailing list archive)
State Accepted
Commit b064ba9c3cfaf3d22d6153ec3c245eaa4d913674
Delegated to: Netdev Maintainers
Headers show
Series net: better const qualifier awareness | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 80 this patch: 75
netdev/cc_maintainers warning 4 maintainers not CCed: jmorris@namei.org linux-security-module@vger.kernel.org serge@hallyn.com paul@paul-moore.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 81 this patch: 76
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eric Dumazet March 17, 2023, 3:55 p.m. UTC
We can change unix_sk() to propagate its argument const qualifier,
thanks to container_of_const().

We need to change dump_common_audit_data() 'struct unix_sock *u'
local var to get a const attribute.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/net/af_unix.h | 5 +----
 security/lsm_audit.c  | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

Comments

Simon Horman March 17, 2023, 4:37 p.m. UTC | #1
On Fri, Mar 17, 2023 at 03:55:35PM +0000, Eric Dumazet wrote:
> We can change unix_sk() to propagate its argument const qualifier,
> thanks to container_of_const().
> 
> We need to change dump_common_audit_data() 'struct unix_sock *u'
> local var to get a const attribute.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff mbox series

Patch

diff --git a/include/net/af_unix.h b/include/net/af_unix.h
index 45ebde587138e59f8331d358420d3fca79d9ee66..824c258143a3ab360b870fda38ba684b70068eee 100644
--- a/include/net/af_unix.h
+++ b/include/net/af_unix.h
@@ -74,10 +74,7 @@  struct unix_sock {
 #endif
 };
 
-static inline struct unix_sock *unix_sk(const struct sock *sk)
-{
-	return (struct unix_sock *)sk;
-}
+#define unix_sk(ptr) container_of_const(ptr, struct unix_sock, sk)
 
 #define peer_wait peer_wq.wait
 
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
index 00d3bdd386e294ecd562bfa8ce502bf179ad32d9..368e77ca43c4a5d5f71a7e9a0a1e58a006796aa6 100644
--- a/security/lsm_audit.c
+++ b/security/lsm_audit.c
@@ -310,7 +310,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;
 			struct unix_address *addr;
 			int len = 0;
 			char *p = NULL;