Skip to contentSkip to conversation

Trusted Path Execution LSM 0.2 (20050107)

PATCH New Lorenzo Hernández García-Hierro 1 participant 1 message Jan 7, 2005

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

PATCH 1/1 Trusted Path Execution LSM 0.2 (20050107)

Hi,

As Chris Wright suggested, the old limitations of the module are not existing anymore, and the protection hooks are now based on memory mappings of executables, which means, you can't bypass it by using the old ld-linux shared library wrapping trick.

Also, many fixes for the module memory use and management, that also prevent a possible overflowing in read functions of acl management code, reported by Brad Spengler (a.k.a. spender) when we were revising it yesterday night.

Also Seth Arnold helped me with some fixes and recommendations. Anyway, feel free to try to mess it up, i would appreciate any information about possible vulnerabilities, unexpected behaviors, stinking buffers...whatever else ;)
Those who have contributed to this little project are listed in the tpe.c source file.

The patch is attached, but i encourage to check out the
http://selinux.tuxedo-es.org/tpe-lsm/ site, as there you can find two regression tests, one to try to bypass the engine and the other one for trigger a basic overflow in the acl read functions (results can be found at http://selinux.tuxedo-es.org/tpe-lsm/rtest2-log.txt).

The current limitations are described in the tpe-lsm.txt file, inside ./Documentation/ and a few examples can be found at
http://selinux.tuxedo-es.org/tpe-lsm/0.2-TPE-LSM-Demonstration.txt )

Now i think it could have a chance for mainline inclusion.

Cheers,

Signature · 2 lines
Lorenzo Hernández García-Hierro <[email protected]> [1024D/6F2B2DEC]
[2048g/9AE91A22] Hardened Debian head developer & project manager
Documentation/tpe-lsm.txt renamed from linux-2.6.10/Documentation/tpe-lsm.txt +103 -0
diff -Nur ../linux-2.6.10/Documentation/tpe-lsm.txt linux-2.6.10-tpe/Documentation/tpe-lsm.txt
@@ -0,0 +1,103 @@
+Trusted Path Execution Linux Security Module
+Copyright (C) 2003 IBM Corp. <[email protected]>
+Copyright (C) 2005 Lorenzo Hernandez Garcia-Hierro <[email protected]>
+Author: Lorenzo Hernandez Garcia-Hierro (Original: Niki Rahimi)
+This file is distributed according to the GNU General Public License.
+This module was tested on the Linux kernel 2.6.9 and 2.6.10.
+
+The purpose of the Trusted Path Execution Linux Security Module is to enable a
+check in the Linux kernel to limit the running of executables in trusted paths
+so that the potential for malicious code to be run on the system is reduced.
+A trusted path is one in which the parent directory of a file is owned by root
+and is neither group nor other writeable. 
+The module relies on a kernel hook which checks to see if the given path is
+trusted or not and who is the user (or group member) that caused the event (execution).
+This check takes place directly upon an attempt to execute the code by using the 
+file_mmap and file_mprotect hooks which control how mmap() can do the memory mapping
+for an executable, preventing the engine to be bypassed by using tricks like the
+ld-linux.so.2 one or any other shared-library-wrapping trick.Also, the file_mprotect
+hook prevents mprotect() of being abused for bypass the TPE engine.
+Old bprm_check_security behavior is not anymore used and is dropped in the source. 
+
+Limitations: 
+Right now, the engine does not use the bprm_secureexec hook to 
+prevent use of sensitive LD_{PRELOAD,DEBUG} variables by untrusted users or groups, but
+making these checks relying in kernel space has been demonstrated being less efficient
+than simply checking and having a well-configured user space.
+Also, script or source interpreters like sh for shell scripts, python, etc could still
+execute code as they run normally from trusted paths, the solution relies on having them
+in non trusted paths or even implementing an user space control tool, use SELinux or
+an advanced method for memory mappings execution.
+This features could be developed, but it's not a critical, blocking issue and in my opinion,
+they shouldn't rely on the kernel space.
+
+The module also creates two Trusted Path access control lists which can be accessed
+by a sysfs mountpoint, inside the ./tpefs/ subdir (ie: /sys/tpefs), writeable by root,
+who can add and delete uids (user id's) and a entire range of users using the (new) native
+support for per-gid (group id) basis access control lists. A user on the list is 
+considered trusted.
+Also, it creates a procfs entry called "tpe" (ie: /proc/tpe) which provides
+version information, total amount of trusted users, total amount of trusted groups and
+other information, depending on the code revision), and those who want extra garbage
+from the kernel will like to enabled debugging by passing debug=1 to the module parameters.
+By default, root is hard coded onto this list with also a trusted gid
+which gets automatically added when selecting the "GID for trusted users" option in kernel
+configuration (SECURITY_TPE_TRUSTED_GID).
+
+Thus if user A attempts to run an executable in path A, the following scenarios
+can play out:
+
+1. Trusted user,trusted path 			= User is able to run the executable.
+2. Trusted user,trusted path,trusted group	= User is able to run the executable.
+3. Trusted user,untrusted path  		= User is able to run the executable.
+4. Trusted user,untrusted path,trusted group	= User is able to run the executable.
+5. Trusted user,untrusted path,untrusted group	= User is able to run the executable.
+6. Untrusted user,trusted path	 		= User is able to run the executable.
+7. Untrusted user,trusted path,trusted group 	= User is able to run the executable.
+8. Untrusted user,trusted path,untrusted group 	= User is able to run the executable.
+9. Untrusted user,untrusted path		= User is not able to run the executable.#
+10. Untrusted user,untrusted path,trusted group	= User is able to run the executable.
+11. Untrusted user,untrusted path,untrusted group= User is not able to run the executable.#
+
+In execution terms, untrusted users under untrusted groups and paths wouldn't
+be able to change or alter the memory layout nor mmap() executables in memory,
+preventing any type of untrusted execution.
+
+In short, if the path and user are both untrusted (and if the group is untrusted),
+execution will be denied sending a message with the uid,gid,euid,egid,pid and full path
+to binary that caused the event.
+
+In order to actually modify the access control list for TPE, the module uses
+a sysfs subsystem called tpefs. The tpefs contains four files; add, del, add-group
+and del-group.
+Performing read and write operations on the aforementioned files creates a user
+to system interface that will alter the TPE access control list. See 
+"Modifying the TPE Access Control Lists" below for the methods of altering the list 
+using these files.
+Note: The original two file approach was utilized rather than a single file in order to
+keep the code and administration of the module simple for both the kernel and
+the user, and it was when only uid-based access control lists were supported, now
+i've followed the same style to provide backwards compatibility.
+
+Installation: 
+1. Recompile the kernel to include LSM and TPE as a module (or even get a
+   kernel-independent packaged TPE module.
+2. mount -t sysfs sysfs <mountpoint>
+3. modprobe tpe debug=1/0 (if you want to use debugging set to 1)
+4. See "Modifying the TPE Access Control Lists" below  for instructions on how to 
+add/delete users and groups to/from the list.
+
+Modifying the TPE Access Control Lists:
+
+- Adding a user		: echo <uid> > <mountpoint>/tpefs/add
+- Deleting a user	: echo <uid> > <mountpoint>/tpefs/del
+- Adding a group	: echo <gid> > <mountpoint>/tpefs/add-group
+- Deleting a group	: echo <gid> > <mountpoint>/tpefs/del-group
+- Show uid list to userspace: cat <mountpoint>/tpefs/add
+- Show gid list to userspace: cat <mountpoint>/tpefs/add-group
+- Show version and statistics information: cat /proc/tpe
+
+Note: Advanced users would be interested in writing a script or something
+to modify the access control lists in a fine-grained manner, but this is out
+of the goals of the TPE development, anyway, feel free to send your contributions
+to [email protected].
security/Kconfig renamed from linux-2.6.10/security/Kconfig +30 -0
diff -Nur ../linux-2.6.10/security/Kconfig linux-2.6.10-tpe/security/Kconfig
@@ -84,6 +84,36 @@
 
 	  If you are unsure how to answer this question, answer N.
 
+config SECURITY_TPE
+	tristate "Trusted Path Execution (EXPERIMENTAL)"
+	depends on SECURITY && EXPERIMENTAL
+	help
+	  The TPE module enforces a check on the running of executables.
+	  It will not allow execution if the program is located in a 
+	  "trusted path" and the current user is "untrusted". A trusted
+	  path is one which is root owned and neither group nor other 
+   	  writeable. A user is considered trusted if their uid is added
+ 	  to a trusted list in memory, also, user groups can be trusted
+ 	  in kernel compile-time and runtime by adding them to the gid-basis
+ 	  access control list.Root is trusted, by default.A proc interface
+ 	  /proc/tpe is created when module loads, it shows version and ACL
+ 	  information to use third-party checkers or scripts.
+ 	  
+	  (c) 2005, Lorenzo Hernandez Garcia-Hierro <[email protected]>.
+	  
+	  If you are unsure how to answer this question, answer N.
+
+config SECURITY_TPE_TRUSTED_GID
+	int "GID for trusted users"
+	depends on SECURITY_TPE
+	default 1337
+	help
+	  Here you can choose the GID to disable trusted path protection for.
+	  Users relying under the group with id specified here will have TPE
+	  disabled by default, so, they could represent a security risk for 
+	  the rest of users.Please, be sure that you can really trust in the
+	  members of this group.	  
+
 source security/selinux/Kconfig
 
 endmenu
security/Makefile renamed from linux-2.6.10/security/Makefile +1 -0
diff -Nur ../linux-2.6.10/security/Makefile linux-2.6.10-tpe/security/Makefile
@@ -17,3 +17,4 @@
 obj-$(CONFIG_SECURITY_CAPABILITIES)	+= commoncap.o capability.o
 obj-$(CONFIG_SECURITY_ROOTPLUG)		+= commoncap.o root_plug.o
 obj-$(CONFIG_SECURITY_SECLVL)		+= seclvl.o
+obj-$(CONFIG_SECURITY_TPE)		+= tpe.o
security/tpe.c renamed from linux-2.6.10/security/tpe.c +735 -0

735 lines not on this page · raw message

security/tpe.h renamed from linux-2.6.10/security/tpe.h +158 -0

158 lines not on this page · raw message