Skip to contentSkip to conversation

sanitize audit_fd_pair()

PATCH In review Al Viro 3 participants 3 messages Dec 17, 2008

Subsystems (4)
lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 9/15 sanitize audit_fd_pair()

* no allocations
* return void

---
 fs/pipe.c             |    7 +------
 include/linux/audit.h |    9 ++++-----
 kernel/auditsc.c      |   44 ++++++++++++++------------------------------
 net/socket.c          |    9 +--------
 4 files changed, 20 insertions(+), 49 deletions(-)
fs/pipe.c +1 -6
index 7aea8b8..5341421 100644
@@ -1016,10 +1016,7 @@ int do_pipe_flags(int *fd, int flags)
 		goto err_fdr;
 	fdw = error;
 
-	error = audit_fd_pair(fdr, fdw);
-	if (error < 0)
-		goto err_fdw;
-
+	audit_fd_pair(fdr, fdw);
 	fd_install(fdr, fr);
 	fd_install(fdw, fw);
 	fd[0] = fdr;
@@ -1027,8 +1024,6 @@ int do_pipe_flags(int *fd, int flags)
 
 	return 0;
 
- err_fdw:
-	put_unused_fd(fdw);
  err_fdr:
 	put_unused_fd(fdr);
  err_read_pipe:
include/linux/audit.h +4 -5
index ed6bdfc..c5e95e7 100644
@@ -446,7 +446,7 @@ extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mod
 extern int audit_bprm(struct linux_binprm *bprm);
 extern void audit_socketcall(int nargs, unsigned long *args);
 extern int audit_sockaddr(int len, void *addr);
-extern int __audit_fd_pair(int fd1, int fd2);
+extern void __audit_fd_pair(int fd1, int fd2);
 extern int audit_set_macxattr(const char *name);
 extern void __audit_mq_open(int oflag, mode_t mode, struct mq_attr *attr);
 extern void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio, const struct timespec *abs_timeout);
@@ -458,11 +458,10 @@ static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
 	if (unlikely(!audit_dummy_context()))
 		__audit_ipc_obj(ipcp);
 }
-static inline int audit_fd_pair(int fd1, int fd2)
+static inline void audit_fd_pair(int fd1, int fd2)
 {
 	if (unlikely(!audit_dummy_context()))
-		return __audit_fd_pair(fd1, fd2);
-	return 0;
+		__audit_fd_pair(fd1, fd2);
 }
 static inline void audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode)
 {
@@ -513,7 +512,7 @@ extern int audit_signals;
 #define audit_ipc_set_perm(q,u,g,m) ((void)0)
 #define audit_bprm(p) ({ 0; })
 #define audit_socketcall(n,a) ((void)0)
-#define audit_fd_pair(n,a) ({ 0; })
+#define audit_fd_pair(n,a) ((void)0)
 #define audit_sockaddr(len, addr) ({ 0; })
 #define audit_set_macxattr(n) do { ; } while (0)
 #define audit_mq_open(o,m,a) ((void)0)
kernel/auditsc.c +14 -30

83 lines not on this page · raw message

net/socket.c +1 -8
index aba5a50..a383608 100644
@@ -1314,13 +1314,7 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
 		goto out_fd1;
 	}
 
-	err = audit_fd_pair(fd1, fd2);
-	if (err < 0) {
-		fput(newfile1);
-		fput(newfile2);
-		goto out_fd;
-	}
-
+	audit_fd_pair(fd1, fd2);
 	fd_install(fd1, newfile1);
 	fd_install(fd2, newfile2);
 	/* fd1 and fd2 may be already another descriptors.
@@ -1350,7 +1344,6 @@ out_fd2:
 out_fd1:
 	put_filp(newfile2);
 	sock_release(sock2);
-out_fd:
 	put_unused_fd(fd1);
 	put_unused_fd(fd2);
 	goto out;
Signature · 1 line
1.5.6.5
maintainer Acked-by on v1 9/15
#2 lore raw
In reply to Al Viro
Quoted 11 lines · Al Viro

* no allocations
* return void

kernel/auditsc.c +0 -0
index ac89cd3..5de0087 100644

kernel/auditsc.c struct audit_context { · line 216

Quoted 7 lines
kernel/auditsc.c +1 -0
@@ -215,6 +210,7 @@ struct audit_context {
 			struct mq_attr		attr;
 		} mq_open;
 	};
+	int fds[2];
 
 #if AUDIT_DEBUG
 	int		    put_count;

Waste of space, at least on a 32 bit machine where the size of the ipc aux data is definitely larger than the sockcall aux data. But I guess what you did is a whole lot easier and clearer than to try to hack up adding it to both sockcall and new pipe_fds and using the right one at the right time. I guess if we cared about 64 bits per audited thread we wouldn't be moving the aux data into the audit_context anyway.