security: add const qualifier to struct sock in various places
authorFlorian Westphal <fw@strlen.de>
Mon, 30 Nov 2020 15:36:29 +0000 (16:36 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 3 Dec 2020 20:56:03 +0000 (12:56 -0800)
A followup change to tcp_request_sock_op would have to drop the 'const'
qualifier from the 'route_req' function as the
'security_inet_conn_request' call is moved there - and that function
expects a 'struct sock *'.

However, it turns out its also possible to add a const qualifier to
security_inet_conn_request instead.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: James Morris <jamorris@linux.microsoft.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/lsm_audit.h
include/linux/lsm_hook_defs.h
include/linux/security.h
security/apparmor/include/net.h
security/apparmor/lsm.c
security/apparmor/net.c
security/lsm_audit.c
security/security.c
security/selinux/hooks.c
security/smack/smack_lsm.c

index 28f23b341c1ca46a0e8b0fee430d947287c331ec..cd23355d2271adc8bac3cb73abb0c2ec1c31f209 100644 (file)
@@ -26,7 +26,7 @@
 
 struct lsm_network_audit {
        int netif;
-       struct sock *sk;
+       const struct sock *sk;
        u16 family;
        __be16 dport;
        __be16 sport;
index 32a940117e7afe4ac997fc19b86684cdb09c0ff7..acc0494ccebab8d9c1b81c714c650c94672d37e1 100644 (file)
@@ -301,7 +301,7 @@ 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, sock_graft, struct sock *sk, struct socket *parent)
-LSM_HOOK(int, 0, inet_conn_request, struct sock *sk, struct sk_buff *skb,
+LSM_HOOK(int, 0, inet_conn_request, const struct sock *sk, struct sk_buff *skb,
         struct request_sock *req)
 LSM_HOOK(void, LSM_RET_VOID, inet_csk_clone, struct sock *newsk,
         const struct request_sock *req)
index bc272549156089a4e92ee7bdc6c86db7343a1f2a..0df62735651b3308be160053704c171f4c08512e 100644 (file)
@@ -1358,7 +1358,7 @@ void security_sk_clone(const struct sock *sk, struct sock *newsk);
 void security_sk_classify_flow(struct sock *sk, struct flowi *fl);
 void security_req_classify_flow(const struct request_sock *req, struct flowi *fl);
 void security_sock_graft(struct sock*sk, struct socket *parent);
-int security_inet_conn_request(struct sock *sk,
+int security_inet_conn_request(const struct sock *sk,
                        struct sk_buff *skb, struct request_sock *req);
 void security_inet_csk_clone(struct sock *newsk,
                        const struct request_sock *req);
@@ -1519,7 +1519,7 @@ static inline void security_sock_graft(struct sock *sk, struct socket *parent)
 {
 }
 
-static inline int security_inet_conn_request(struct sock *sk,
+static inline int security_inet_conn_request(const struct sock *sk,
                        struct sk_buff *skb, struct request_sock *req)
 {
        return 0;
index 2431c011800dd012307630e1ce23ae3114479542..aadb4b29fb66e421a8dc6200f9aa8c3f4cd0da1d 100644 (file)
@@ -107,6 +107,6 @@ int aa_sock_file_perm(struct aa_label *label, const char *op, u32 request,
                      struct socket *sock);
 
 int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
-                          u32 secid, struct sock *sk);
+                          u32 secid, const struct sock *sk);
 
 #endif /* __AA_NET_H */
index ffeaee5ed968376dff3cc5f210dea1e23149a9ea..1b0aba8eb7235f129b260ae36f6ba1ab2c2317ca 100644 (file)
@@ -1147,7 +1147,7 @@ static void apparmor_sock_graft(struct sock *sk, struct socket *parent)
 }
 
 #ifdef CONFIG_NETWORK_SECMARK
-static int apparmor_inet_conn_request(struct sock *sk, struct sk_buff *skb,
+static int apparmor_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
                                      struct request_sock *req)
 {
        struct aa_sk_ctx *ctx = SK_CTX(sk);
index fa0e85568450b0e7b942d576460499b425a1f61a..e0c1b50d6eddcb32993c57f207bc9c1ed20997da 100644 (file)
@@ -211,7 +211,7 @@ static int apparmor_secmark_init(struct aa_secmark *secmark)
 }
 
 static int aa_secmark_perm(struct aa_profile *profile, u32 request, u32 secid,
-                          struct common_audit_data *sa, struct sock *sk)
+                          struct common_audit_data *sa)
 {
        int i, ret;
        struct aa_perms perms = { };
@@ -244,13 +244,13 @@ static int aa_secmark_perm(struct aa_profile *profile, u32 request, u32 secid,
 }
 
 int apparmor_secmark_check(struct aa_label *label, char *op, u32 request,
-                          u32 secid, struct sock *sk)
+                          u32 secid, const struct sock *sk)
 {
        struct aa_profile *profile;
        DEFINE_AUDIT_SK(sa, op, sk);
 
        return fn_for_each_confined(label, profile,
                                    aa_secmark_perm(profile, request, secid,
-                                                   &sa, sk));
+                                                   &sa));
 }
 #endif
index 53d0d183db8f88b4a8b33315cfa30979856d225b..078f9cdcd7f5b3f2cadbf1820263b4fc144c8c9d 100644 (file)
@@ -183,7 +183,7 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 
 
 static inline void print_ipv6_addr(struct audit_buffer *ab,
-                                  struct in6_addr *addr, __be16 port,
+                                  const struct in6_addr *addr, __be16 port,
                                   char *name1, char *name2)
 {
        if (!ipv6_addr_any(addr))
@@ -322,7 +322,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        }
        case LSM_AUDIT_DATA_NET:
                if (a->u.net->sk) {
-                       struct sock *sk = a->u.net->sk;
+                       const struct sock *sk = a->u.net->sk;
                        struct unix_sock *u;
                        struct unix_address *addr;
                        int len = 0;
index a28045dc9e7f62b1fe843189b14e7d2f7620c355..6509f95d203f4cb653c5fc21f2b48851ddec1584 100644 (file)
@@ -2225,7 +2225,7 @@ void security_sock_graft(struct sock *sk, struct socket *parent)
 }
 EXPORT_SYMBOL(security_sock_graft);
 
-int security_inet_conn_request(struct sock *sk,
+int security_inet_conn_request(const struct sock *sk,
                        struct sk_buff *skb, struct request_sock *req)
 {
        return call_int_hook(inet_conn_request, 0, sk, skb, req);
index 6b1826fc3658e365915ed3b7d8c78942ee874d93..6fa593006802571bf5ea65448eda3cdf4cee6295 100644 (file)
@@ -5355,7 +5355,7 @@ static void selinux_sctp_sk_clone(struct sctp_endpoint *ep, struct sock *sk,
        selinux_netlbl_sctp_sk_clone(sk, newsk);
 }
 
-static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
+static int selinux_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
                                     struct request_sock *req)
 {
        struct sk_security_struct *sksec = sk->sk_security;
index 5c90b9fa4d405c69e9876e6a5b35e8d0cd9c477c..3a62d6aa74a6987c0e699474bc56838ecf653d33 100644 (file)
@@ -3864,7 +3864,7 @@ static inline struct smack_known *smack_from_skb(struct sk_buff *skb)
  *
  * Returns smack_known of the IP options or NULL if that won't work.
  */
-static struct smack_known *smack_from_netlbl(struct sock *sk, u16 family,
+static struct smack_known *smack_from_netlbl(const struct sock *sk, u16 family,
                                             struct sk_buff *skb)
 {
        struct netlbl_lsm_secattr secattr;
@@ -4114,7 +4114,7 @@ static void smack_sock_graft(struct sock *sk, struct socket *parent)
  * Returns 0 if a task with the packet label could write to
  * the socket, otherwise an error code
  */
-static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
+static int smack_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
                                   struct request_sock *req)
 {
        u16 family = sk->sk_family;