make vm86 call audit_syscall_exit

Jason Baron jbaron at redhat.com
Tue Jan 31 21:56:28 UTC 2006


hi,

The motivation behind the patch below was to address messages in 
/var/log/messages such as:

Jan 31 10:54:15 mets kernel: audit(:0): major=252 name_count=0: freeing 
multiple contexts (1)
Jan 31 10:54:15 mets kernel: audit(:0): major=113 name_count=0: freeing 
multiple contexts (2)

I can reproduce by running 'get-edid' from:
http://john.fremlin.de/programs/linux/read-edid/. 

These messages come about in the log b/c the vm86 calls do not exit via 
the normal system call exit paths and thus do not call 
'audit_syscall_exit'. The next system call will then free the context for 
itself and for the vm86 context, thus generating the above messages. This 
patch addresses the issue by simply adding a call to 'audit_syscall_exit' 
from the vm86 code.

Besides fixing the above error messages the patch also now allows vm86 
system calls to become auditable. This is useful since strace does not 
appear to properly record the return values from sys_vm86.

I think this patch is also a step in the right direction in terms of 
cleaning up some core auditing code. If we can correct any other paths 
that do not properly call the audit exit and entries points, then we can 
also eliminate the notion of context chaining.

I've tested this patch by verifying that the log messages no longer 
appear, and that the audit records for sys_vm86 appear to be correct. 
Also, 'read_edid' produces itentical output.

thanks,

-Jason

Signed-off-by: Jason Baron <jbaron at redhat.com>


--- linux-2.6/kernel/auditsc.c.bak
+++ linux-2.6/kernel/auditsc.c
@@ -981,11 +981,6 @@ void audit_syscall_entry(struct task_str
 	if (context && context->in_syscall) {
 		struct audit_context *newctx;
 
-#if defined(__NR_vm86) && defined(__NR_vm86old)
-		/* vm86 mode should only be entered once */
-		if (major == __NR_vm86 || major == __NR_vm86old)
-			return;
-#endif
 #if AUDIT_DEBUG
 		printk(KERN_ERR
 		       "audit(:%d) pid=%d in syscall=%d;"
--- linux-2.6/arch/i386/kernel/vm86.c.bak	2006-01-31 12:19:56.000000000 -0500
+++ linux-2.6/arch/i386/kernel/vm86.c	2006-01-31 12:24:52.000000000 -0500
@@ -42,6 +42,7 @@
 #include <linux/smp_lock.h>
 #include <linux/highmem.h>
 #include <linux/ptrace.h>
+#include <linux/audit.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -251,6 +252,7 @@ out:
 static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk)
 {
 	struct tss_struct *tss;
+	long eax;
 /*
  * make sure the vm86() system call doesn't try to do anything silly
  */
@@ -304,13 +306,19 @@ static void do_sys_vm86(struct kernel_vm
 	tsk->thread.screen_bitmap = info->screen_bitmap;
 	if (info->flags & VM86_SCREEN_BITMAP)
 		mark_screen_rdonly(tsk->mm);
+	__asm__ __volatile__("xorl %eax,%eax; movl %eax,%fs; movl %eax,%gs\n\t");
+	__asm__ __volatile__("movl %%eax, %0\n" :"=r"(eax));
+	
+	/*call audit_syscall_exit since we do not exit via the normal paths */
+	if (unlikely(current->audit_context))
+		audit_syscall_exit(current, AUDITSC_RESULT(eax), eax);
+
 	__asm__ __volatile__(
-		"xorl %%eax,%%eax; movl %%eax,%%fs; movl %%eax,%%gs\n\t"
 		"movl %0,%%esp\n\t"
 		"movl %1,%%ebp\n\t"
 		"jmp resume_userspace"
 		: /* no outputs */
-		:"r" (&info->regs), "r" (tsk->thread_info) : "ax");
+		:"r" (&info->regs), "r" (tsk->thread_info));
 	/* we never return here */
 }
 




More information about the Linux-audit mailing list