SELinux patches for 2.6.23
Subsystems (7)
James Morris
maintainercover SELinux patches for 2.6.23
The following changes since commit 7dcca30a32aadb0520417521b0c44f42d09fe05c:
Linus Torvalds (1):
Linux 2.6.22
are found in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/selinux-2.6.git#for-linus
Adrian Bunk (1):
security: unexport mmap_min_addr
Christopher J. PeBenito (4):
selinux: add support for querying object classes and permissions from the running policy
selinux: rename sel_remove_bools() for more general usage.
selinux: change sel_make_dir() to specify inode counter.
selinux: add selinuxfs structure for object class discovery
Eric Paris (2):
selinux: introduce schedule points in policydb_destroy()
security: Protection for exploiting null dereference using mmap
James Morris (1):
security: revalidate rw permissions for sys_splice and sys_vmsplice
Paul Moore (1):
SELinux: use SECINITSID_NETMSG instead of SECINITSID_UNLABELED for NetLabel
Stephen Smalley (1):
SELinux: allow preemption between transition permission checks
Tobias Oed (1):
SELinux: Use %lu for inode->i_no when printing avc
Documentation/sysctl/vm.txt | 15 ++ fs/splice.c | 14 ++ include/linux/security.h | 17 ++- kernel/sysctl.c | 10 + mm/mmap.c | 4 +- mm/mremap.c | 13 +- mm/nommu.c | 2 +- security/dummy.c | 6 +- security/security.c | 1 + security/selinux/avc.c | 12 +- security/selinux/hooks.c | 42 +++-- security/selinux/include/av_perm_to_string.h | 1 + security/selinux/include/av_permissions.h | 1 + security/selinux/include/avc.h | 6 +- security/selinux/include/class_to_string.h | 1 + security/selinux/include/flask.h | 1 + security/selinux/include/security.h | 4 + security/selinux/netlabel.c | 34 ++-- security/selinux/selinuxfs.c | 269 +++++++++++++++++++++++++- security/selinux/ss/policydb.c | 7 + security/selinux/ss/services.c | 144 ++++++++++++-- 21 files changed, 518 insertions(+), 86 deletions(-)
Signature · 2 lines
James Morris <[email protected]>
James Morris
maintainerPATCH 1/11 selinux: add support for querying object classes and permissions from the running policy
From: Christopher J. PeBenito <[email protected]>
Add support to the SELinux security server for obtaining a list of classes, and for obtaining a list of permissions for a specified class.
--- security/selinux/include/security.h | 3 + security/selinux/ss/services.c | 95 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 0 deletions(-)
security/selinux/include/security.h +3 -0
@@ -87,6 +87,9 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,int security_sid_mls_copy (u32 sid,u32 mls_sid,u32 *new_sid); +int security_get_classes (char ***classes,int *nclasses); +int security_get_permissions (char *class,char ***perms,int *nperms); +#define SECURITY_FS_USE_XATTR 1/* use xattr */ #define SECURITY_FS_USE_TRANS 2/* use transition SIDs, e.g. devpts/tmpfs */ #define SECURITY_FS_USE_TASK 3/* use task SIDs, e.g. pipefs/sockfs */
security/selinux/ss/services.c +95 -0
101 lines not on this page · raw message
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 2/11 selinux: rename sel_remove_bools() for more general usage.
In reply to James MorrisFrom: Christopher J. PeBenito <[email protected]>
sel_remove_bools() will also be used by the object class discovery, rename it for more general use.
--- security/selinux/selinuxfs.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
security/selinux/selinuxfs.c +4 -5
@@ -940,9 +940,8 @@ static const struct file_operations sel_commit_bools_ops = { .write = sel_commit_bools_write, }; -/* delete booleans - partial revoke() from -* fs/proc/generic.c proc_kill_inodes */ -static void sel_remove_bools (struct dentry *de) +/* partial revoke() from fs/proc/generic.c proc_kill_inodes */ +static void sel_remove_entries (struct dentry *de) {struct list_head *p, *node;struct super_block *sb = de->d_sb;
@@ -998,7 +997,7 @@ static int sel_make_bools(void)kfree (bool_pending_values); bool_pending_values =NULL ; -sel_remove_bools (dir); +sel_remove_entries (dir);if (!(page = (char *)get_zeroed_page (GFP_KERNEL )))return -ENOMEM ;
@@ -1048,7 +1047,7 @@ out:return ret; err:kfree (values); -sel_remove_bools (dir); +sel_remove_entries (dir); ret = -ENOMEM ; goto out; }
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 3/11 selinux: change sel_make_dir() to specify inode counter
In reply to James MorrisFrom: Christopher J. PeBenito <[email protected]>
Specify the inode counter explicitly in sel_make_dir(), rather than always using sel_last_ino.
--- security/selinux/selinuxfs.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
security/selinux/selinuxfs.c +6 -5
@@ -1293,7 +1293,8 @@ out:return ret; } -static int sel_make_dir (struct inode *dir,struct dentry *dentry) +static int sel_make_dir (struct inode *dir,struct dentry *dentry, +unsigned long *ino) {int ret =0 ;struct inode *inode;
@@ -1305,7 +1306,7 @@ static int sel_make_dir(struct inode *dir, struct dentry *dentry) } inode->i_op = &simple_dir_inode_operations; inode->i_fop = &simple_dir_operations; - inode->i_ino = ++sel_last_ino; + inode->i_ino = ++(*ino);/* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink (inode);d_add (dentry, inode);
@@ -1351,7 +1352,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) goto err; } - ret =sel_make_dir (root_inode, dentry); + ret =sel_make_dir (root_inode, dentry, &sel_last_ino);if (ret) goto err;
@@ -1384,7 +1385,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) goto err; } - ret =sel_make_dir (root_inode, dentry); + ret =sel_make_dir (root_inode, dentry, &sel_last_ino);if (ret) goto err;
@@ -1398,7 +1399,7 @@ static int sel_fill_super(struct super_block * sb, void * data, int silent) goto err; } - ret =sel_make_dir (root_inode, dentry); + ret =sel_make_dir (root_inode, dentry, &sel_last_ino);if (ret) goto err;
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 4/11 selinux: add selinuxfs structure for object class discovery
In reply to James MorrisFrom: Christopher J. PeBenito <[email protected]>
The structure is as follows (relative to selinuxfs root):
/class/file/index
/class/file/perms/read
/class/file/perms/write
...
Each class is allocated 33 inodes, 1 for the class index and 32 for permissions. Relative to SEL_CLASS_INO_OFFSET, the inode of the index file DIV 33 is the class number. The inode of the permission file % 33 is the index of the permission for that class.
--- security/selinux/include/security.h | 1 + security/selinux/selinuxfs.c | 249 +++++++++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+), 0 deletions(-)
security/selinux/include/security.h +1 -0
@@ -41,6 +41,7 @@ extern int selinux_mls_enabled;int security_load_policy (void * data,size_t len); +#define SEL_VEC_MAX 32struct av_decision {u32 allowed;u32 decided;
security/selinux/selinuxfs.c +249 -0
289 lines not on this page · raw message
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 5/11 security: revalidate rw permissions for sys_splice and sys_vmsplice
In reply to James MorrisRevalidate read/write permissions for splice(2) and vmslice(2), in case security policy has changed since the files were opened.
--- fs/splice.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
fs/splice.c +14 -0
@@ -28,6 +28,7 @@#include <linux/module.h> #include <linux/syscalls.h> #include <linux/uio.h> +#include <linux/security.h> struct partial_page {unsigned int offset;
@@ -931,6 +932,10 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,if (unlikely (ret <0 ))return ret; + ret =security_file_permission (out,MAY_WRITE ); +if (unlikely (ret <0 )) +return ret; +return out->f_op->splice_write (pipe, out, ppos, len, flags); }
@@ -953,6 +958,10 @@ static long do_splice_to(struct file *in, loff_t *ppos,if (unlikely (ret <0 ))return ret; + ret =security_file_permission (in,MAY_READ ); +if (unlikely (ret <0 )) +return ret; +return in->f_op->splice_read (in, ppos, pipe, len, flags); }
@@ -1271,6 +1280,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,static long do_vmsplice (struct file *file,const struct iovec __user *iov,unsigned long nr_segs,unsigned int flags) { +long err;struct pipe_inode_info *pipe;struct page *pages[PIPE_BUFFERS ];struct partial_page partial[PIPE_BUFFERS ];
@@ -1289,6 +1299,10 @@ static long do_vmsplice(struct file *file, const struct iovec __user *iov,else if (unlikely (!nr_segs))return 0 ; + err =security_file_permission (file,MAY_WRITE ); +if (unlikely (err <0 )) +return err; + spd.nr_pages =get_iovec_page_array (iov, nr_segs, pages, partial, flags &SPLICE_F_GIFT );if (spd.nr_pages <=0 )
Signature · 1 line
1.5.0.6
James Morris
maintainerRe: [PATCH 05/11] security: revalidate rw permissions for sys_splice and sys_vmsplice
Quoted 2 lines · James Morris
Revalidate read/write permissions for splice(2) and vmslice(2), in case security policy has changed since the files were opened.
This patch clashes with changes which came in via Jens (who I'll submit the patch via once it's fixed).
I'll send an updated pull request with this patch removed from the branch.
- James
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH 05/11] security: revalidate rw permissions for sys_splice and sys_vmsplice
Quoted 9 lines · James Morris
Quoted 2 lines · James Morris
Revalidate read/write permissions for splice(2) and vmslice(2), in case security policy has changed since the files were opened.
This patch clashes with changes which came in via Jens (who I'll submit the patch via once it's fixed).
I'll send an updated pull request with this patch removed from the branch.
Just send me the vmsplice/splice patch, and I'll review and integrate it.
Signature · 1 line
Jens Axboe
James Morris
maintainerPATCH 6/11 selinux: introduce schedule points in policydb_destroy()
In reply to James MorrisFrom: Eric Paris <[email protected]>
During the LSPP testing we found that it was possible for policydb_destroy() to take 10+ seconds of kernel time to complete. Basically all policydb_destroy() does is walk some (possibly long) lists and free the memory it finds. Turning off slab debugging config options made the problem go away since the actual functions which took most of the time were (as seen by oprofile)
Quoted 2 lines
121202 23.9879 .check_poison_obj 78247 15.4864 .check_slabp
were caused by that. So I decided to also add some voluntary schedule points in that code so config voluntary preempt would be enough to solve the problem. Something similar was done in places like shmem_free_pages() when we have to walk a list of memory and free it. This was tested by the LSPP group on the hardware which could reproduce the problem just loading a new policy and was found to not trigger the softlock detector. It takes just as much processing time, but the kernel doesn't spend all that time stuck doing one thing and never scheduling.
Someday a better way to handle memory might make the time needed in this function a lot less, but this fixes the current issue as it stands today.
--- security/selinux/ss/policydb.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
security/selinux/ss/policydb.c +7 -0
@@ -21,6 +21,7 @@*/ #include <linux/kernel.h> +#include <linux/sched.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/errno.h>
@@ -598,6 +599,7 @@ void policydb_destroy(struct policydb *p)struct range_trans *rt, *lrt =NULL ;for (i =0 ; i <SYM_NUM ; i++) { +cond_resched ();hashtab_map (p->symtab[i].table, destroy_f[i],NULL );hashtab_destroy (p->symtab[i].table); }
@@ -612,6 +614,7 @@ void policydb_destroy(struct policydb *p)avtab_destroy (&p->te_avtab);for (i =0 ; i <OCON_NUM ; i++) { +cond_resched (); c = p->ocontexts[i];while (c) { ctmp = c;
@@ -623,6 +626,7 @@ void policydb_destroy(struct policydb *p) g = p->genfs;while (g) { +cond_resched ();kfree (g->fstype); c = g->head;while (c) {
@@ -639,18 +643,21 @@ void policydb_destroy(struct policydb *p)cond_policydb_destroy (p);for (tr = p->role_tr; tr; tr = tr->next) { +cond_resched ();kfree (ltr); ltr = tr; }kfree (ltr);for (ra = p->role_allow; ra; ra = ra -> next) { +cond_resched ();kfree (lra); lra = ra; }kfree (lra);for (rt = p->range_tr; rt; rt = rt -> next) { +cond_resched ();if (lrt) {ebitmap_destroy (&lrt->target_range.level[0 ].cat);ebitmap_destroy (&lrt->target_range.level[1 ].cat);
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 7/11 SELinux: allow preemption between transition permission checks
In reply to James MorrisFrom: Stephen Smalley <[email protected]>
In security_get_user_sids, move the transition permission checks outside of the section holding the policy rdlock, and use the AVC to perform the checks, calling cond_resched after each one. These changes should allow preemption between the individual checks and enable caching of the results. It may however increase the overall time spent in the function in some cases, particularly in the cache miss case.
The long term fix will be to take much of this logic to userspace by exporting additional state via selinuxfs, and ultimately deprecating and eliminating this interface from the kernel.
--- security/selinux/avc.c | 10 +++++--- security/selinux/hooks.c | 9 ++++--- security/selinux/include/avc.h | 6 +++- security/selinux/ss/services.c | 49 ++++++++++++++++++++++++--------------- 4 files changed, 45 insertions(+), 29 deletions(-)
security/selinux/avc.c +6 -4
@@ -832,6 +832,7 @@ int avc_ss_reset(u32 seqno)* @tsid: target security identifier * @tclass: target security class * @requested: requested permissions, interpreted based on @tclass +* @flags: AVC_STRICT or 0 * @avd: access vector decisions * * Check the AVC to determine whether the @requested permissions are granted
@@ -846,8 +847,9 @@ int avc_ss_reset(u32 seqno)* should be released for the auditing. */ int avc_has_perm_noaudit (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd) +u16 tclass,u32 requested, +unsigned flags, +struct av_decision *avd) {struct avc_node *node;struct avc_entry entry, *p_ae;
@@ -874,7 +876,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid, denied = requested & ~(p_ae->avd.allowed);if (!requested || denied) { -if (selinux_enforcing) +if (selinux_enforcing || (flags &AVC_STRICT )) rc = -EACCES ;else if (node)
@@ -909,7 +911,7 @@ int avc_has_perm(u32 ssid, u32 tsid, u16 tclass,struct av_decision avd;int rc; - rc =avc_has_perm_noaudit (ssid, tsid, tclass, requested, &avd); + rc =avc_has_perm_noaudit (ssid, tsid, tclass, requested,0 , &avd);avc_audit (ssid, tsid, tclass, requested, &avd, rc, auditdata);return rc; }
security/selinux/hooks.c +5 -4
@@ -1592,9 +1592,10 @@ static int selinux_vm_enough_memory(long pages) rc = secondary_ops->capable (current,CAP_SYS_ADMIN );if (rc ==0 ) rc =avc_has_perm_noaudit (tsec->sid, tsec->sid, -SECCLASS_CAPABILITY , -CAP_TO_MASK (CAP_SYS_ADMIN ), -NULL ); +SECCLASS_CAPABILITY , +CAP_TO_MASK (CAP_SYS_ADMIN ), +0 , +NULL );if (rc ==0 ) cap_sys_admin =1 ;
@@ -4626,7 +4627,7 @@ static int selinux_setprocattr(struct task_struct *p,if (p->ptrace &PT_PTRACED ) { error =avc_has_perm_noaudit (tsec->ptrace_sid, sid,SECCLASS_PROCESS , -PROCESS__PTRACE , &avd); +PROCESS__PTRACE ,0 , &avd);if (!error) tsec->sid = sid;task_unlock (p);
security/selinux/include/avc.h +4 -2
@@ -102,9 +102,11 @@ void avc_audit(u32 ssid, u32 tsid, u16 tclass, u32 requested, struct av_decision *avd, int result, struct avc_audit_data *auditdata); +#define AVC_STRICT 1/* Ignore permissive mode. */ int avc_has_perm_noaudit (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +u16 tclass,u32 requested, +unsigned flags, +struct av_decision *avd); int avc_has_perm(u32 ssid, u32 tsid, u16 tclass, u32 requested,
security/selinux/ss/services.c +30 -19
84 lines not on this page · raw message
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 8/11 SELinux: Use %lu for inode->i_no when printing avc
In reply to James MorrisFrom: Tobias Oed <[email protected]>
Inode numbers are unsigned long and so need to %lu as format string of printf.
--- security/selinux/avc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
security/selinux/avc.c +1 -1
@@ -586,7 +586,7 @@ void avc_audit(u32 ssid, u32 tsid, } }if (inode) -audit_log_format (ab," dev=%s ino=%ld" , +audit_log_format (ab," dev=%s ino=%lu" , inode->i_sb->s_id, inode->i_ino);break ;
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 9/11 security: Protection for exploiting null dereference using mmap
In reply to James MorrisFrom: Eric Paris <[email protected]>
Add a new security check on mmap operations to see if the user is attempting to mmap to low area of the address space. The amount of space protected is indicated by the new proc tunable /proc/sys/vm/mmap_min_addr and defaults to 0, preserving existing behavior.
This patch uses a new SELinux security class "memprotect." Policy already contains a number of allow rules like a_t self:process * (unconfined_t being one of them) which mean that putting this check in the process class (its best current fit) would make it useless as all user processes, which we also want to protect against, would be allowed. By taking the memprotect name of the new class it will also make it possible for us to move some of the other memory protect permissions out of 'process' and into the new class next time we bump the policy version number (which I also think is a good future idea)
--- Documentation/sysctl/vm.txt | 15 +++++++++++++++ include/linux/security.h | 17 ++++++++++++----- kernel/sysctl.c | 10 ++++++++++ mm/mmap.c | 4 ++-- mm/mremap.c | 13 +++++++++++-- mm/nommu.c | 2 +- security/dummy.c | 6 +++++- security/security.c | 2 ++ security/selinux/hooks.c | 12 ++++++++---- security/selinux/include/av_perm_to_string.h | 1 + security/selinux/include/av_permissions.h | 1 + security/selinux/include/class_to_string.h | 1 + security/selinux/include/flask.h | 1 + 13 files changed, 70 insertions(+), 15 deletions(-)
Documentation/sysctl/vm.txt +15 -0
@@ -31,6 +31,7 @@ Currently, these files are in /proc/sys/vm: - min_unmapped_ratio - min_slab_ratio - panic_on_oom +- mmap_min_address ==============================================================
@@ -216,3 +217,17 @@ above-mentioned. The default value is 0. 1 and 2 are for failover of clustering. Please select either according to your policy of failover. + +============================================================== + +mmap_min_addr + +This file indicates the amount of address space which a user process will +be restricted from mmaping. Since kernel null dereference bugs could +accidentally operate based on the information in the first couple of pages +of memory userspace processes should not be allowed to write to them. By +default this value is set to 0 and no protections will be enforced by the +security module. Setting this value to something like 64k will allow the +vast majority of applications to work correctly and provide defense in depth +against future potential kernel bugs. +
include/linux/security.h +12 -5
@@ -71,6 +71,7 @@ struct xfrm_user_sec_ctx;extern int cap_netlink_send (struct sock *sk,struct sk_buff *skb);extern int cap_netlink_recv (struct sk_buff *skb,int cap); +extern unsigned long mmap_min_addr;/* * Values used in the task_security_ops calls */
@@ -1241,8 +1242,9 @@ struct security_operations {int (*file_ioctl) (struct file * file,unsigned int cmd,unsigned long arg);int (*file_mmap) (struct file * file, -unsigned long reqprot, -unsigned long prot,unsigned long flags); +unsigned long reqprot,unsigned long prot, +unsigned long flags,unsigned long addr, +unsigned long addr_only);int (*file_mprotect) (struct vm_area_struct * vma,unsigned long reqprot,unsigned long prot);
@@ -1814,9 +1816,12 @@ static inline int security_file_ioctl (struct file *file, unsigned int cmd,static inline int security_file_mmap (struct file *file,unsigned long reqprot,unsigned long prot, -unsigned long flags) +unsigned long flags, +unsigned long addr, +unsigned long addr_only) { -return security_ops->file_mmap (file, reqprot, prot, flags); +return security_ops->file_mmap (file, reqprot, prot, flags, addr, + addr_only); } static inline int security_file_mprotect (struct vm_area_struct *vma,
@@ -2489,7 +2494,9 @@ static inline int security_file_ioctl (struct file *file, unsigned int cmd,static inline int security_file_mmap (struct file *file,unsigned long reqprot,unsigned long prot, -unsigned long flags) +unsigned long flags, +unsigned long addr, +unsigned long addr_only) {return 0 ; }
kernel/sysctl.c +10 -0
@@ -869,6 +869,16 @@ static ctl_table vm_table[] = { .strategy = &sysctl_jiffies, },#endif +#ifdef CONFIG_SECURITY + { + .ctl_name = CTL_UNNUMBERED, + .procname = "mmap_min_addr", + .data = &mmap_min_addr, + .maxlen = sizeof(unsigned long), + .mode = 0644, + .proc_handler = &proc_doulongvec_minmax, + }, +#endif #if defined(CONFIG_X86_32) || \ (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) {
mm/mmap.c +2 -2
@@ -1023,10 +1023,10 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, } } - error =security_file_mmap (file, reqprot, prot, flags); + error =security_file_mmap (file, reqprot, prot, flags, addr,0 );if (error)return error; - +/* Clear old maps */ error = -ENOMEM ; munmap_back:
mm/mremap.c +11 -2
@@ -291,6 +291,10 @@ unsigned long do_mremap(unsigned long addr,if ((addr <= new_addr) && (addr+old_len) > new_addr) goto out; + ret =security_file_mmap (0 ,0 ,0 ,0 , new_addr,1 ); +if (ret) + goto out; + ret =do_munmap (mm, new_addr, new_len);if (ret) goto out;
@@ -390,8 +394,13 @@ unsigned long do_mremap(unsigned long addr, new_addr =get_unmapped_area (vma->vm_file,0 , new_len, vma->vm_pgoff, map_flags); - ret = new_addr; -if (new_addr & ~PAGE_MASK ) +if (new_addr & ~PAGE_MASK ) { + ret = new_addr; + goto out; + } + + ret =security_file_mmap (0 ,0 ,0 ,0 , new_addr,1 ); +if (ret) goto out; } ret =move_vma (vma, addr, old_len, new_len, new_addr);
mm/nommu.c +1 -1
@@ -639,7 +639,7 @@ static int validate_mmap_request(struct file *file, }/* allow the security API to have its say */ - ret =security_file_mmap (file, reqprot, prot, flags); + ret =security_file_mmap (file, reqprot, prot, flags, addr,0 );if (ret <0 )return ret;
security/dummy.c +5 -1
@@ -420,8 +420,12 @@ static int dummy_file_ioctl (struct file *file, unsigned int command,static int dummy_file_mmap (struct file *file,unsigned long reqprot,unsigned long prot, -unsigned long flags) +unsigned long flags, +unsigned long addr, +unsigned long addr_only) { +if (addr < mmap_min_addr) +return -EACCES ;return 0 ; }
security/security.c +2 -0
@@ -24,6 +24,7 @@ extern struct security_operations dummy_security_ops;extern void security_fixup_ops (struct security_operations *ops);struct security_operations *security_ops;/* Initialized to NULL */ +unsigned long mmap_min_addr;/* 0 means no protection */ static inline int verify (struct security_operations *ops) {
@@ -176,4 +177,5 @@ EXPORT_SYMBOL_GPL(register_security);EXPORT_SYMBOL_GPL (unregister_security);EXPORT_SYMBOL_GPL (mod_reg_security);EXPORT_SYMBOL_GPL (mod_unreg_security); +EXPORT_SYMBOL_GPL (mmap_min_addr);EXPORT_SYMBOL (security_ops);
security/selinux/hooks.c +8 -4
@@ -2569,12 +2569,16 @@ static int file_map_prot_check(struct file *file, unsigned long prot, int shared }static int selinux_file_mmap (struct file *file,unsigned long reqprot, -unsigned long prot,unsigned long flags) +unsigned long prot,unsigned long flags, +unsigned long addr,unsigned long addr_only) { -int rc; +int rc =0 ; +u32 sid = ((struct task_security_struct *)(current->security))->sid; - rc = secondary_ops->file_mmap (file, reqprot, prot, flags); -if (rc) +if (addr < mmap_min_addr) + rc =avc_has_perm (sid, sid,SECCLASS_MEMPROTECT , +MEMPROTECT__MMAP_ZERO ,NULL ); +if (rc || addr_only)return rc;if (selinux_checkreqprot)
security/selinux/include/av_perm_to_string.h +1 -0
@@ -158,3 +158,4 @@ S_(SECCLASS_KEY, KEY__CREATE, "create") S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NODE_BIND, "node_bind") S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NAME_CONNECT, "name_connect") +S_ (SECCLASS_MEMPROTECT ,MEMPROTECT__MMAP_ZERO ,"mmap_zero" )
security/selinux/include/av_permissions.h +1 -0
@@ -823,3 +823,4 @@#define DCCP_SOCKET__NAME_BIND 0x00200000UL#define DCCP_SOCKET__NODE_BIND 0x00400000UL#define DCCP_SOCKET__NAME_CONNECT 0x00800000UL +#define MEMPROTECT__MMAP_ZERO 0x00000001UL
security/selinux/include/class_to_string.h +1 -0
@@ -63,3 +63,4 @@ S_("key") S_(NULL) S_("dccp_socket") +S_ ("memprotect" )
security/selinux/include/flask.h +1 -0
@@ -49,6 +49,7 @@#define SECCLASS_PACKET 57#define SECCLASS_KEY 58#define SECCLASS_DCCP_SOCKET 60 +#define SECCLASS_MEMPROTECT 61/* * Security identifier indices for initial entities
Signature · 1 line
1.5.0.6
Re: [PATCH 09/11] security: Protection for exploiting null dereference using mmap
Quoted 4 lines · James Morris
security/dummy.c +0
-0@@ -420,8 +420,12 @@ static int dummy_file_ioctl (struct file *file, unsigned int command, static int dummy_file_mmap (struct file *file, unsigned long reqprot, unsigned long prot,
security/dummy.c static int dummy_file_ioctl (struct file *file, unsigned int command, · line 431
Quoted 10 lines
security/dummy.c +5
-1- unsigned long flags) +unsigned long flags, + unsigned long addr, + unsigned long addr_only) { + if (addr < mmap_min_addr) + return -EACCES;return 0 ; }
Not -EPERM?
Jan
James Morris
maintainerRe: [PATCH 09/11] security: Protection for exploiting null dereference using mmap
Quoted 4 lines · Jan Engelhardt
Quoted 2 lines · James Morris
(quoted diff) +0
-0@@ -420,8 +420,12 @@ static int dummy_file_ioctl (struct file *file, unsigned int command,
Quoted 14 lines
security/dummy.c static int dummy_file_ioctl (struct file *file, unsigned int command, · line 431
Quoted 12 lines
security/dummy.c +5
-1static int dummy_file_mmap (struct file *file,unsigned long reqprot,unsigned long prot, -unsigned long flags) +unsigned long flags, +unsigned long addr, +unsigned long addr_only) { +if (addr < mmap_min_addr) +return -EACCES ;return 0 ; }Not
-EPERM?
No, EACCES is what's used.
Signature · 2 lines
James Morris <[email protected]>
James Morris
maintainerPATCH 10/11 SELinux: use SECINITSID_NETMSG instead of SECINITSID_UNLABELED for NetLabel
In reply to James MorrisFrom: Paul Moore <[email protected]>
These changes will make NetLabel behave like labeled IPsec where there is an access check for both labeled and unlabeled packets as well as providing the ability to restrict domains to receiving only labeled packets when NetLabel is in use. The changes to the policy are straight forward with the following necessary to receive labeled traffic (with SECINITSID_NETMSG defined as "netlabel_peer_t"):
allow mydom_t netlabel_peer_t:{ tcp_socket udp_socket rawip_socket } recvfrom;
The policy for unlabeled traffic would be:
allow mydom_t unlabeled_t:{ tcp_socket udp_socket rawip_socket } recvfrom;
These policy changes, as well as more general NetLabel support, are included in the SELinux Reference Policy SVN tree, r2352 or later. Users who enable NetLabel support in the kernel are strongly encouraged to upgrade their policy to avoid network problems.
--- security/selinux/hooks.c | 21 +++++++++++---------- security/selinux/netlabel.c | 34 +++++++++++++--------------------- 2 files changed, 24 insertions(+), 31 deletions(-)
security/selinux/hooks.c +11 -10
@@ -3129,17 +3129,19 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,/** * selinux_skb_extlbl_sid - Determine the external label of a packet * @skb: the packet -* @base_sid: the SELinux SID to use as a context for MLS only external labels * @sid: the packet's SID * * Description: * Check the various different forms of external packet labeling and determine -* the external SID for the packet. +* the external SID for the packet. If only one form of external labeling is +* present then it is used, if both labeled IPsec and NetLabel labels are +* present then the SELinux type information is taken from the labeled IPsec +* SA and the MLS sensitivity label information is taken from the NetLabel +* security attributes. This bit of "magic" is done in the call to +* selinux_netlbl_skbuff_getsid(). * */ -static void selinux_skb_extlbl_sid (struct sk_buff *skb, -u32 base_sid, -u32 *sid) +static void selinux_skb_extlbl_sid (struct sk_buff *skb,u32 *sid) {u32 xfrm_sid;u32 nlbl_sid;
@@ -3147,10 +3149,9 @@ static void selinux_skb_extlbl_sid(struct sk_buff *skb,selinux_skb_xfrm_sid (skb, &xfrm_sid);if (selinux_netlbl_skbuff_getsid (skb, (xfrm_sid ==SECSID_NULL ? - base_sid : xfrm_sid), +SECINITSID_NETMSG : xfrm_sid), &nlbl_sid) !=0 ) nlbl_sid =SECSID_NULL ; - *sid = (nlbl_sid ==SECSID_NULL ? xfrm_sid : nlbl_sid); }
@@ -3695,7 +3696,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *if (sock && sock->sk->sk_family ==PF_UNIX )selinux_get_inode_sid (SOCK_INODE (sock), &peer_secid);else if (skb) -selinux_skb_extlbl_sid (skb,SECINITSID_UNLABELED , &peer_secid); +selinux_skb_extlbl_sid (skb, &peer_secid);if (peer_secid ==SECSID_NULL ) err = -EINVAL ;
@@ -3756,7 +3757,7 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,u32 newsid;u32 peersid; -selinux_skb_extlbl_sid (skb,SECINITSID_UNLABELED , &peersid); +selinux_skb_extlbl_sid (skb, &peersid);if (peersid ==SECSID_NULL ) { req->secid = sksec->sid; req->peer_secid =SECSID_NULL ;
@@ -3794,7 +3795,7 @@ static void selinux_inet_conn_established(struct sock *sk, {struct sk_security_struct *sksec = sk->sk_security; -selinux_skb_extlbl_sid (skb,SECINITSID_UNLABELED , &sksec->peer_sid); +selinux_skb_extlbl_sid (skb, &sksec->peer_sid); } static void selinux_req_classify_flow(const struct request_sock *req,
security/selinux/netlabel.c +13 -21
@@ -158,9 +158,7 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb, u32 base_sid, u32 *sid)netlbl_secattr_init (&secattr); rc =netlbl_skbuff_getattr (skb, &secattr);if (rc ==0 && secattr.flags !=NETLBL_SECATTR_NONE ) - rc =security_netlbl_secattr_to_sid (&secattr, - base_sid, - sid); + rc =security_netlbl_secattr_to_sid (&secattr, base_sid, sid);else *sid =SECSID_NULL ;netlbl_secattr_destroy (&secattr);
@@ -198,7 +196,7 @@ void selinux_netlbl_sock_graft(struct sock *sk, struct socket *sock)if (netlbl_sock_getattr (sk, &secattr) ==0 && secattr.flags !=NETLBL_SECATTR_NONE &&security_netlbl_secattr_to_sid (&secattr, -SECINITSID_UNLABELED , +SECINITSID_NETMSG , &nlbl_peer_sid) ==0 ) sksec->peer_sid = nlbl_peer_sid;netlbl_secattr_destroy (&secattr);
@@ -295,38 +293,32 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec, struct avc_audit_data *ad) {int rc; -u32 netlbl_sid; -u32 recv_perm; +u32 nlbl_sid; +u32 perm; - rc =selinux_netlbl_skbuff_getsid (skb, -SECINITSID_UNLABELED , - &netlbl_sid); + rc =selinux_netlbl_skbuff_getsid (skb,SECINITSID_NETMSG , &nlbl_sid);if (rc !=0 )return rc; - -if (netlbl_sid ==SECSID_NULL ) -return 0 ; +if (nlbl_sid ==SECSID_NULL ) + nlbl_sid =SECINITSID_UNLABELED ;switch (sksec->sclass) {case SECCLASS_UDP_SOCKET : - recv_perm =UDP_SOCKET__RECVFROM ; + perm =UDP_SOCKET__RECVFROM ;break ;case SECCLASS_TCP_SOCKET : - recv_perm =TCP_SOCKET__RECVFROM ; + perm =TCP_SOCKET__RECVFROM ;break ;default : - recv_perm =RAWIP_SOCKET__RECVFROM ; + perm =RAWIP_SOCKET__RECVFROM ; } - rc =avc_has_perm (sksec->sid, - netlbl_sid, - sksec->sclass, - recv_perm, - ad); + rc =avc_has_perm (sksec->sid, nlbl_sid, sksec->sclass, perm, ad);if (rc ==0 )return 0 ; -netlbl_skbuff_err (skb, rc); +if (nlbl_sid !=SECINITSID_UNLABELED ) +netlbl_skbuff_err (skb, rc);return rc; }
Signature · 1 line
1.5.0.6
James Morris
maintainerPATCH 11/11 security: unexport mmap_min_addr
In reply to James MorrisFrom: Adrian Bunk <[email protected]>
Remove unneeded export.
--- security/security.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
security/security.c +0 -1
@@ -177,5 +177,4 @@ EXPORT_SYMBOL_GPL(register_security);EXPORT_SYMBOL_GPL (unregister_security);EXPORT_SYMBOL_GPL (mod_reg_security);EXPORT_SYMBOL_GPL (mod_unreg_security); -EXPORT_SYMBOL_GPL (mmap_min_addr);EXPORT_SYMBOL (security_ops);
Signature · 1 line
1.5.0.6