]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
UBUNTU: SAUCE: Stacking v38: LSM: Use lsmblob in security_ipc_getsecid
authorCasey Schaufler <casey@schaufler-ca.com>
Mon, 27 Jun 2022 20:48:53 +0000 (13:48 -0700)
committerAndrea Righi <andrea.righi@canonical.com>
Thu, 23 Mar 2023 19:41:23 +0000 (20:41 +0100)
BugLink: https://bugs.launchpad.net/bugs/2012136
There may be more than one LSM that provides IPC data
for auditing. Change security_ipc_getsecid() to fill in
a lsmblob structure instead of the u32 secid. The
audit data structure containing the secid will be updated
later, so there is a bit of scaffolding here.

Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: John Johansen <john.johansen@canonical.com>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Cc: linux-audit@redhat.com
Signed-off-by: John Johansen <john.johansen@canonical.com>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
include/linux/security.h
kernel/auditsc.c
security/security.c

index 450dcb3bde36abc2d2c5ee0ef84585915f426b9c..ce03586c255f0a02cc94167cc931ef1fce613634 100644 (file)
@@ -553,7 +553,7 @@ int security_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 void security_task_to_inode(struct task_struct *p, struct inode *inode);
 int security_create_user_ns(const struct cred *cred);
 int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag);
-void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid);
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob);
 int security_msg_msg_alloc(struct msg_msg *msg);
 void security_msg_msg_free(struct msg_msg *msg);
 int security_msg_queue_alloc(struct kern_ipc_perm *msq);
@@ -1349,9 +1349,10 @@ static inline int security_ipc_permission(struct kern_ipc_perm *ipcp,
        return 0;
 }
 
-static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+static inline void security_ipc_getsecid(struct kern_ipc_perm *ipcp,
+                                        struct lsmblob *blob)
 {
-       *secid = 0;
+       lsmblob_init(blob, 0);
 }
 
 static inline int security_msg_msg_alloc(struct msg_msg *msg)
index 74f58df2732543952f2892b679b76c7738b1365d..9e0ae06ecf8dc647d301108cdfa6ebd7136edd7e 100644 (file)
@@ -2646,12 +2646,17 @@ void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
 void __audit_ipc_obj(struct kern_ipc_perm *ipcp)
 {
        struct audit_context *context = audit_context();
+       struct lsmblob blob;
 
        context->ipc.uid = ipcp->uid;
        context->ipc.gid = ipcp->gid;
        context->ipc.mode = ipcp->mode;
        context->ipc.has_perm = 0;
-       security_ipc_getsecid(ipcp, &context->ipc.osid);
+       security_ipc_getsecid(ipcp, &blob);
+       /* context->ipc.osid will be changed to a lsmblob later in
+        * the patch series. This will allow auditing of all the object
+        * labels associated with the ipc object. */
+       context->ipc.osid = lsmblob_value(&blob);
        context->type = AUDIT_IPC;
 }
 
index e19ea1d769a0d4803640b2e1c1093530d1b0395a..b86851d08d2f875ddf7fb9058052783fe5602692 100644 (file)
@@ -2117,10 +2117,16 @@ int security_ipc_permission(struct kern_ipc_perm *ipcp, short flag)
        return call_int_hook(ipc_permission, 0, ipcp, flag);
 }
 
-void security_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
+void security_ipc_getsecid(struct kern_ipc_perm *ipcp, struct lsmblob *blob)
 {
-       *secid = 0;
-       call_void_hook(ipc_getsecid, ipcp, secid);
+       struct security_hook_list *hp;
+
+       lsmblob_init(blob, 0);
+       hlist_for_each_entry(hp, &security_hook_heads.ipc_getsecid, list) {
+               if (WARN_ON(hp->lsmid->slot < 0 || hp->lsmid->slot >= lsm_slot))
+                       continue;
+               hp->hook.ipc_getsecid(ipcp, &blob->secid[hp->lsmid->slot]);
+       }
 }
 
 int security_msg_msg_alloc(struct msg_msg *msg)