Skip to contentSkip to conversation

Systrace 2.6.19 patch -- need comments

PATCH iSteve 1 participant 1 message Dec 9, 2006

Subsystems (4)
lore
Share & tools
lore

iSteve

author
#0 lore raw

Hi,
while getting familiar with OpenBSD, I've noticed a utility called systrace
(http://www.citi.umich.edu/u/provos/systrace/, http://www.systrace.org/). This application can alter behavior of syscalls on a simple rules basis; it can operate on various backends and systems: it's native in OpenBSD and NetBSD, it has generic ptrace backend (yes, I know that's not really safe) and it has a Linux kernel patch.

The latest Linux kernel patch I've found was for 2.6.13.4; I've found no mention of systrace whatsoever when searching through LKML, so I've decided to try my best and upgrade it to 2.6.19.

Please see the attached patch; it basically only fixes of what didn't apply clean with the old patch. It's been vaguely tested and it appears to work as expected.

As I'm not the author, nor do I understand exactly the internals, I'd merely like to ask someone to look at it, comment it, perhaps even fix it; in the most optimistic thoughts, maintain it.

My thought on the patch is that linux_sysent.c could be replaced by something way cleaner. Also, I'm not entirely certain whether it should be in drivers/ instead of security/. Last but definitely not least, only x86 asm code is available, so it'd have to be ported to other architectures as well.

Thanks in advance for any reply.

PS.: Please, CC me, I'm off-list.
PPS.: To build systrace userland application to use the Linux kernel backend, ensure that the configure script has access to systrace header files.

arch/i386/kernel/entry.S +31 -0
diff -ruN linux-2.6.19-vanilla/arch/i386/kernel/entry.S linux-2.6.19/arch/i386/kernel/entry.S
@@ -330,8 +330,23 @@
 	jnz syscall_trace_entry
 	cmpl $(nr_syscalls), %eax
 	jae syscall_badsys
+#ifdef CONFIG_SYSTRACE
+	movl %esp,%eax
+	call systrace_intercept
+	cmpl $0,%eax
+	jl ret1
+	movl ORIG_EAX(%esp),%eax
+#endif /* CONFIG_SYSTRACE */
 	call *sys_call_table(,%eax,4)
+#ifdef CONFIG_SYSTRACE
+	ret1:
+#endif /* CONFIG_SYSTRACE */
 	movl %eax,EAX(%esp)
+#ifdef CONFIG_SYSTRACE
+	movl %esp,%eax                  # pass in stack
+	call systrace_result
+	movl EAX(%esp),%eax             # XXX: ?to be on the safe side
+#endif /* CONFIG_SYSTRACE */
 	DISABLE_INTERRUPTS
 	TRACE_IRQS_OFF
 	movl TI_flags(%ebp), %ecx
@@ -363,9 +378,25 @@
 	jnz syscall_trace_entry
 	cmpl $(nr_syscalls), %eax
 	jae syscall_badsys
+#ifdef CONFIG_SYSTRACE
+	movl %esp,%eax
+	call systrace_intercept
+	cmpl $0,%eax
+	jl ret
+	movl ORIG_EAX(%esp),%eax
+#endif /* CONFIG_SYSTRACE */
 syscall_call:
 	call *sys_call_table(,%eax,4)
+#ifdef CONFIG_SYSTRACE
+	ret:
+#endif /* CONFIG_SYSTRACE */
 	movl %eax,EAX(%esp)		# store the return value
+#ifdef CONFIG_SYSTRACE
+	movl %esp,%eax                  # pass in stack
+	call systrace_result
+	movl EAX(%esp),%eax             # XXX: ?to be on the safe side
+#endif /* CONFIG_SYSTRACE */
+
 syscall_exit:
 	DISABLE_INTERRUPTS		# make sure we don't miss an interrupt
 					# setting need_resched or sigpending
drivers/Makefile +1 -0
diff -ruN linux-2.6.19-vanilla/drivers/Makefile linux-2.6.19/drivers/Makefile
@@ -67,6 +67,7 @@
 obj-$(CONFIG_MCA)		+= mca/
 obj-$(CONFIG_EISA)		+= eisa/
 obj-$(CONFIG_CPU_FREQ)		+= cpufreq/
+obj-$(CONFIG_SYSTRACE)		+= systrace/
 obj-$(CONFIG_MMC)		+= mmc/
 obj-$(CONFIG_NEW_LEDS)		+= leds/
 obj-$(CONFIG_INFINIBAND)	+= infiniband/
drivers/systrace/Kconfig +7 -0
diff -ruN linux-2.6.19-vanilla/drivers/systrace/Kconfig linux-2.6.19/drivers/systrace/Kconfig
@@ -0,0 +1,7 @@
+config SYSTRACE
+        bool "Systrace support"
+        help
+          This enables systrace support.  See http://www.systrace.org/ for details.
+          
+          Also enable Default Linux Capabilites (CONFIG_SECURITY_CAPABILITIES)!
+
drivers/systrace/linux_sysent.c +296 -0

296 lines not on this page · raw message

drivers/systrace/Makefile +1 -0
diff -ruN linux-2.6.19-vanilla/drivers/systrace/Makefile linux-2.6.19/drivers/systrace/Makefile
@@ -0,0 +1 @@
+obj-y    := systrace.o policy.o linux_sysent.o
drivers/systrace/policy.c +159 -0

159 lines not on this page · raw message

drivers/systrace/systrace.c +1378 -0

1,378 lines not on this page · raw message

drivers/systrace/systrace-private.h +144 -0

144 lines not on this page · raw message

include/linux/queue.h +145 -0

145 lines not on this page · raw message

include/linux/sched.h +4 -0
diff -ruN linux-2.6.19-vanilla/include/linux/sched.h linux-2.6.19/include/linux/sched.h
@@ -982,6 +982,10 @@
 
 	unsigned long ptrace_message;
 	siginfo_t *last_siginfo; /* For ptrace use.  */
+#ifdef CONFIG_SYSTRACE
+	void *systrace;
+#endif
+
 /*
  * current io wait handle: wait queue entry to use for io waits
  * If this thread is processing aio, this points at the waitqueue
include/linux/systrace.h +216 -0

216 lines not on this page · raw message

kernel/exit.c +10 -0
diff -ruN linux-2.6.19-vanilla/kernel/exit.c linux-2.6.19/kernel/exit.c
@@ -42,6 +42,12 @@
 #include <linux/resource.h>
 #include <linux/blkdev.h>
 
+#ifdef CONFIG_SYSTRACE
+#include <linux/queue.h>
+#include <asm/semaphore.h>
+#include <linux/systrace.h>
+#endif
+
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 #include <asm/pgtable.h>
@@ -914,6 +920,10 @@
 	taskstats_exit_send(tsk, tidstats, group_dead, mycpu);
 	taskstats_exit_free(tidstats);
 
+#ifdef CONFIG_SYSTRACE
+	systrace_exit(tsk);
+#endif
+
 	exit_mm(tsk);
 
 	if (group_dead)
kernel/fork.c +10 -0
diff -ruN linux-2.6.19-vanilla/kernel/fork.c linux-2.6.19/kernel/fork.c
@@ -39,6 +39,11 @@
 #include <linux/rcupdate.h>
 #include <linux/ptrace.h>
 #include <linux/mount.h>
+#ifdef CONFIG_SYSTRACE
+#include <linux/queue.h>
+#include <asm/semaphore.h>
+#include <linux/systrace.h>
+#endif /* CONFIG_SYSTRACE */
 #include <linux/audit.h>
 #include <linux/profile.h>
 #include <linux/rmap.h>
@@ -1385,6 +1390,11 @@
 			set_tsk_thread_flag(p, TIF_SIGPENDING);
 		}
 
+#ifdef CONFIG_SYSTRACE
+		if (current->systrace != NULL)
+			systrace_fork(current, p);
+#endif
+
 		if (!(clone_flags & CLONE_STOPPED))
 			wake_up_new_task(p, clone_flags);
 		else

Files linux-2.6.19-vanilla/scripts/kconfig/mconf and linux-2.6.19/scripts/kconfig/mconf differ

security/Kconfig +1 -0
diff -ruN linux-2.6.19-vanilla/security/Kconfig linux-2.6.19/security/Kconfig
@@ -94,6 +94,7 @@
 	  If you are unsure how to answer this question, answer N.
 
 source security/selinux/Kconfig
+source drivers/systrace/Kconfig
 
 endmenu