Skip to contentSkip to conversation

Reducing size of libselinux/libsepol: 3rd

PATCH In review Yuichi Nakamura 2 participants 2 messages May 23, 2007 – May 31, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Reducing size of libselinux/libsepol: 3rd

Hi.
As discussed in previous threads,
http://marc.info/?t=117609454600002&r=1&w=2
http://marc.info/?t=117886013000001&r=1&w=2
I would like to submit patch to reduce size of libselinux+libsepol, again.

1. Background
Current libselinux+libsepol size is big for embedded devices. libselinux.so.1: 115348 byte
libsepol.so.1:302067
Total: 417415 byte
It uses more than 400kbyte.
Needs for embedded device is various, because hardware resource is various. If device is rich enough, people may want full-featured SELinux. If device is not rich, people want to reduce binary size by removing some features.
For example, some may not want modular policy, may not want boolean.

We thought size of libselinux+libsepol can be reduced
by removing libsepol and removing unnecessary functions from libselinux.

2. What this patch does
1) libsepol is separated from libselinux
libsepol is not required by libselinux.
So you do not have to compile libsepol,
if you do not need libsepol functions.

2) Some features are disabled in libselinux
By typing "make EMBEDDED=y" in libselinux dir, what happens is following. Following values are defined in Makefile.

Quoted 6 lines

ifeq ($(EMBEDDED),y)
override DISABLE_AVC=y
override DISABLE_SETRANS=y
override DISABLE_RPM=y
override DISABLE_BOOL=y
endif

* DISABLE_AVC
Disables user space avc support, avc.c avc_internal.c avc_sidtab.c are not compiled.
* DISABLE_SETRANS
Some functions of translations are replaced with stubs in setrans_client.c
* DISABLE_RPM
Disables rpm features, rpm.c are not compiled.
* DISABLE_BOOL
Disable boolean features, booleans.c are not compiled.

3) Fixes to libselinux/utils
* -lsepol is removed
* When make EMBEDDED=y, some utils are not compiled.

3. Size measurement
Compiled libselinux/libsepol in trunk by gcc(x86).

* Before
libselinux.so.1: 115348 byte
libsepol.so.1:302067
Total: 417415 byte

* After
libselinux.so.1: 77103 byte
libsepol.so.1:0 byte(do not have to compile)
Total: 77103 byte

Please consider merging this patch.

-------

 Makefile             |   18 ++++
 src/Makefile         |   20 ++++-
 src/load_policy.c    |  190 +++++++++++++++++++++++++++++++++++++--------------
 src/policy.h         |    2
 src/policyvers.c     |    2
 src/setrans_client.c |   49 ++++++++++++-
 utils/Makefile       |   11 ++
libselinux/utils/Makefile +9 -2
Index: trunk/libselinux/utils/Makefile
===================================================================
@@ -4,10 +4,17 @@
 BINDIR ?= $(PREFIX)/sbin
 
 CFLAGS ?= -Wall
-override CFLAGS += -I../include -D_GNU_SOURCE
-LDLIBS += -L../src -lselinux -lsepol -L$(LIBDIR)
+override CFLAGS += -I../include -D_GNU_SOURCE $(EMFLAGS)
+LDLIBS += -L../src -lselinux -L$(LIBDIR)
 
 TARGETS=$(patsubst %.c,%,$(wildcard *.c))
+ifeq ($(DISABLE_AVC),y)
+	UNUSED_TARGETS+=compute_av compute_create compute_member compute_relabel
+endif
+ifeq ($(DISABLE_BOOL),y)
+	UNUSED_TARGETS+=getsebool togglesebool
+endif
+TARGETS:= $(filter-out $(UNUSED_TARGETS), $(TARGETS))
 
 all: $(TARGETS)
 
libselinux/src/policyvers.c +0 -2
Index: trunk/libselinux/src/policyvers.c
===================================================================
@@ -10,8 +10,6 @@
 #include "dso.h"
 #include <limits.h>
 
-#define DEFAULT_POLICY_VERSION 15
-
 int security_policyvers(void)
 {
 	int fd, ret;
libselinux/src/policy.h +2 -0
Index: trunk/libselinux/src/policy.h
===================================================================
@@ -20,4 +20,6 @@
 
 #define FILECONTEXTS "/etc/security/selinux/file_contexts"
 
+#define DEFAULT_POLICY_VERSION 15
+
 #endif
libselinux/src/setrans_client.c +48 -1

61 lines not on this page · raw message

libselinux/src/Makefile +16 -4
Index: trunk/libselinux/src/Makefile
===================================================================
@@ -18,10 +18,22 @@
 SWIGSO=_selinux.so
 SWIGFILES=$(SWIGSO) selinux.py 
 LIBSO=$(TARGET).$(LIBVERSION)
-OBJS= $(patsubst %.c,%.o,$(filter-out $(SWIGCOUT),$(wildcard *.c))) 
-LOBJS= $(patsubst %.c,%.lo,$(filter-out $(SWIGCOUT),$(wildcard *.c)))
+
+ifeq ($(DISABLE_AVC),y)
+	UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c 
+endif
+ifeq ($(DISABLE_BOOL),y)
+	UNUSED_SRCS+=booleans.c
+endif
+ifeq ($(DISABLE_RPM),y)
+	UNUSED_SRCS+=rpm.c
+endif
+SRCS= $(filter-out $(UNUSED_SRCS), $(filter-out $(SWIGCOUT),$(wildcard *.c)))
+
+OBJS= $(patsubst %.c,%.o,$(SRCS))
+LOBJS= $(patsubst %.c,%.lo,$(SRCS))
 CFLAGS ?= -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute
-override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
+override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(EMFLAGS)
 RANLIB=ranlib
 
 ARCH := $(patsubst i%86,i386,$(shell uname -m))
@@ -48,7 +60,7 @@
 	$(CC) $(LDFLAGS) -shared -o $@ $< -L. -lselinux -L$(LIBDIR) -Wl,-soname,$@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(LDFLAGS) -shared -o $@ $^ -ldl -lsepol -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+	$(CC) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET) 
 
 %.o:  %.c policy.h
libselinux/src/load_policy.c +139 -51

251 lines not on this page · raw message

libselinux/Makefile +18 -0
Index: trunk/libselinux/Makefile
===================================================================
@@ -1,3 +1,21 @@
+DISABLE_AVC ?= n
+DISABLE_SETRANS ?= n
+DISABLE_RPM ?= n
+DISABLE_BOOL ?= n
+ifeq ($(EMBEDDED),y)
+	override DISABLE_AVC=y
+	override DISABLE_SETRANS=y
+	override DISABLE_RPM=y
+	override DISABLE_BOOL=y
+endif
+ifeq ($(DISABLE_BOOL),y)
+	EMFLAGS+= -DDISABLE_BOOL
+endif
+ifeq ($(DISABLE_SETRANS),y)
+	EMFLAGS+= -DDISABLE_SETRANS
+endif
+export DISABLE_AVC DISABLE_SETRANS DISABLE_RPM DISABLE_BOOL EMFLAGS
+
 all: 
 	$(MAKE) -C src 
 	$(MAKE) -C utils

Regards,

Signature · 10 lines
Yuichi Nakamura
Hitachi Software Engineering Co., Ltd.
Japan SELinux Users Group(JSELUG)
SELinux Policy Editor: http://seedit.sourceforge.net/


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 58 lines · Yuichi Nakamura

Hi.
As discussed in previous threads,
http://marc.info/?t=117609454600002&r=1&w=2
http://marc.info/?t=117886013000001&r=1&w=2
I would like to submit patch to reduce size of libselinux+libsepol, again.

1. Background
Current libselinux+libsepol size is big for embedded devices. libselinux.so.1: 115348 byte
libsepol.so.1:302067
Total: 417415 byte
It uses more than 400kbyte.
Needs for embedded device is various, because hardware resource is various. If device is rich enough, people may want full-featured SELinux. If device is not rich, people want to reduce binary size by removing some features.
For example, some may not want modular policy, may not want boolean.

We thought size of libselinux+libsepol can be reduced
by removing libsepol and removing unnecessary functions from libselinux.

2. What this patch does
1) libsepol is separated from libselinux
libsepol is not required by libselinux.
So you do not have to compile libsepol,
if you do not need libsepol functions.

2) Some features are disabled in libselinux
By typing "make EMBEDDED=y" in libselinux dir, what happens is following. Following values are defined in Makefile.

Quoted 6 lines

ifeq ($(EMBEDDED),y)
override DISABLE_AVC=y
override DISABLE_SETRANS=y
override DISABLE_RPM=y
override DISABLE_BOOL=y
endif

* DISABLE_AVC
Disables user space avc support, avc.c avc_internal.c avc_sidtab.c are not compiled.
* DISABLE_SETRANS
Some functions of translations are replaced with stubs in setrans_client.c
* DISABLE_RPM
Disables rpm features, rpm.c are not compiled.
* DISABLE_BOOL
Disable boolean features, booleans.c are not compiled.

3) Fixes to libselinux/utils
* -lsepol is removed
* When make EMBEDDED=y, some utils are not compiled.

3. Size measurement
Compiled libselinux/libsepol in trunk by gcc(x86).

* Before
libselinux.so.1: 115348 byte
libsepol.so.1:302067
Total: 417415 byte

Quoted 6 lines

* After
libselinux.so.1: 77103 byte
libsepol.so.1:0 byte(do not have to compile)
Total: 77103 byte

Please consider merging this patch.

Thanks, merged.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.