Skip to contentSkip to conversation

busybox patch for SE Linux

PATCH Russell Coker 1 participant 1 message May 19, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

I have attached a patch against busybox 0.60.5 to provide basic SE Linux support. The commands "id", "ls", and "ps" are patched to display SE Linux security contexts (not SIDs).

This patch also does a few other minor things.

It renames the "State" field to "Stat" which makes it match procps, and gives me an extra column of display.

It adds a CFLAGS_INCLUDE variable to the Makefile so that I can specify -I options on the make command line (with the Debian build the option "-I-" is appended after CFLAGS_EXTRA). The correct thing to do may be to change the Makefile such that CFLAGS_EXTRA really is last.

If you compile it without -DSELINUX it will give the same code as the regular version of Busybox. Eric I believe that this patch is worth considering for the next upstream tree. This functionality is needed for recovery of a damaged SE Linux system, and for SE Linux running on small computers such as the iPaQ. The patch as it stands will (apart from the debian/rules bit) have no impact on non-SE users.

Also I plan to write applets for load_policy, avc_enforcing, avc_toggle, and chsid/chcon.

Signature · 4 lines
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page
Makefile renamed from busybox-0.60.5/Makefile +6 -6
diff -ru orig/busybox-0.60.5/Makefile busybox-0.60.5/Makefile
@@ -386,34 +386,34 @@
 ash.o hush.o lash.o msh.o: cmdedit.h
 $(OBJECTS): %.o: %.c Config.h busybox.h applets.h Makefile
 ifeq ($(strip $(BB_SRC_DIR)),)
-	$(CC) $(CFLAGS) -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
+	$(CC) $(CFLAGS) -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) $(CFLAGS_INCLUDE) -c $< -o $*.o
 else
-	$(CC) $(CFLAGS) -I- -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
+	$(CC) $(CFLAGS) -I- -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $(CFLAGS_INCLUDE) $< -o $*.o
 endif
 
 $(PWD_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile
 ifneq ($(strip $(BB_SRC_DIR)),)
 	-mkdir -p $(PWD_GRP)
 endif
-	$(CC) $(CFLAGS) $(PWD_CFLAGS) -c $< -o $*.o
+	$(CC) $(CFLAGS) $(PWD_CFLAGS) $(CFLAGS_INCLUDE) -c $< -o $*.o
 
 $(LIBBB_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile libbb/libbb.h
 ifneq ($(strip $(BB_SRC_DIR)),)
 	-mkdir -p $(LIBBB)
 endif
-	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -c $< -o $*.o
+	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) $(CFLAGS_INCLUDE) -c $< -o $*.o
 
 $(LIBBB_MOBJ): $(LIBBB_MSRC)
 ifneq ($(strip $(BB_SRC_DIR)),)
 	-mkdir -p $(LIBBB)
 endif
-	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) -c $< -o $*.o
+	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) $(CFLAGS_INCLUDE) -c $< -o $*.o
 
 $(LIBBB_AROBJS): $(LIBBB_ARCSRC)
 ifneq ($(strip $(BB_SRC_DIR)),)
 	-mkdir -p $(LIBBB)
 endif
-	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) -c $< -o $*.o
+	$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) $(CFLAGS_INCLUDE) -c $< -o $*.o
 
 libpwd.a: $(PWD_OBJS)
 	$(AR) $(ARFLAGS) $@ $^
debian/control renamed from busybox-0.60.5/debian/control +1 -1
diff -ru orig/busybox-0.60.5/debian/control busybox-0.60.5/debian/control
@@ -1,7 +1,7 @@
 Source: busybox
 Priority: optional
 Maintainer: Erik Andersen <[email protected]>
-Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0)
+Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0), libselinux-dev [i386]
 Standards-Version: 3.2.1.0
 
 Package: busybox
debian/rules renamed from busybox-0.60.5/debian/rules +3 -3
diff -ru orig/busybox-0.60.5/debian/rules busybox-0.60.5/debian/rules
@@ -29,7 +29,7 @@
 	cp Makefile $(bbbd)
 	cp debian/Config.h-deb $(bbbd)/Config.h
 	-(cd $(bbbd); $(MAKE) "BB_SRC_DIR=../../" applet_source_list)
-	(cd $(bbbd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
+	(cd $(bbbd); $(MAKE) CFLAGS_EXTRA="-DSELINUX" CFLAGS_INCLUDE="-I/usr/include/selinux" LIBRARIES=-lsecure USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
 	touch debian/build-stamp-busybox
 
 install: build
@@ -54,7 +54,7 @@
 	mkdir -p $(bbsbd)
 	cp Makefile $(bbsbd)
 	cp debian/Config.h-static $(bbsbd)/Config.h
-	(cd $(bbsbd); $(MAKE) DOSTATIC=true USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
+	(cd $(bbsbd); $(MAKE) DOSTATIC=true CFLAGS_EXTRA="-DSELINUX" CFLAGS_INCLUDE="-I/usr/include/selinux" LIBRARIES=-lsecure USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
 	touch debian/build-stamp-busybox-static
 
 install-static: build
@@ -94,7 +94,7 @@
 	mkdir -p $(bbubd)
 	cp Makefile $(bbubd)
 	cp debian/Config.h-udeb $(bbubd)/Config.h
-	(cd $(bbubd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
+	(cd $(bbubd); $(MAKE) CFLAGS_EXTRA="-DSELINUX" CFLAGS_INCLUDE="-I/usr/include/selinux" LIBRARIES=-lsecure USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
 	touch debian/build-stamp-busybox-udeb
 
 install-udeb: build
id.c renamed from busybox-0.60.5/id.c +44 -8

99 lines not on this page · raw message

ls.c renamed from busybox-0.60.5/ls.c +58 -6

132 lines not on this page · raw message

ps.c renamed from busybox-0.60.5/ps.c +38 -5

73 lines not on this page · raw message

usage.h renamed from busybox-0.60.5/usage.h +11 -2
diff -ru orig/busybox-0.60.5/usage.h busybox-0.60.5/usage.h
@@ -627,6 +627,12 @@
 	"$ hostname\n" \
 	"sage \n"
 
+#ifdef SELINUX
+#define USAGE_SELINUX(a, b) a
+#else
+#define USAGE_SELINUX(a, b) b
+#endif
+
 #define id_trivial_usage \
 	"[OPTIONS]... [USERNAME]"
 #define id_full_usage \
@@ -634,6 +640,7 @@
 	"Options:\n" \
 	"\t-g\tprints only the group ID\n" \
 	"\t-u\tprints only the user ID\n" \
+	USAGE_SELINUX("\t-c\tprints only the security context\n", "") \
 	"\t-n\tprint a name instead of a number (with for -ug)\n" \
 	"\t-r\tprints the real user ID instead of the effective ID (with -ug)"
 #define id_example_usage \
@@ -958,7 +965,7 @@
   #define USAGE_AUTOWIDTH(a)
 #endif
 #define ls_trivial_usage \
-	"[-1Aa" USAGE_LS_TIMESTAMPS("c") "Cd" USAGE_LS_TIMESTAMPS("e") USAGE_LS_FILETYPES("F") "iln" USAGE_LS_FILETYPES("p") USAGE_LS_FOLLOWLINKS("L") USAGE_LS_RECURSIVE("R") USAGE_LS_SORTFILES("rS") "s" USAGE_AUTOWIDTH("T") USAGE_LS_TIMESTAMPS("tu") USAGE_LS_SORTFILES("v") USAGE_AUTOWIDTH("w") "x" USAGE_LS_SORTFILES("X") USAGE_HUMAN_READABLE("h") USAGE_NOT_HUMAN_READABLE("") "k] [filenames...]"
+	"[-1Aa" USAGE_LS_TIMESTAMPS("c") "Cd" USAGE_LS_TIMESTAMPS("e") USAGE_LS_FILETYPES("F") "iln" USAGE_LS_FILETYPES("p") USAGE_LS_FOLLOWLINKS("L") USAGE_LS_RECURSIVE("R") USAGE_LS_SORTFILES("rS") "s" USAGE_AUTOWIDTH("T") USAGE_LS_TIMESTAMPS("tu") USAGE_LS_SORTFILES("v") USAGE_AUTOWIDTH("w") "x" USAGE_LS_SORTFILES("X") USAGE_HUMAN_READABLE("h") USAGE_NOT_HUMAN_READABLE("") "k" USAGE_SELINUX("K", "") "] [filenames...]"
 #define ls_full_usage \
 	"List directory contents\n\n" \
 	"Options:\n" \
@@ -986,6 +993,7 @@
 	USAGE_AUTOWIDTH("\t-w NUM\tassume the terminal is NUM columns wide\n") \
 	"\t-x\tlist entries by lines instead of by columns\n" \
 	USAGE_LS_SORTFILES("\t-X\tsort the listing by extension\n") \
+	USAGE_SELINUX("\t-K\tprint security context\n", "") \
 	USAGE_HUMAN_READABLE( \
 	"\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \
 	"\t-k\tprint sizes in kilobytes(default)") USAGE_NOT_HUMAN_READABLE( \
@@ -1344,7 +1352,8 @@
 	""
 #define ps_full_usage \
 	"Report process status\n" \
-	"\nThis version of ps accepts no options."
+	USAGE_SELINUX("\nOptions:\n\t-c\tshow SE Linux context", "\nThis version of ps accepts no options.")
+ 
 #define ps_example_usage \
 	"$ ps\n" \
 	"  PID  Uid      Gid State Command\n" \