security: Constify sk in the sk_getsecid hook.
authorGuillaume Nault <gnault@redhat.com>
Tue, 11 Jul 2023 13:06:08 +0000 (15:06 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 14 Jul 2023 07:27:33 +0000 (08:27 +0100)
The sk_getsecid hook shouldn't need to modify its socket argument.
Make it const so that callers of security_sk_classify_flow() can use a
const struct sock *.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/lsm_hook_defs.h
include/linux/security.h
security/security.c
security/selinux/hooks.c

index 7308a1a7599b4a1335b0a208d32cfb6888224370..4f2621e8763405745de4c917ed97c7a19056a246 100644 (file)
@@ -316,7 +316,7 @@ LSM_HOOK(int, 0, sk_alloc_security, struct sock *sk, int family, gfp_t priority)
 LSM_HOOK(void, LSM_RET_VOID, sk_free_security, struct sock *sk)
 LSM_HOOK(void, LSM_RET_VOID, sk_clone_security, const struct sock *sk,
         struct sock *newsk)
-LSM_HOOK(void, LSM_RET_VOID, sk_getsecid, struct sock *sk, u32 *secid)
+LSM_HOOK(void, LSM_RET_VOID, sk_getsecid, const struct sock *sk, u32 *secid)
 LSM_HOOK(void, LSM_RET_VOID, sock_graft, struct sock *sk, struct socket *parent)
 LSM_HOOK(int, 0, inet_conn_request, const struct sock *sk, struct sk_buff *skb,
         struct request_sock *req)
index 32828502f09eae3383e854e0ed62541dd28c9303..994cf099d9ac9f6bf6267d8ee260ff1e869daa30 100644 (file)
@@ -1439,7 +1439,8 @@ int security_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u
 int security_sk_alloc(struct sock *sk, int family, gfp_t priority);
 void security_sk_free(struct sock *sk);
 void security_sk_clone(const struct sock *sk, struct sock *newsk);
-void security_sk_classify_flow(struct sock *sk, struct flowi_common *flic);
+void security_sk_classify_flow(const struct sock *sk,
+                              struct flowi_common *flic);
 void security_req_classify_flow(const struct request_sock *req,
                                struct flowi_common *flic);
 void security_sock_graft(struct sock*sk, struct socket *parent);
@@ -1597,7 +1598,7 @@ static inline void security_sk_clone(const struct sock *sk, struct sock *newsk)
 {
 }
 
-static inline void security_sk_classify_flow(struct sock *sk,
+static inline void security_sk_classify_flow(const struct sock *sk,
                                             struct flowi_common *flic)
 {
 }
index b720424ca37d9c683c757abf3433217061b3d1e2..2dfc7b9f6ed99a27718cad7f133f348651a054d4 100644 (file)
@@ -4396,7 +4396,7 @@ void security_sk_clone(const struct sock *sk, struct sock *newsk)
 }
 EXPORT_SYMBOL(security_sk_clone);
 
-void security_sk_classify_flow(struct sock *sk, struct flowi_common *flic)
+void security_sk_classify_flow(const struct sock *sk, struct flowi_common *flic)
 {
        call_void_hook(sk_getsecid, sk, &flic->flowic_secid);
 }
index d06e350fedee5f7936ce0e9bd33c8befd771f886..2bdc48dd867099136502ef004dbae0effba4e6dd 100644 (file)
@@ -5167,12 +5167,12 @@ static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
        selinux_netlbl_sk_security_reset(newsksec);
 }
 
-static void selinux_sk_getsecid(struct sock *sk, u32 *secid)
+static void selinux_sk_getsecid(const struct sock *sk, u32 *secid)
 {
        if (!sk)
                *secid = SECINITSID_ANY_SOCKET;
        else {
-               struct sk_security_struct *sksec = sk->sk_security;
+               const struct sk_security_struct *sksec = sk->sk_security;
 
                *secid = sksec->sid;
        }