LSM changes for 2.5.38
Subsystems (7)
Hi,
Here are some patches against the latest 2.5 BK tree that add some further LSM hooks and documentation to the tree. There is also one minor change to fs/inode.c to allow security modules more information about newly created inodes.
These changesets can be found at bk://lsm.bkbits.net/linus-2.5 and I'll be attaching the individual patches as responses to this email for those who don't want to mess with bitkeeper.
If anyone has any questions or comments on these patches, please let us know. Otherwise I'll be sending them off to Linus in a few days.
thanks,
greg k-h
Documentation/DocBook/Makefile | 2 Documentation/DocBook/kernel-api.tmpl | 5 Documentation/DocBook/lsm.tmpl | 285 +++++++++++++++++++++++++++++++++ arch/i386/kernel/ioport.c | 14 + arch/ia64/ia32/sys_ia32.c | 7 fs/inode.c | 2 include/linux/ipc.h | 1 include/linux/msg.h | 1 include/linux/security.h | 291 ++++++++++++++++++++++++++++++++++ ipc/msg.c | 57 ++++++ ipc/sem.c | 43 ++++- ipc/shm.c | 55 ++++++ ipc/util.c | 3 kernel/printk.c | 4 kernel/sys.c | 35 ++-- kernel/sysctl.c | 5 kernel/time.c | 6 mm/oom_kill.c | 6 mm/swapfile.c | 10 + security/capability.c | 210 ++++++++++++++++++++++++ security/dummy.c | 210 ++++++++++++++++++++++++ 21 files changed, 1227 insertions(+), 25 deletions(-)
-----
[email protected], 2002-09-26 13:13:36-07:00, [email protected]
LSM: added the LSM documentation to the tree.
Documentation/DocBook/Makefile | 2 Documentation/DocBook/kernel-api.tmpl | 5 Documentation/DocBook/lsm.tmpl | 285 ++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+), 1 deletion(-)
------
[email protected], 2002-09-26 13:05:47-07:00, [email protected]
[PATCH] LSM: inode.c init modification
Quoted 5 lines · Greg KH
Yes, and explaining the fine points of
inode_init()andinode_alloc_security()and why they are different, might be a bit tough.{sigh}, well if there's no other way (and I can't think of one right now), but I really don't like it...
Here's a patch that attempt to support the same functionality without inserting hooks into filesystem-specific code. This patch permits the security module to perform initialization of the inode security state based on the superblock information, enabling SELinux to initialize pipe, devpts, and shm inodes without relying on inode_precondition to catch them on first use.
This is achieved simply by moving the initialization of inode->i_sb before the call to inode_alloc_security, enabling the inode_alloc_security hook function to perform the allocation and initialization for such inodes. No new hooks are required.
fs/inode.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
------
[email protected], 2002-09-26 11:56:46-07:00, [email protected]
[PATCH] LSM: misc hooks addition
The patch below (relative to the LSM IPC hooks patch) adds the LSM hooks for miscellaneous system operations (module_*, sethostname, setdomainname, reboot, ioperm/iopl, sysctl, swapon/swapoff, syslog, settime). It also replaces the hardcoded capability tests in the OOM killer code with appropriate calls to the LSM capable hook, preserving the original behavior as long as the capabilities module is enabled.
arch/i386/kernel/ioport.c | 14 +++++- arch/ia64/ia32/sys_ia32.c | 7 +++ include/linux/security.h | 106 ++++++++++++++++++++++++++++++++++++++++++++++ kernel/printk.c | 4 + kernel/sys.c | 35 ++++++++++----- kernel/sysctl.c | 5 ++ kernel/time.c | 6 ++ mm/oom_kill.c | 6 +- mm/swapfile.c | 10 ++++ security/capability.c | 79 ++++++++++++++++++++++++++++++++++ security/dummy.c | 79 ++++++++++++++++++++++++++++++++++ 11 files changed, 337 insertions(+), 14 deletions(-)
------
[email protected], 2002-09-26 11:56:14-07:00, [email protected]
[PATCH] LSM: SysV IPC hooks addition
The patch below adds the LSM hooks for System V IPC to the 2.5.38 kernel.
include/linux/ipc.h | 1 include/linux/msg.h | 1 include/linux/security.h | 185 +++++++++++++++++++++++++++++++++++++++++++++++ ipc/msg.c | 57 +++++++++++++- ipc/sem.c | 43 ++++++++++ ipc/shm.c | 55 +++++++++++++ ipc/util.c | 3 security/capability.c | 131 +++++++++++++++++++++++++++++++++ security/dummy.c | 131 +++++++++++++++++++++++++++++++++ 9 files changed, 598 insertions(+), 9 deletions(-)
------
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.611 -> 1.612 # include/linux/ipc.h 1.1 -> 1.2 # ipc/msg.c 1.6 -> 1.7 # include/linux/security.h 1.3 -> 1.4 # security/dummy.c 1.6 -> 1.7 # security/capability.c 1.5 -> 1.6 # ipc/sem.c 1.11 -> 1.12 # ipc/util.c 1.5 -> 1.6 # ipc/shm.c 1.17 -> 1.18 # include/linux/msg.h 1.2 -> 1.3
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/09/26 [email protected] 1.612
# [PATCH] LSM: SysV IPC hooks addition
#
# The patch below adds the LSM hooks for System V IPC to the 2.5.38 kernel. # --------------------------------------------
#
include/linux/ipc.h +1 -0
@@ -63,6 +63,7 @@gid_t cgid;mode_t mode;unsigned long seq; + void *security; };#endif /* __KERNEL__ */
include/linux/msg.h +1 -0
@@ -69,6 +69,7 @@long m_type;int m_ts;/* message text size */ struct msg_msgseg * next; +void *security;/* the actual message follows immediately */ };
include/linux/security.h +185 -0
197 lines not on this page · raw message
ipc/msg.c +53 -4
149 lines not on this page · raw message
ipc/sem.c +41 -2
105 lines not on this page · raw message
ipc/shm.c +53 -2
127 lines not on this page · raw message
ipc/util.c +2 -1
@@ -19,6 +19,7 @@#include <linux/vmalloc.h> #include <linux/slab.h> #include <linux/highuid.h> +#include <linux/security.h> #if defined(CONFIG_SYSVIPC )
@@ -263,7 +264,7 @@ !capable(CAP_IPC_OWNER))return -1 ; -return 0 ; +return security_ops->ipc_permission (ipcp, flag); }/*
security/capability.c +131 -0
143 lines not on this page · raw message
security/dummy.c +131 -0
143 lines not on this page · raw message
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.612 -> 1.613 # kernel/sys.c 1.28 -> 1.29 # kernel/sysctl.c 1.30 -> 1.31 # include/linux/security.h 1.4 -> 1.5 # mm/swapfile.c 1.56 -> 1.57 # security/dummy.c 1.7 -> 1.8 # kernel/time.c 1.7 -> 1.8
# security/capability.c 1.6 -> 1.7
# arch/i386/kernel/ioport.c 1.3 -> 1.4
# mm/oom_kill.c 1.16 -> 1.17
# arch/ia64/ia32/sys_ia32.c 1.19 -> 1.20
# kernel/printk.c 1.14 -> 1.15
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/09/26 [email protected] 1.613
# [PATCH] LSM: misc hooks addition
#
# The patch below (relative to the LSM IPC hooks patch) adds the LSM hooks
# for miscellaneous system operations (module_*, sethostname, setdomainname, # reboot, ioperm/iopl, sysctl, swapon/swapoff, syslog, settime). It also # replaces the hardcoded capability tests in the OOM killer code with # appropriate calls to the LSM capable hook, preserving the original behavior # as long as the capabilities module is enabled. # -------------------------------------------- # diff -Nru a/arch/i386/kernel/ioport.c b/arch/i386/kernel/ioport.c --- a/arch/i386/kernel/ioport.c Thu Sep 26 13:23:55 2002 +++ b/arch/i386/kernel/ioport.c Thu Sep 26 13:23:55 2002 @@ -14,6 +14,7 @@ #include <linux/smp_lock.h> #include <linux/stddef.h> #include <linux/slab.h> +#include <linux/security.h>
/* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */ static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
@@ -62,7 +63,12 @@
return -EINVAL;
if (turn_on && !capable(CAP_SYS_RAWIO))
return -EPERM;
-
+
+ ret = security_ops->ioperm(from, num, turn_on);
+ if (ret) {
+ return ret;
+ }
+
tss = init_tss + get_cpu();
/*
@@ -116,6 +122,7 @@
struct pt_regs * regs = (struct pt_regs *) &unused; unsigned int level = regs->ebx;
unsigned int old = (regs->eflags >> 12) & 3;
+ int retval;
if (level > 3)
return -EINVAL;
@@ -124,6 +131,11 @@
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
}
+ retval = security_ops->iopl(old, level);
+ if (retval) {
+ return retval;
+ }
+
regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12); return 0;
}
arch/ia64/ia32/sys_ia32.c +7 -0
@@ -49,6 +49,7 @@#include <linux/ptrace.h> #include <linux/stat.h> #include <linux/ipc.h> +#include <linux/security.h> #include <asm/types.h> #include <asm/uaccess.h>
@@ -3184,6 +3185,7 @@unsigned int old;unsigned long addr;mm_segment_t old_fs =get_fs (); +int retval;if (level !=3 )return (-EINVAL );
@@ -3193,6 +3195,11 @@if (!capable (CAP_SYS_RAWIO ))return -EPERM ; } + retval = security_ops->iopl (old,level); +if (retval) { +return retval; + } +set_fs (KERNEL_DS ); fd =sys_open ("/dev/mem" ,O_SYNC |O_RDWR ,0 );set_fs (old_fs);
include/linux/security.h +106 -0
165 lines not on this page · raw message
kernel/printk.c +4 -0
@@ -175,6 +175,10 @@char *lbuf =NULL ;int error =0 ; + error = security_ops->syslog (type); +if ( error ) +return error; +switch (type) {case 0 :/* Close log */ break ;
kernel/sys.c +25 -10
@@ -349,11 +349,17 @@asmlinkage long sys_reboot (int magic1,int magic2,unsigned int cmd,void * arg) {char buffer[256 ]; +int retval;/* We only trust the superuser with rebooting the system. */ if (!capable (CAP_SYS_BOOT ))return -EPERM ; + retval = security_ops->reboot (cmd); +if (retval) { +return retval; + } +/* For safety, we require "magic" arguments. */ if (magic1 != LINUX_REBOOT_MAGIC1 || (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A &&
@@ -1130,18 +1136,23 @@asmlinkage long sys_sethostname (char *name,int len) { +char nodename[__NEW_UTS_LEN+1 ];int errno;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;if (len <0 || len > __NEW_UTS_LEN)return -EINVAL ; +if (copy_from_user (nodename, name, len)) +return -EFAULT ; + nodename[len] =0 ; + + errno = security_ops->sethostname (nodename); +if (errno) +return errno; +down_write (&uts_sem); - errno = -EFAULT ; -if (!copy_from_user (system_utsname.nodename, name, len)) { - system_utsname.nodename[len] =0 ; - errno =0 ; - } +memcpy (system_utsname.nodename, nodename, len+1 );up_write (&uts_sem);return errno; }
@@ -1169,19 +1180,23 @@*/ asmlinkage long sys_setdomainname (char *name,int len) { +char domainname[__NEW_UTS_LEN+1 ];int errno;if (!capable (CAP_SYS_ADMIN ))return -EPERM ;if (len <0 || len > __NEW_UTS_LEN)return -EINVAL ; +if (copy_from_user (domainname, name, len)) +return -EFAULT ; + domainname[len] =0 ; + + errno = security_ops->setdomainname (domainname); +if (errno) +return errno;down_write (&uts_sem); - errno = -EFAULT ; -if (!copy_from_user (system_utsname.domainname, name, len)) { - errno =0 ; - system_utsname.domainname[len] =0 ; - } +memcpy (system_utsname.domainname, domainname, len+1 );up_write (&uts_sem);return errno; }
kernel/sysctl.c +5 -0
@@ -427,6 +427,11 @@static inline int ctl_perm (ctl_table *table,int op) { +int error; + error = security_ops->sysctl (table, op); +if (error) { +return error; + }return test_perm (table->mode, op); }
kernel/time.c +6 -0
@@ -27,6 +27,7 @@#include <linux/timex.h> #include <linux/errno.h> #include <linux/smp_lock.h> +#include <linux/security.h> #include <asm/uaccess.h>
@@ -147,9 +148,14 @@int do_sys_settimeofday (struct timeval *tv,struct timezone *tz) {static int firsttime =1 ; +int error =0 ;if (!capable (CAP_SYS_TIME ))return -EPERM ; + + error = security_ops->settime (tv, tz); +if (error) +return error;if (tz) {/* SMP safe, global irq locking makes it work. */
mm/oom_kill.c +3 -3
@@ -88,7 +88,7 @@* Superuser processes are usually more important, so we make it * less likely that we kill those. */ -if (cap_t (p->cap_effective) &CAP_TO_MASK (CAP_SYS_ADMIN ) || +if (!security_ops->capable (p,CAP_SYS_ADMIN ) || p->uid ==0 || p->euid ==0 ) points /=4 ;
@@ -98,7 +98,7 @@* tend to only have this flag set on applications they think * of as important. */ -if (cap_t (p->cap_effective) &CAP_TO_MASK (CAP_SYS_RAWIO )) +if (!security_ops->capable (p,CAP_SYS_RAWIO )) points /=4 ;#ifdef DEBUG printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
@@ -149,7 +149,7 @@ p->flags |=PF_MEMALLOC |PF_MEMDIE ;/* This process has hardware access, be more careful. */ -if (cap_t (p->cap_effective) &CAP_TO_MASK (CAP_SYS_RAWIO )) { +if (!security_ops->capable (p,CAP_SYS_RAWIO )) {force_sig (SIGTERM , p); }else {force_sig (SIGKILL , p);
mm/swapfile.c +10 -0
@@ -964,6 +964,13 @@ } prev = type; } + + err = security_ops->swapoff (p); +if (err) { +swap_list_unlock (); + goto out_dput; + } + err = -EINVAL ;if (type <0 ) {swap_list_unlock ();
@@ -1136,6 +1143,9 @@ } p->swap_file = swap_file; + error = security_ops->swapon (p); +if (error) + goto bad_swap_2; error = -EINVAL ;if (S_ISBLK (swap_file->f_dentry->d_inode->i_mode)) {
security/capability.c +79 -0
130 lines not on this page · raw message
security/dummy.c +79 -0
130 lines not on this page · raw message
Copied linux-fsdevel, as it touches the core fs code.
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.613 -> 1.614
# fs/inode.c 1.69 -> 1.70
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/09/26 [email protected] 1.614
# [PATCH] LSM: inode.c init modification
#
# On Thu, 19 Sep 2002, Greg KH wrote:
#
# > Yes, and explaining the fine points of inode_init() and
# > inode_alloc_security() and why they are different, might be a bit tough. # >
# > {sigh}, well if there's no other way (and I can't think of one right # > now), but I really don't like it...
#
# Here's a patch that attempt to support the same functionality without
# inserting hooks into filesystem-specific code. This patch permits the
# security module to perform initialization of the inode security state
# based on the superblock information, enabling SELinux to initialize
# pipe, devpts, and shm inodes without relying on inode_precondition to
# catch them on first use.
#
# This is achieved simply by moving the initialization of inode->i_sb
# before the call to inode_alloc_security, enabling the
# inode_alloc_security hook function to perform the allocation and
# initialization for such inodes. No new hooks are required.
# --------------------------------------------
#
diff -Nru a/fs/inode.c b/fs/inode.c
--- a/fs/inode.c Thu Sep 26 13:23:52 2002
+++ b/fs/inode.c Thu Sep 26 13:23:52 2002
@@ -101,6 +101,7 @@
if (inode) {
struct address_space * const mapping = &inode->i_data;+ inode->i_sb = sb;
inode->i_security = NULL;
if (security_ops->inode_alloc_security(inode)) {
if (inode->i_sb->s_op->destroy_inode)
@@ -109,7 +110,6 @@
kmem_cache_free(inode_cachep, (inode));
return NULL;
}
- inode->i_sb = sb;
inode->i_dev = sb->s_dev;
inode->i_blkbits = sb->s_blocksize_bits; inode->i_flags = 0;
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.614 -> 1.615
# Documentation/DocBook/kernel-api.tmpl 1.19 -> 1.20
# Documentation/DocBook/Makefile 1.30 -> 1.31
# (new) -> 1.1 Documentation/DocBook/lsm.tmpl
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/09/26 [email protected] 1.615
# LSM: added the LSM documentation to the tree.
# --------------------------------------------
#
Documentation/DocBook/Makefile +1 -1
@@ -11,7 +11,7 @@ kernel-locking.sgml via-audio.sgml mousedrivers.sgml \ deviceiobook.sgml procfs-guide.sgml tulip-user.sgml \ writing_usb_driver.sgml scsidrivers.sgml sis900.sgml \ - kernel-api.sgml + kernel-api.sgml lsm.sgml ### # The build process is as follows (targets):
Documentation/DocBook/kernel-api.tmpl +5 -0
@@ -185,6 +185,11 @@ !Efs/devfs/base.c </chapter> + <chapter id="security"> + <title>Security Framework</title> +!Esecurity/security.c + </chapter> + <chapter id="pmfuncs"> <title>Power Management</title> !Ekernel/pm.c
Documentation/DocBook/lsm.tmpl new file +285 -0
285 lines not on this page · raw message