Skip to contentSkip to conversation

sanitize audit_ipc_obj()

PATCH In review Al Viro 4 participants 5 messages Dec 17, 2008 Audit

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 3/15 sanitize audit_ipc_obj()

* get rid of allocations
* make it return void
* simplify callers

---
 include/linux/audit.h |    9 ++---
 ipc/shm.c             |    4 +--
 ipc/util.c            |    9 ++---
 kernel/auditsc.c      |   88 ++++++++++++++++++++----------------------------
 4 files changed, 45 insertions(+), 65 deletions(-)
include/linux/audit.h +4 -5
index e59feb9..97598f0 100644
@@ -441,7 +441,7 @@ extern int  audit_set_loginuid(struct task_struct *task, uid_t loginuid);
 #define audit_get_loginuid(t) ((t)->loginuid)
 #define audit_get_sessionid(t) ((t)->sessionid)
 extern void audit_log_task_context(struct audit_buffer *ab);
-extern int __audit_ipc_obj(struct kern_ipc_perm *ipcp);
+extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
 extern int __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode);
 extern int audit_bprm(struct linux_binprm *bprm);
 extern void audit_socketcall(int nargs, unsigned long *args);
@@ -454,11 +454,10 @@ extern int __audit_mq_timedreceive(mqd_t mqdes, size_t msg_len, unsigned int __u
 extern int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification);
 extern int __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat);
 
-static inline int audit_ipc_obj(struct kern_ipc_perm *ipcp)
+static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
 {
 	if (unlikely(!audit_dummy_context()))
-		return __audit_ipc_obj(ipcp);
-	return 0;
+		__audit_ipc_obj(ipcp);
 }
 static inline int audit_fd_pair(int fd1, int fd2)
 {
@@ -522,7 +521,7 @@ extern int audit_signals;
 #define audit_get_loginuid(t) (-1)
 #define audit_get_sessionid(t) (-1)
 #define audit_log_task_context(b) do { ; } while (0)
-#define audit_ipc_obj(i) ({ 0; })
+#define audit_ipc_obj(i) ((void)0)
 #define audit_ipc_set_perm(q,u,g,m) ({ 0; })
 #define audit_bprm(p) ({ 0; })
 #define audit_socketcall(n,a) ((void)0)
ipc/shm.c +1 -3
index 867e5d6..e40065e 100644
@@ -747,9 +747,7 @@ asmlinkage long sys_shmctl(int shmid, int cmd, struct shmid_ds __user *buf)
 			goto out;
 		}
 
-		err = audit_ipc_obj(&(shp->shm_perm));
-		if (err)
-			goto out_unlock;
+		audit_ipc_obj(&(shp->shm_perm));
 
 		if (!capable(CAP_IPC_LOCK)) {
 			err = -EPERM;
ipc/util.c +3 -6
index 361fd1c..0aa8ed8 100644
@@ -620,10 +620,9 @@ void ipc_rcu_putref(void *ptr)
  
 int ipcperms (struct kern_ipc_perm *ipcp, short flag)
 {	/* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
-	int requested_mode, granted_mode, err;
+	int requested_mode, granted_mode;
 
-	if (unlikely((err = audit_ipc_obj(ipcp))))
-		return err;
+	audit_ipc_obj(ipcp);
 	requested_mode = (flag >> 6) | (flag >> 3) | flag;
 	granted_mode = ipcp->mode;
 	if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
@@ -797,9 +796,7 @@ struct kern_ipc_perm *ipcctl_pre_down(struct ipc_ids *ids, int id, int cmd,
 		goto out_up;
 	}
 
-	err = audit_ipc_obj(ipcp);
-	if (err)
-		goto out_unlock;
+	audit_ipc_obj(ipcp);
 
 	if (cmd == IPC_SET) {
 		err = audit_ipc_set_perm(extra_perm, perm->uid,
kernel/auditsc.c +37 -51

133 lines not on this page · raw message

Signature · 1 line
1.5.6.5
Reviewed-by on v1 3/15
#1 lore raw

kernel/auditsc.c struct audit_context { · line 229

Quoted 6 lines · Al Viro
kernel/auditsc.c +6 -0
+		struct {
+			uid_t			uid;
+			gid_t			gid;
+			mode_t			mode;
+			u32			osid;
+		} ipc;

'osid' should be converted into 'secid' someday.

Signature · 2 lines
James Morris
<[email protected]>
#2 lore raw
Quoted 10 lines · James Morris

kernel/auditsc.c struct audit_context { · line 229

Quoted 6 lines · Al Viro
kernel/auditsc.c +6 -0
+		struct {
+			uid_t			uid;
+			gid_t			gid;
+			mode_t			mode;
+			u32			osid;
+		} ipc;

'osid' should be converted into 'secid' someday.

Eh? Do you mean the field name there or the actual output? Either is trivial, of course, but the latter is up to userland folks and the former alone seems to be rather pointless...

#3 lore raw
Quoted 12 lines · Al Viro
Quoted 10 lines · James Morris

kernel/auditsc.c struct audit_context { · line 229

Quoted 6 lines · Al Viro
kernel/auditsc.c +6 -0
+		struct {
+			uid_t			uid;
+			gid_t			gid;
+			mode_t			mode;
+			u32			osid;
+		} ipc;

'osid' should be converted into 'secid' someday.

Quoted 3 lines

Eh? Do you mean the field name there or the actual output? Either is trivial, of course, but the latter is up to userland folks and the former alone seems to be rather pointless...

I was thinking in terms of the kernel API, where 'secid' is the preferred name for security identifiers ('sid' being an SELinux-specific term and also conflicting with 'session id'). Given that it's exposed to userland, I guess it's too late.

- James

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#4 lore raw
Quoted 14 lines · James Morris
Quoted 12 lines · Al Viro
Quoted 10 lines · James Morris

kernel/auditsc.c struct audit_context { · line 229

Quoted 6 lines · Al Viro
kernel/auditsc.c +6 -0
+		struct {
+			uid_t			uid;
+			gid_t			gid;
+			mode_t			mode;
+			u32			osid;
+		} ipc;

'osid' should be converted into 'secid' someday.

Quoted 8 lines
Quoted 3 lines

Eh? Do you mean the field name there or the actual output? Either is trivial, of course, but the latter is up to userland folks and the former alone seems to be rather pointless...

I was thinking in terms of the kernel API, where 'secid' is the preferred name for security identifiers ('sid' being an SELinux-specific term and also conflicting with 'session id'). Given that it's exposed to userland, I guess it's too late.

James meant just do s/osid/secid/ for continuity across the kernel (we are trying to make the main kernel a bit more LSM agnostic and sid is an SELinux term). The userspace exported part is actually a translated string (I think we use ocontext= and scontext=).

There is no reason we couldn't do this in audit. But, I don't think it's worth changing this patch, as I think audit refers to it as sid in other places. Maybe I'll try to clean that up someday. I at least added it to my "someday" todo list.

-Eric