audit: support for descriptor pairs
Subsystems (4)
PATCH 1/1 audit: support for descriptor pairs
provide an audit record of the descriptor pair returned by pipe() and socketpair().
Signed-off-by Jeremy Latt <[email protected]>
Signed-off-by Steven Trieber <[email protected]>
Signed-off-by Mark Workman <[email protected]>
--- fs/pipe.c | 7 ++++++ include/linux/audit.h | 9 ++++++++ kernel/auditsc.c | 40 ++++++++++++++++++++++++++++++++++++ net/socket.c | 55 +++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 99 insertions(+), 12 deletions(-)
---
fs/pipe.c +7 -0
@@ -16,6 +16,7 @@#include <linux/uio.h> #include <linux/highmem.h> #include <linux/pagemap.h> +#include <linux/audit.h> #include <asm/uaccess.h> #include <asm/ioctls.h>
@@ -972,6 +973,10 @@ int do_pipe(int *fd) goto err_fdr; fdw = error; + error =audit_fd_pair (fdr, fdw); +if (error <0 ) + goto err_fdw; +fd_install (fdr, fr);fd_install (fdw, fw); fd[0 ] = fdr;
@@ -979,6 +984,8 @@ int do_pipe(int *fd)return 0 ; + err_fdw: +put_unused_fd (fdw); err_fdr:put_unused_fd (fdr); err_read_pipe:
include/linux/audit.h +9 -0
@@ -89,6 +89,7 @@#define AUDIT_MQ_NOTIFY 1314/* POSIX MQ notify record type */ #define AUDIT_MQ_GETSETATTR 1315/* POSIX MQ get/set attribute record type */ #define AUDIT_KERNEL_OTHER 1316/* For use by 3rd party modules */ +#define AUDIT_FD_PAIR 1317/* audit record for pipe/socketpair */ #define AUDIT_AVC 1400/* SE Linux avc denial or grant */ #define AUDIT_SELINUX_ERR 1401/* Internal SE Linux Errors */
@@ -382,6 +383,7 @@ extern int __audit_ipc_set_perm(unsignedextern int audit_bprm (struct linux_binprm *bprm);extern int 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 int audit_avc_path (struct dentry *dentry,struct vfsmount *mnt);extern int audit_set_macxattr (const char *name);extern int __audit_mq_open (int oflag,mode_t mode,struct mq_attr __user *u_attr);
@@ -396,6 +398,12 @@ static inline int audit_ipc_obj(struct kreturn __audit_ipc_obj (ipcp);return 0 ; } +static inline int audit_fd_pair (int fd1,int fd2) +{ +if (unlikely (!audit_dummy_context ())) +return __audit_fd_pair (fd1, fd2); +return 0 ; +}static inline int audit_ipc_set_perm (unsigned long qbytes,uid_t uid,gid_t gid,mode_t mode) {if (unlikely (!audit_dummy_context ()))
@@ -453,6 +461,7 @@ extern int audit_n_rules;#define audit_ipc_set_perm (q,u,g,m) ({ 0; })#define audit_bprm (p) ({ 0; })#define audit_socketcall (n,a) ({ 0; }) +#define audit_fd_pair (n,a) ({ 0; })#define audit_sockaddr (len, addr) ({ 0; })#define audit_avc_path (dentry, mnt) ({ 0; })#define audit_set_macxattr (n) do { ; } while (0)
kernel/auditsc.c +40 -0
@@ -169,6 +169,11 @@ struct audit_aux_data_sockaddr {char a[0 ]; }; +struct audit_aux_data_fd_pair { +struct audit_aux_data d; +int fd[2 ]; +}; +struct audit_aux_data_path {struct audit_aux_data d;struct dentry *dentry;
@@ -956,6 +961,11 @@ static void audit_log_exit(struct audit_audit_log_d_path (ab,"path=" , axi->dentry, axi->mnt);break ; } +case AUDIT_FD_PAIR : { +struct audit_aux_data_fd_pair *axs = (void *)aux; +audit_log_format (ab,"fd0=%d fd1=%d" , axs->fd[0 ], axs->fd[1 ]); +break ; } + }audit_log_end (ab); }
@@ -1808,6 +1818,36 @@ int audit_socketcall(int nargs, unsigned }/** +* __audit_fd_pair - record audit data for pipe and socketpair +* @fd1: the first file descriptor +* @fd2: the second file descriptor +* +* Returns 0 for success or NULL context or < 0 on error. +*/ +int __audit_fd_pair (int fd1,int fd2) +{ +struct audit_context *context = current->audit_context; +struct audit_aux_data_fd_pair *ax; + +if (likely (!context)) { +return 0 ; + } + + ax =kmalloc (sizeof (*ax),GFP_KERNEL ); +if (!ax) { +return -ENOMEM ; + } + + ax->fd[0 ] = fd1; + ax->fd[1 ] = fd2; + + ax->d.type =AUDIT_FD_PAIR ; + ax->d.next = context->aux; + context->aux = (void *)ax; +return 0 ; +} + +/** * audit_sockaddr - record audit data for sys_bind, sys_connect, sys_sendto * @len: data length in user space * @a: data address in kernel space
net/socket.c +43 -12
81 lines not on this page · raw message