selinux: dynamic class/perm discovery
PATCH v4 1/2 selinux: dynamic class/perm discovery
Modify SELinux to dynamically discover class and permission values upon policy load, based on the dynamic object class/perm discovery logic from libselinux. A mapping is created between kernel-private class and permission indices used outside the security server and the policy values used within the security server.
The mappings are only applied upon kernel-internal computations; similar mappings for the private indices of userspace object managers is handled on a per-object manager basis by the userspace AVC. The interfaces for compute_av and transition_sid are split for kernel vs. userspace; the userspace functions are distinguished by a _user suffix.
The kernel-private class indices are no longer tied to the policy values and thus do not need to skip indices for userspace classes; thus the kernel class index values are compressed. The flask.h definitions were regenerated by deleting the userspace classes from refpolicy's definitions and then regenerating the headers. Going forward, we can just maintain the flask.h, av_permissions.h, and classmap.h definitions separately from policy as they are no longer tied to the policy values. The next patch introduces a utility to automate generation of flask.h and av_permissions.h from the classmap.h definitions.
The older kernel class and permission string tables are removed and replaced by a single security class mapping table that is walked at policy load to generate the mapping. The old kernel class validation logic is completely replaced by the mapping logic.
The handle unknown logic is reworked. reject_unknown=1 is handled when the mappings are computed at policy load time, similar to the old handling by the class validation logic. allow_unknown=1 is handled when computing and mapping decisions - if the permission was not able to be mapped (i.e. undefined, mapped to zero), then it is automatically added to the allowed vector. If the class was not able to be mapped (i.e. undefined, mapped to zero), then all permissions are allowed for it if allow_unknown=1.
avc_audit leverages the new security class mapping table to lookup the class and permission names from the kernel-private indices.
The mdp program is updated to use the new table when generating the class definitions and allow rules for a minimal boot policy for the kernel. It should be noted that this policy will not include any userspace classes, nor will its policy index values for the kernel classes correspond with the ones in refpolicy (they will instead match the kernel-private indices).
---
This is a re-base against 2.6.32-rc1 to address conflicts with a trivial cleanup of mdp.c upstream. Also folds all mdp.c changes into this patch, where they belong logically.
scripts/selinux/mdp/mdp.c | 153 ++----- security/selinux/avc.c | 76 +--- security/selinux/include/av_inherit.h | 34 -- security/selinux/include/av_perm_to_string.h | 183 -------- security/selinux/include/av_permissions.h | 44 +- security/selinux/include/avc_ss.h | 21 +- security/selinux/include/class_to_string.h | 80 ---- security/selinux/include/classmap.h | 155 +++++++ security/selinux/include/common_perm_to_string.h | 58 --- security/selinux/include/flask.h | 40 +- security/selinux/include/security.h | 13 +- security/selinux/selinuxfs.c | 4 +- security/selinux/ss/policydb.c | 1 - security/selinux/ss/policydb.h | 1 - security/selinux/ss/services.c | 538 ++++++++++++--------- 15 files changed, 557 insertions(+), 844 deletions(-) delete mode 100644 security/selinux/include/av_inherit.h delete mode 100644 security/selinux/include/av_perm_to_string.h delete mode 100644 security/selinux/include/class_to_string.h create mode 100644 security/selinux/include/classmap.h delete mode 100644 security/selinux/include/common_perm_to_string.h
scripts/selinux/mdp/mdp.c +29 -124
@@ -29,86 +29,27 @@#include <unistd.h> #include <string.h> -#include "flask.h" -static void usage (char *name) {printf ("usage: %s [-m] policy_file context_file\n" , name);exit (1 ); } -static void find_common_name (char *cname,char *dest,int len) -{ -char *start, *end; - - start =strchr (cname,'_' )+1 ; - end =strchr (start,'_' ); -if (!start || !end || start-cname > len || end-start > len) { -printf ("Error with commons defines\n" ); -exit (1 ); - } -strncpy (dest, start, end-start); - dest[end-start] ='\0' ; -} - -#define S_ (x) x, -static char *classlist[] = { -#include "class_to_string.h" -NULL +/* Class/perm mapping support */ +struct security_class_mapping { +const char *name; +const char *perms[sizeof (unsigned ) *8 +1 ]; }; -#undef S_ - + +#include "classmap.h" #include "initial_sid_to_string.h" -#define TB_ (x) char *x[] = { -#define TE_ (x) NULL }; -#define S_ (x) x, -#include "common_perm_to_string.h" -#undef TB_ -#undef TE_ -#undef S_ - -struct common { -char *cname; -char **perms; -}; -struct common common[] = { -#define TB_(x) { #x, x }, -#define S_(x) -#define TE_ (x) -#include "common_perm_to_string.h" -#undef TB_ -#undef TE_ -#undef S_ -}; - -#define S_ (x, y, z) {x, #y}, -struct av_inherit { -int class; -char *common; -}; -struct av_inherit av_inherit[] = { -#include "av_inherit.h" -}; -#undef S_ - -#include "av_permissions.h" -#define S_ (x, y, z) {x, y, z}, -struct av_perms { -int class; -int perm_i; -char *perm_s; -}; -struct av_perms av_perms[] = { -#include "av_perm_to_string.h" -}; -#undef S_ -int main (int argc,char *argv[]) {int i, j, mls =0 ; +int initial_sid_to_string_len;char **arg, *polout, *ctxout; -int classlist_len, initial_sid_to_string_len; +FILE *fout;if (argc <3 )
@@ -127,64 +68,25 @@ int main(int argc, char *argv[])usage (argv[0 ]); } - classlist_len =sizeof (classlist) /sizeof (char *);/* print out the classes */ -for (i=1 ; i < classlist_len; i++) { -if (classlist[i]) -fprintf (fout,"class %s\n" , classlist[i]); -else -fprintf (fout,"class user%d\n" , i); - } +for (i =0 ; secclass_map[i].name; i++) +fprintf (fout,"class %s\n" , secclass_map[i].name);fprintf (fout,"\n" ); initial_sid_to_string_len =sizeof (initial_sid_to_string) /sizeof (char *);/* print out the sids */ -for (i=1 ; i < initial_sid_to_string_len; i++) +for (i =1 ; i < initial_sid_to_string_len; i++)fprintf (fout,"sid %s\n" , initial_sid_to_string[i]);fprintf (fout,"\n" ); -/* print out the commons */ -for (i=0 ; i<sizeof (common)/sizeof (struct common ); i++) { -char cname[101 ]; -find_common_name (common[i].cname, cname,100 ); - cname[100 ] ='\0' ; -fprintf (fout,"common %s\n{\n" , cname); -for (j=0 ; common[i].perms[j]; j++) -fprintf (fout,"\t%s\n" , common[i].perms[j]); -fprintf (fout,"}\n\n" ); - } -fprintf (fout,"\n" ); -/* print out the class permissions */ -for (i=1 ; i < classlist_len; i++) { -if (classlist[i]) { -int firstperm =-1 , numperms =0 ; - -fprintf (fout,"class %s\n" , classlist[i]); -/* does it inherit from a common? */ -for (j=0 ; j <sizeof (av_inherit)/sizeof (struct av_inherit ); j++) -if (av_inherit[j].class == i) -fprintf (fout,"inherits %s\n" , av_inherit[j].common); - -for (j=0 ; j <sizeof (av_perms)/sizeof (struct av_perms ); j++) { -if (av_perms[j].class == i) { -if (firstperm ==-1 ) - firstperm = j; - numperms++; - } - } -if (!numperms) { -fprintf (fout,"\n" ); -continue ; - } - -fprintf (fout,"{\n" ); -/* print out the av_perms */ -for (j=0 ; j < numperms; j++) { -fprintf (fout,"\t%s\n" , av_perms[firstperm+j].perm_s); - } -fprintf (fout,"}\n\n" ); - } +for (i =0 ; secclass_map[i].name; i++) { +struct security_class_mapping *map = &secclass_map[i]; +fprintf (fout,"class %s\n" , map->name); +fprintf (fout,"{\n" ); +for (j =0 ; map->perms[j]; j++) +fprintf (fout,"\t%s\n" , map->perms[j]); +fprintf (fout,"}\n\n" ); }fprintf (fout,"\n" );
@@ -197,31 +99,34 @@ int main(int argc, char *argv[])/* types, roles, and allows */ fprintf (fout,"type base_t;\n" );fprintf (fout,"role base_r types { base_t };\n" ); -for (i=1 ; i < classlist_len; i++) { -if (classlist[i]) -fprintf (fout,"allow base_t base_t:%s *;\n" , classlist[i]); -else -fprintf (fout,"allow base_t base_t:user%d *;\n" , i); - } +for (i =0 ; secclass_map[i].name; i++) +fprintf (fout,"allow base_t base_t:%s *;\n" , + secclass_map[i].name);fprintf (fout,"user user_u roles { base_r };\n" );fprintf (fout,"\n" );/* default sids */ -for (i=1 ; i < initial_sid_to_string_len; i++) +for (i =1 ; i < initial_sid_to_string_len; i++)fprintf (fout,"sid %s user_u:base_r:base_t\n" , initial_sid_to_string[i]);fprintf (fout,"\n" ); -fprintf (fout,"fs_use_xattr ext2 user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_xattr ext3 user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_xattr ext4 user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_xattr jfs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_xattr xfs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_xattr reiserfs user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_xattr jffs2 user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_xattr gfs2 user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_xattr lustre user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_task eventpollfs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_task pipefs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_task sockfs user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_trans mqueue user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_trans devpts user_u:base_r:base_t;\n" ); +fprintf (fout,"fs_use_trans hugetlbfs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_trans tmpfs user_u:base_r:base_t;\n" );fprintf (fout,"fs_use_trans shm user_u:base_r:base_t;\n" );
security/selinux/avc.c +8 -68
111 lines not on this page · raw message
security/selinux/include/av_inherit.h deleted +0 -34
@@ -1,34 +0,0 @@ -/* This file is automatically generated. Do not edit. */ - S_(SECCLASS_DIR, file, 0x00020000UL) - S_(SECCLASS_FILE, file, 0x00020000UL) - S_(SECCLASS_LNK_FILE, file, 0x00020000UL) - S_(SECCLASS_CHR_FILE, file, 0x00020000UL) - S_(SECCLASS_BLK_FILE, file, 0x00020000UL) - S_(SECCLASS_SOCK_FILE, file, 0x00020000UL) - S_(SECCLASS_FIFO_FILE, file, 0x00020000UL) - S_(SECCLASS_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_TCP_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_UDP_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_RAWIP_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_PACKET_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_KEY_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_UNIX_STREAM_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_UNIX_DGRAM_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_TUN_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_IPC, ipc, 0x00000200UL) - S_(SECCLASS_SEM, ipc, 0x00000200UL) - S_(SECCLASS_MSGQ, ipc, 0x00000200UL) - S_(SECCLASS_SHM, ipc, 0x00000200UL) - S_(SECCLASS_NETLINK_ROUTE_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_FIREWALL_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_TCPDIAG_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_NFLOG_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_XFRM_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_SELINUX_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_AUDIT_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_IP6FW_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_DNRT_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET, socket, 0x00400000UL) - S_(SECCLASS_APPLETALK_SOCKET, socket, 0x00400000UL) -S_ (SECCLASS_DCCP_SOCKET , socket,0x00400000UL )
security/selinux/include/av_perm_to_string.h deleted +0 -183
183 lines not on this page · raw message
security/selinux/include/av_permissions.h +22 -22
53 lines not on this page · raw message
security/selinux/include/avc_ss.h +4 -17
@@ -10,26 +10,13 @@int avc_ss_reset (u32 seqno); -struct av_perm_to_string { -u16 tclass; -u32 value; +/* Class/perm mapping support */ +struct security_class_mapping {const char *name; +const char *perms[sizeof (u32) *8 +1 ]; }; -struct av_inherit { -const char **common_pts; -u32 common_base; -u16 tclass; -}; - -struct selinux_class_perm { -const struct av_perm_to_string *av_perm_to_string; -u32 av_pts_len; -u32 cts_len; -const char **class_to_string; -const struct av_inherit *av_inherit; -u32 av_inherit_len; -}; +extern struct security_class_mapping secclass_map[];#endif /* _SELINUX_AVC_SS_H_ */
security/selinux/include/class_to_string.h deleted +0 -80
80 lines not on this page · raw message
security/selinux/include/classmap.h new file +155 -0
155 lines not on this page · raw message
security/selinux/include/common_perm_to_string.h deleted +0 -58
58 lines not on this page · raw message
security/selinux/include/flask.h +20 -20
@@ -34,26 +34,26 @@#define SECCLASS_MSGQ 27#define SECCLASS_SHM 28#define SECCLASS_IPC 29 -#define SECCLASS_NETLINK_ROUTE_SOCKET 43 -#define SECCLASS_NETLINK_FIREWALL_SOCKET 44 -#define SECCLASS_NETLINK_TCPDIAG_SOCKET 45 -#define SECCLASS_NETLINK_NFLOG_SOCKET 46 -#define SECCLASS_NETLINK_XFRM_SOCKET 47 -#define SECCLASS_NETLINK_SELINUX_SOCKET 48 -#define SECCLASS_NETLINK_AUDIT_SOCKET 49 -#define SECCLASS_NETLINK_IP6FW_SOCKET 50 -#define SECCLASS_NETLINK_DNRT_SOCKET 51 -#define SECCLASS_ASSOCIATION 54 -#define SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET 55 -#define SECCLASS_APPLETALK_SOCKET 56 -#define SECCLASS_PACKET 57 -#define SECCLASS_KEY 58 -#define SECCLASS_DCCP_SOCKET 60 -#define SECCLASS_MEMPROTECT 61 -#define SECCLASS_PEER 68 -#define SECCLASS_CAPABILITY2 69 -#define SECCLASS_KERNEL_SERVICE 74 -#define SECCLASS_TUN_SOCKET 75 +#define SECCLASS_NETLINK_ROUTE_SOCKET 30 +#define SECCLASS_NETLINK_FIREWALL_SOCKET 31 +#define SECCLASS_NETLINK_TCPDIAG_SOCKET 32 +#define SECCLASS_NETLINK_NFLOG_SOCKET 33 +#define SECCLASS_NETLINK_XFRM_SOCKET 34 +#define SECCLASS_NETLINK_SELINUX_SOCKET 35 +#define SECCLASS_NETLINK_AUDIT_SOCKET 36 +#define SECCLASS_NETLINK_IP6FW_SOCKET 37 +#define SECCLASS_NETLINK_DNRT_SOCKET 38 +#define SECCLASS_ASSOCIATION 39 +#define SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET 40 +#define SECCLASS_APPLETALK_SOCKET 41 +#define SECCLASS_PACKET 42 +#define SECCLASS_KEY 43 +#define SECCLASS_DCCP_SOCKET 44 +#define SECCLASS_MEMPROTECT 45 +#define SECCLASS_PEER 46 +#define SECCLASS_CAPABILITY2 47 +#define SECCLASS_KERNEL_SERVICE 48 +#define SECCLASS_TUN_SOCKET 49/* * Security identifier indices for initial entities
security/selinux/include/security.h +10 -3
@@ -97,11 +97,18 @@ struct av_decision {#define AVD_FLAGS_PERMISSIVE 0x0001int security_compute_av (u32 ssid,u32 tsid, -u16 tclass,u32 requested, -struct av_decision *avd); +u16 tclass,u32 requested, +struct av_decision *avd); + +int security_compute_av_user (u32 ssid,u32 tsid, +u16 tclass,u32 requested, +struct av_decision *avd);int security_transition_sid (u32 ssid,u32 tsid, -u16 tclass,u32 *out_sid); +u16 tclass,u32 *out_sid); + +int security_transition_sid_user (u32 ssid,u32 tsid, +u16 tclass,u32 *out_sid);int security_member_sid (u32 ssid,u32 tsid,u16 tclass,u32 *out_sid);
security/selinux/selinuxfs.c +2 -2
@@ -522,7 +522,7 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_compute_av (ssid, tsid, tclass, req, &avd); + length =security_compute_av_user (ssid, tsid, tclass, req, &avd);if (length <0 ) goto out2;
@@ -571,7 +571,7 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)if (length <0 ) goto out2; - length =security_transition_sid (ssid, tsid, tclass, &newsid); + length =security_transition_sid_user (ssid, tsid, tclass, &newsid);if (length <0 ) goto out2;
security/selinux/ss/policydb.c +0 -1
@@ -713,7 +713,6 @@ void policydb_destroy(struct policydb *p)ebitmap_destroy (&p->type_attr_map[i]); }kfree (p->type_attr_map); -kfree (p->undefined_perms);ebitmap_destroy (&p->policycaps);ebitmap_destroy (&p->permissive_map);
security/selinux/ss/policydb.h +0 -1
@@ -254,7 +254,6 @@ struct policydb { unsigned int reject_unknown : 1; unsigned int allow_unknown : 1; -u32 *undefined_perms; };extern void policydb_destroy (struct policydb *p);
security/selinux/ss/services.c +307 -231
689 lines not on this page · raw message
Signature · 12 lines
1.6.2.5 -- Stephen Smalley National Security Agency -- 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.
PATCH v4 2/2 selinux: generate flask headers during kernel build
Add a simple utility (scripts/selinux/genheaders) and invoke it to generate the kernel-private class and permission indices in flask.h and av_permissions.h automatically during the kernel build from the security class mapping definitions in classmap.h. Adding new kernel classes and permissions can then be done just by adding them to classmap.h.
--- scripts/selinux/Makefile | 4 +- scripts/selinux/genheaders/Makefile | 5 + scripts/selinux/genheaders/genheaders.c | 118 ++++ security/selinux/Makefile | 10 +- security/selinux/include/av_permissions.h | 870 ----------------------------- security/selinux/include/flask.h | 91 --- security/selinux/ss/Makefile | 2 +- 7 files changed, 135 insertions(+), 965 deletions(-) create mode 100644 scripts/selinux/genheaders/Makefile create mode 100644 scripts/selinux/genheaders/genheaders.c delete mode 100644 security/selinux/include/av_permissions.h delete mode 100644 security/selinux/include/flask.h
scripts/selinux/Makefile +2 -2
@@ -1,2 +1,2 @@ -subdir-y := mdp -subdir- += mdp +subdir-y := mdp genheaders +subdir- += mdp genheaders
scripts/selinux/genheaders/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +hostprogs-y := genheaders +HOST_EXTRACFLAGS += -Isecurity/selinux/include + +always := $(hostprogs-y) +clean-files := $(hostprogs-y)
scripts/selinux/genheaders/genheaders.c new file +118 -0
118 lines not on this page · raw message
security/selinux/Makefile +9 -1
@@ -18,5 +18,13 @@ selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o selinux-$(CONFIG_NETLABEL) += netlabel.o -EXTRA_CFLAGS += -Isecurity/selinux/include +EXTRA_CFLAGS += -Isecurity/selinux -Isecurity/selinux/include +$(obj)/avc.o: $(obj)/flask.h + +quiet_cmd_flask = GEN $(obj)/flask.h $(obj)/av_permissions.h + cmd_flask = scripts/selinux/genheaders/genheaders $(obj)/flask.h $(obj)/av_permissions.h + +targets += flask.h +$(obj)/flask.h: $(src)/include/classmap.h FORCE + $(call if_changed,flask)
security/selinux/include/av_permissions.h deleted +0 -870
870 lines not on this page · raw message
security/selinux/include/flask.h deleted +0 -91
91 lines not on this page · raw message
security/selinux/ss/Makefile +1 -1
@@ -2,7 +2,7 @@ # Makefile for building the SELinux security server as part of the kernel tree. # -EXTRA_CFLAGS += -Isecurity/selinux/include +EXTRA_CFLAGS += -Isecurity/selinux -Isecurity/selinux/include obj-y := ss.o ss-y := ebitmap.o hashtab.o symtab.o sidtab.o avtab.o policydb.o services.o conditional.o mls.o
Signature · 12 lines
1.6.2.5 -- Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 5 lines · Stephen Smalley
Add a simple utility (
scripts/selinux/genheaders) and invoke it to generate the kernel-private class and permission indices inflask.handav_permissions.hautomatically during the kernel build from the security class mapping definitions inclassmap.h. Adding new kernel classes and permissions can then be done just by adding them toclassmap.h.
I've run the ltp selinux testsuite before and after these patches and confirmed no regressions in denying system calls (i.e. no FAILs) or in generated AVC messages (by clearing the audit log and restarting auditd before each run, then running ausearch -m AVC -ts today | audit2allow afterward and comparing the generated allow rules - cannot compare the raw audit messages since they have data that changes on each run, e.g. pid, ino, ...).
Looks like these patches are linux-next material though since the merge window has closed for 2.6.32.
Eric, with these patches applied, to add a new permission (e.g. for access) to the kernel, you would add it to security/selinux/include/classmap.h, and then separately add it to the refpolicy access vector definitions. No requirement for the two definitions to line up in terms of index value since they will get mapped based on string name. You could even add the new permission to COMMON_FILE_PERMS, and the rest of the per-class file permissions will just get remapped appropriately. On the policy side though, you don't want to modify the common file permissions definition because that will affect older kernels that predate this dynamic class/perm discovery support. But there is no need for COMMON_FILE_PERMS to line up with the common file perms in the policy, which means we can in fact continue to use common file perms as a convenient way to avoid a switch statement or array for mapping classes to permissions in the hook functions.
One caveat is that we still need to ensure that COMMON_FILE_PERMS and COMMON_SOCK_PERMS continue to line up with each other in the set of permissions used by file hooks that can act on either files or sockets, unless we change those hooks to select the specific permission based on the class. The permissions that are shared by file and socket classes are the ones up through "append"; after that they diverge.
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's classmap.h definitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them from classmap.h.
The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket { recv_msg send_msg }
# Only added so that subsequent permissions (execmod) would get the same value as class file chr_file { execute_no_trans entrypoint }
# Original socket controls; never merged to mainlinetcp_socket { connectto newconn acceptfrom }
# legacy network or compat_net=1 checks
node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send }
# legacy network or compat_net=1 checks
netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send }
# Original socket controls; never merged to mainline - only connectto is used
unix_stream_socket { newconn acceptfrom }
# Patches merged prematurely by Fedora, never merged to mainline
packet { flow_in flow_out }Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 57 lines · Stephen Smalley
Quoted 5 lines · Stephen Smalley
Add a simple utility (
scripts/selinux/genheaders) and invoke it to generate the kernel-private class and permission indices inflask.handav_permissions.hautomatically during the kernel build from the security class mapping definitions inclassmap.h. Adding new kernel classes and permissions can then be done just by adding them toclassmap.h.I've run the ltp selinux testsuite before and after these patches and confirmed no regressions in denying system calls (i.e. no FAILs) or in generated AVC messages (by clearing the audit log and restarting auditd before each run, then running ausearch -m AVC -ts today | audit2allow afterward and comparing the generated allow rules - cannot compare the raw audit messages since they have data that changes on each run, e.g. pid, ino, ...).
Looks like these patches are linux-next material though since the merge window has closed for 2.6.32.
Eric, with these patches applied, to add a new permission (e.g. for access) to the kernel, you would add it to
security/selinux/include/classmap.h, and then separately add it to the refpolicy access vector definitions. No requirement for the two definitions to line up in terms of index value since they will get mapped based on string name. You could even add the new permission toCOMMON_FILE_PERMS, and the rest of the per-class file permissions will just get remapped appropriately. On the policy side though, you don't want to modify the common file permissions definition because that will affect older kernels that predate this dynamic class/perm discovery support. But there is no need forCOMMON_FILE_PERMSto line up with the common file perms in the policy, which means we can in fact continue to use common file perms as a convenient way to avoid a switch statement or array for mapping classes to permissions in the hook functions.One caveat is that we still need to ensure that
COMMON_FILE_PERMSandCOMMON_SOCK_PERMScontinue to line up with each other in the set of permissions used by file hooks that can act on either files or sockets, unless we change those hooks to select the specific permission based on the class. The permissions that are shared by file and socket classes are the ones up through "append"; after that they diverge.There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }
Quoted 8 lines
# legacy network or compat_net=1 checks
node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send }
# legacy network or compat_net=1 checks
netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send }
# Original socket controls; never merged to mainline - only connectto is used
unix_stream_socket { newconn acceptfrom }
# Patches merged prematurely by Fedora, never merged to mainline
packet { flow_in flow_out }One other note: before we can allow arbitrary ordering of class definitions, we need to update all userspace object managers to use selinux_set_mapping(). This includes cronie, usermode, pam, mcstrans, passwd, shadow-utils, util-linux-ng, nscd (glibc), dbus and possibly others I am forgetting. Also libselinux rpm_execcon().
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 5 lines
One other note: before we can allow arbitrary ordering of class definitions, we need to update all userspace object managers to use
selinux_set_mapping(). This includes cronie, usermode, pam, mcstrans, passwd, shadow-utils, util-linux-ng, nscd (glibc), dbus and possibly others I am forgetting. Also libselinuxrpm_execcon().
busybox. It uses checkPasswdAccess() which internally calls string_to_security_class() but requested access vector is delivered without any translation.
#if ENABLE_SELINUX
static void check_selinux_update_passwd(const char *username)
{
security_context_t context;
char *seuser;
if (getuid() != (uid_t)0 || is_selinux_enabled() == 0)
return; /* No need to check */
if (getprevcon_raw(&context) < 0)
bb_perror_msg_and_die("getprevcon failed");
seuser = strtok(context, ":");
if (!seuser)
bb_error_msg_and_die("invalid context '%s'", context);
if (strcmp(seuser, username) != 0) {
if (checkPasswdAccess(PASSWD__PASSWD) != 0)
bb_error_msg_and_die("SELinux: access denied");
}
if (ENABLE_FEATURE_CLEAN_UP)
freecon(context);
}#else
#define check_selinux_update_passwd(username) ((void)0) #endif
Signature · 7 lines
OSS Platform Development Division, NEC KaiGai Kohei <[email protected]> -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
In reply to Stephen SmalleyQuoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }
Quoted 8 lines
# legacy network or compat_net=1 checks
node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send }
# legacy network or compat_net=1 checks
netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send }
# Original socket controls; never merged to mainline - only connectto is used
unix_stream_socket { newconn acceptfrom }
# Patches merged prematurely by Fedora, never merged to mainline
packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the classmap.h for the test purpose. The object classes and access vectors are ramdomized as the attached claasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.
Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permission module_request in class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process
type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process
type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------
Signature · 2 lines
OSS Platform Development Division, NEC KaiGai Kohei <[email protected]>
/* These definitions must match the definitions in av_permissions.h. */
#define COMMON_FILE_PERMS "mounton", "quotaon", "swapon", "execute", "rename", \ "link", "unlink", "append", "relabelto", "relabelfrom", "lock", \ "setattr", "getattr", "create", "write", "read", "ioctl"
#define COMMON_SOCK_PERMS "append", "bind", "connect", "listen", "accept", \ "getopt", "setopt", "shutdown", "recvfrom", \ "setattr", "lock", "relabelfrom", "relabelto", \ "sendto", "recv_msg", "send_msg", "name_bind", \ "ioctl", "read", "write", "create", "getattr"
struct security_class_mapping secclass_map[] = {
{ "dir",
{ COMMON_FILE_PERMS, "add_name", "remove_name",
"reparent", "search", "rmdir", "open", NULL } },
{ "fd", { "use", NULL } },
{ "lnk_file",
{ COMMON_FILE_PERMS, NULL } },
{ "chr_file",
{ COMMON_FILE_PERMS,
"execute_no_trans", "entrypoint", "execmod", "open", NULL } },
{ "file",
{ COMMON_FILE_PERMS,
"execute_no_trans", "entrypoint", "execmod", "open", NULL } },
{ "packet",
{ "send", "recv", "relabelto", "flow_in", "flow_out",
"forward_in", "forward_out", NULL } },
{ "blk_file",
{ COMMON_FILE_PERMS, "open", NULL } },
{ "sock_file",
{ COMMON_FILE_PERMS, "open", NULL } },
{ "fifo_file",
{ COMMON_FILE_PERMS, "open", NULL } },
{ "socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "tcp_socket",
{ COMMON_SOCK_PERMS,
"connectto", "newconn", "acceptfrom", "node_bind", "name_connect",
NULL } },
{ "udp_socket",
{ COMMON_SOCK_PERMS,
"node_bind", NULL } },
{ "rawip_socket",
{ COMMON_SOCK_PERMS,
"node_bind", NULL } },
{ "netlink_nflog_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "netlink_xfrm_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", NULL } },
{ "netlink_selinux_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "netlink_audit_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", "nlmsg_relay", "nlmsg_readpriv",
"nlmsg_tty_audit", NULL } },
{ "netlink_ip6fw_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", NULL } },
{ "netlink_dnrt_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "association",
{ "sendto", "recvfrom", "setcontext", "polmatch", NULL } },
{ "node",
{ "tcp_recv", "tcp_send", "udp_recv", "udp_send",
"rawip_recv", "rawip_send", "enforce_dest",
"dccp_recv", "dccp_send", "recvfrom", "sendto", NULL } },
{ "netif",
{ "tcp_recv", "tcp_send", "udp_recv", "udp_send",
"rawip_recv", "rawip_send", "dccp_recv", "dccp_send",
"ingress", "egress", NULL } },
{ "netlink_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "packet_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "key_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "unix_stream_socket",
{ COMMON_SOCK_PERMS, "connectto", "newconn", "acceptfrom", NULL
} },
{ "unix_dgram_socket",
{ COMMON_SOCK_PERMS, NULL
} },
{ "sem",
{ "create", "destroy", "getattr", "setattr", "read",
"write", "associate", "unix_read", "unix_write", NULL } },
{ "msg", { "send", "receive", NULL } },
{ "msgq",
{ "create", "destroy", "getattr", "setattr", "read",
"write", "associate", "unix_read", "unix_write",
"enqueue", NULL } },
{ "shm",
{ "create", "destroy", "getattr", "setattr", "read",
"write", "associate", "unix_read", "unix_write", "lock",
NULL } },
{ "ipc",
{ "create", "destroy", "getattr", "setattr", "read",
"write", "associate", "unix_read", "unix_write", NULL } },
{ "netlink_route_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", NULL } },
{ "netlink_firewall_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", NULL } },
{ "netlink_tcpdiag_socket",
{ COMMON_SOCK_PERMS,
"nlmsg_read", "nlmsg_write", NULL } },
{ "netlink_kobject_uevent_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "appletalk_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ "security",
{ "compute_av", "compute_create", "compute_member",
"check_context", "load_policy", "compute_relabel",
"compute_user", "setenforce", "setbool", "setsecparam",
"setcheckreqprot", NULL } },
{ "process",
{ "fork", "transition", "sigchld", "sigkill",
"sigstop", "signull", "signal", "ptrace", "getsched", "setsched",
"getsession", "getpgid", "setpgid", "getcap", "setcap", "share",
"getattr", "setexec", "setfscreate", "noatsecure", "siginh",
"setrlimit", "rlimitinh", "dyntransition", "setcurrent",
"execmem", "execstack", "execheap", "setkeycreate",
"setsockcreate", NULL } },
{ "system",
{ "ipc_info", "syslog_read", "syslog_mod",
"syslog_console", "module_request", NULL } },
{ "capability",
{ "chown", "dac_override", "dac_read_search",
"fowner", "fsetid", "kill", "setgid", "setuid", "setpcap",
"linux_immutable", "net_bind_service", "net_broadcast",
"net_admin", "net_raw", "ipc_lock", "ipc_owner", "sys_module",
"sys_rawio", "sys_chroot", "sys_ptrace", "sys_pacct", "sys_admin",
"sys_boot", "sys_nice", "sys_resource", "sys_time",
"sys_tty_config", "mknod", "lease", "audit_write",
"audit_control", "setfcap", NULL } },
{ "filesystem",
{ "mount", "remount", "unmount", "getattr",
"relabelfrom", "relabelto", "transition", "associate", "quotamod",
"quotaget", NULL } },
{ "key",
{ "view", "read", "write", "search", "link", "setattr", "create",
NULL } },
{ "dccp_socket",
{ COMMON_SOCK_PERMS,
"node_bind", "name_connect", NULL } },
{ "memprotect", { "mmap_zero", NULL } },
{ "peer", { "recv", NULL } },
{ "capability2", { "mac_override", "mac_admin", NULL } },
{ "kernel_service", { "use_as_override", "create_files_as", NULL } },
{ "tun_socket",
{ COMMON_SOCK_PERMS, NULL } },
{ NULL }};
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 54 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permissionmodule_requestin class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295
Quoted 6 lines
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------
Oh, I see why. The security server internally uses a few class and permission symbolic definitions (e.g. SECCLASS_PROCESS, PROCESS__TRANSITION, ...), and it expects them to correspond to the policy values rather than the kernel-private indices. So it needs to instead use string_to_security_class() and string_to_av_perm() to look them up. Easy enough to fix.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 62 lines · Stephen Smalley
Quoted 54 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permissionmodule_requestin class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295Quoted 6 lines
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------
Quoted 6 lines
Oh, I see why. The security server internally uses a few class and permission symbolic definitions (e.g.
SECCLASS_PROCESS,PROCESS__TRANSITION, ...), and it expects them to correspond to the policy values rather than the kernel-private indices. So it needs to instead usestring_to_security_class()andstring_to_av_perm()to look them up. Easy enough to fix.
Does anyone think we still need to support policy versions < POLICYDB_VERSION_NLCLASS (18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version < POLICYDB_VERSION_NLCLASS)
if (tclass >= SECCLASS_NETLINK_ROUTE_SOCKET &&
tclass <= SECCLASS_NETLINK_DNRT_SOCKET)
tclass = SECCLASS_NETLINK_SOCKET;
I think RHEL4 shipped with policy.18.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 9 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
Signature · 7 lines
James Morris <[email protected]> -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 10 lines · James Morris
Quoted 8 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;
Quoted 4 lines
Quoted 1 line
I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux < 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua? Debian selinux packages predated Fedora, of course, but weren't mainstreamed into Debian until much later.
I didn't yet remove this logic in my patches, but will do so if there are no objections.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 26 lines · Stephen Smalley
Quoted 11 lines · James Morris
Quoted 8 lines · Stephen Smalley
Does anyone think we still need to support policy versions<
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:if (policydb_loaded_version< POLICYDB_VERSION_NLCLASS) if (tclass>= SECCLASS_NETLINK_ROUTE_SOCKET&& tclass<= SECCLASS_NETLINK_DNRT_SOCKET) tclass = SECCLASS_NETLINK_SOCKET;Quoted 5 lines
Quoted 2 lines
I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux< 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua? Debian selinux packages predated Fedora, of course, but weren't mainstreamed into Debian until much later.
Quoted 4 lines
I didn't yet remove this logic in my patches, but will do so if there are no objections.
I don't think it matters, the only case where this would come up is if you updated your kernel to 2.6.33 and didn't rebuild your policy right? I just don't see that happening really.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
In reply to Stephen SmalleyQuoted 22 lines · Stephen Smalley
Quoted 9 lines · James Morris
Quoted 8 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;Quoted 4 lines
Quoted 1 line
I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux < 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua? Debian selinux packages predated Fedora, of course, but weren't mainstreamed into Debian until much later.
Quoted 2 lines
I didn't yet remove this logic in my patches, but will do so if there are no objections.
I'm sure you've already thought about this, but if you do remove the code for policy versions below 18 I would recommend doing so in a standalone patch - that way if somebody does end up with a broken system the bisect will only drag down the policy.18 patch and not the rest of these patches (which are going to be a very nice addition).
Signature · 7 lines
paul moore linux @ hp -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 23 lines · Paul Moore
Quoted 22 lines · Stephen Smalley
Quoted 9 lines · James Morris
Quoted 8 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;Quoted 4 lines
Quoted 1 line
I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux < 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua? Debian selinux packages predated Fedora, of course, but weren't mainstreamed into Debian until much later.
Quoted 8 lines
Quoted 2 lines
I didn't yet remove this logic in my patches, but will do so if there are no objections.
I'm sure you've already thought about this, but if you do remove the code for policy versions below 18 I would recommend doing so in a standalone patch - that way if somebody does end up with a broken system the bisect will only drag down the policy.18 patch and not the rest of these patches (which are going to be a very nice addition).
Yes, I'll do it as a separate patch relative to the v5 patches.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
In reply to Stephen SmalleyQuoted 13 lines · Stephen Smalley
Quoted 12 lines · James Morris
Quoted 9 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;I think RHEL4 shipped with policy.18.
Quoted 8 lines
Quoted 2 lines
Was any distro shipped with a lower policy version? If not, then I think it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux < 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua?
No objection here. Gentoo has several kernels, but none that old.
Signature · 13 lines
Chris PeBenito <[email protected]> Developer, Hardened Gentoo Linux Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243 Key fingerprint = B0E6 877A 883F A57A 8E6A CB00 BC8E E42D E6AF 9243 -- 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.
RE: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Hello all,
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Chris PeBenito
Sent: Saturday, October 03, 2009 3:34 AM
To: Stephen Smalley
Cc: James Morris; KaiGai Kohei; [email protected]; Eric Paris; Paul Moore; Joshua Brindle
Subject: Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 11 lines · Stephen Smalley
Quoted 10 lines · James Morris
Quoted 8 lines · Stephen Smalley
Does anyone think we still need to support policy versions <
POLICYDB_VERSION_NLCLASS(18)? If not, then we can just drop the dynamic remapping of netlink classes in the security server:
if (policydb_loaded_version<POLICYDB_VERSION_NLCLASS)
if (tclass >=SECCLASS_NETLINK_ROUTE_SOCKET&&
tclass <=SECCLASS_NETLINK_DNRT_SOCKET)
tclass =SECCLASS_NETLINK_SOCKET;
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I think RHEL4 shipped with policy.18.
Was any distro shipped with a lower policy version? If not, then I
think
Quoted 7 lines
Quoted 1 line
it should be ok.
policy.18 was first supported by Linux 2.6.8.
I think the only distro to ship with SELinux enabled and Linux < 2.6.8 would have been Fedora Core 2, which is long since EOL'd and even akpm doesn't run it anymore. Not sure about Hardened Gentoo - Chris and/or Joshua?
No objection here. Gentoo has several kernels, but none that old.
Signature · 26 lines
Chris PeBenito <[email protected]> Developer, Hardened Gentoo Linux Public Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE6AF9243 Key fingerprint = B0E6 877A 883F A57A 8E6A CB00 BC8E E42D E6AF 9243 We've agreed! Best regards, Octavian Ionescu 欧珂塔维亚 Core Network TAC Engineer Huawei Technologies Co. ,Ltd Mobile: +40726691157 E-mail: [email protected] -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
In reply to Stephen SmalleyQuoted 62 lines · Stephen Smalley
Quoted 54 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permissionmodule_requestin class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295Quoted 6 lines
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------
Quoted 6 lines
Oh, I see why. The security server internally uses a few class and permission symbolic definitions (e.g.
SECCLASS_PROCESS,PROCESS__TRANSITION, ...), and it expects them to correspond to the policy values rather than the kernel-private indices. So it needs to instead usestring_to_security_class()andstring_to_av_perm()to look them up. Easy enough to fix.
I applied the patch below on top. Since we use the process class and process transition permissions multiple times and even need the process class value at policy load, I look those values up during policydb_read and cache them in the policydb. For the other uses of SECCLASS_ values within the security server, I just call unmap_class() as needed. Building it now. I'll fold this into the first patch if it works.
security/selinux/ss/mls.c +1 -1
@@ -532,7 +532,7 @@ int mls_compute_sid(struct context *scontext, }/* Fallthrough */ case AVTAB_CHANGE : -if (tclass ==SECCLASS_PROCESS ) +if (tclass == policydb.process_class)/* Use the process MLS attributes. */ return mls_context_cpy (newcontext, scontext);else
security/selinux/ss/policydb.c +45 -1
64 lines not on this page · raw message
security/selinux/ss/policydb.h +6 -0
@@ -254,6 +254,9 @@ struct policydb { unsigned int reject_unknown : 1; unsigned int allow_unknown : 1; + +u16 process_class; +u32 process_trans_perms; };extern void policydb_destroy (struct policydb *p);
@@ -294,5 +297,8 @@ static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes) return 0; } +extern u16 string_to_security_class (struct policydb *p,const char *name); +extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name); +#endif /* _SS_POLICYDB_H_ */
security/selinux/ss/services.c +24 -68
185 lines not on this page · raw message
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 70 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 54 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permissionmodule_requestin class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295Quoted 6 lines
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------Quoted 6 lines
Oh, I see why. The security server internally uses a few class and permission symbolic definitions (e.g.
SECCLASS_PROCESS,PROCESS__TRANSITION, ...), and it expects them to correspond to the policy values rather than the kernel-private indices. So it needs to instead usestring_to_security_class()andstring_to_av_perm()to look them up. Easy enough to fix.
Quoted 6 lines
I applied the patch below on top. Since we use the process class and process transition permissions multiple times and even need the process class value at policy load, I look those values up during
policydb_readand cache them in the policydb. For the other uses ofSECCLASS_values within the security server, I just callunmap_class()as needed. Building it now. I'll fold this into the first patch if it works.
Ah, that crashes on boot. Need to wait until after we've done policydb_index_classes() to call string_to_av_perm(). Let's try this instead:
security/selinux/ss/mls.c +1 -1
@@ -532,7 +532,7 @@ int mls_compute_sid(struct context *scontext, }/* Fallthrough */ case AVTAB_CHANGE : -if (tclass ==SECCLASS_PROCESS ) +if (tclass == policydb.process_class)/* Use the process MLS attributes. */ return mls_context_cpy (newcontext, scontext);else
security/selinux/ss/policydb.c +45 -1
64 lines not on this page · raw message
security/selinux/ss/policydb.h +6 -0
@@ -254,6 +254,9 @@ struct policydb { unsigned int reject_unknown : 1; unsigned int allow_unknown : 1; + +u16 process_class; +u32 process_trans_perms; };extern void policydb_destroy (struct policydb *p);
@@ -294,5 +297,8 @@ static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes) return 0; } +extern u16 string_to_security_class (struct policydb *p,const char *name); +extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name); +#endif /* _SS_POLICYDB_H_ */
security/selinux/ss/services.c +24 -68
185 lines not on this page · raw message
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 78 lines · Stephen Smalley
Quoted 70 lines · Stephen Smalley
Quoted 62 lines · Stephen Smalley
Quoted 54 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.Did you already remove the unused kernel permissions?
-- kernel boot messages
:
Creating initial device nodes
plymouthd used greatest stack depth: 6532 bytes left
async/0 used greatest stack depth: 6284 bytes left
async/1 used greatest stack depth: 5828 bytes left
input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input4 kjournald starting. Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
type=1404 audit(1254231627.600:2): enforcing=1 old_enforcing=0 auid=4294967295 ses=4294967295
SELinux: Permissionmodule_requestin class system not defined in policy.
SELinux: the above unknown classes and permissions will be allowed
type=1403 audit(1254231628.088:3): policy loaded auid=4294967295 ses=4294967295Quoted 6 lines
type=1400 audit(1254231628.100:4): avc: denied { transition } for pid=58 comm="init" path="/bin/plymouth" dev=rootfs ino=3512 scontext=system_u:system_r:kernel_t:s0 tcontext=system_u:object_r:root_t:s0 tclass=process type=1400 audit(1254231628.438:5): avc: denied { transition } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:init_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=process type=1400 audit(1254231628.458:6): avc: denied { entrypoint } for pid=58 comm="init" path="/sbin/telinit" dev=sda5 ino=621655 scontext=system_u:object_r:bin_t:s0 tcontext=system_u:object_r:bin_t:s0 tclass=fileinit used greatest stack depth: 5684 bytes left
init: Not being executed as init
------Quoted 6 lines
Oh, I see why. The security server internally uses a few class and permission symbolic definitions (e.g.
SECCLASS_PROCESS,PROCESS__TRANSITION, ...), and it expects them to correspond to the policy values rather than the kernel-private indices. So it needs to instead usestring_to_security_class()andstring_to_av_perm()to look them up. Easy enough to fix.Quoted 6 lines
I applied the patch below on top. Since we use the process class and process transition permissions multiple times and even need the process class value at policy load, I look those values up during
policydb_readand cache them in the policydb. For the other uses ofSECCLASS_values within the security server, I just callunmap_class()as needed. Building it now. I'll fold this into the first patch if it works.
Quoted 3 lines
Ah, that crashes on boot. Need to wait until after we've done
policydb_index_classes()to callstring_to_av_perm(). Let's try this instead:
Almost, but not quite - need to always unmap the class passed to security_genfs_sid().
security/selinux/ss/mls.c +1 -1
@@ -532,7 +532,7 @@ int mls_compute_sid(struct context *scontext, }/* Fallthrough */ case AVTAB_CHANGE : -if (tclass ==SECCLASS_PROCESS ) +if (tclass == policydb.process_class)/* Use the process MLS attributes. */ return mls_context_cpy (newcontext, scontext);else
security/selinux/ss/policydb.c +45 -1
64 lines not on this page · raw message
security/selinux/ss/policydb.h +6 -0
@@ -254,6 +254,9 @@ struct policydb { unsigned int reject_unknown : 1; unsigned int allow_unknown : 1; + +u16 process_class; +u32 process_trans_perms; };extern void policydb_destroy (struct policydb *p);
@@ -294,5 +297,8 @@ static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes) return 0; } +extern u16 string_to_security_class (struct policydb *p,const char *name); +extern u32 string_to_av_perm (struct policydb *p,u16 tclass,const char *name); +#endif /* _SS_POLICYDB_H_ */
security/selinux/ss/services.c +26 -68
196 lines not on this page · raw message
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
In reply to KaiGai KoheiQuoted 32 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Quoted 6 lines
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.
Your classmap.h file violates the requirement that the kernel definitions for the common file perms and common sock perms line up with each other for the set of permissions checked by file hooks that can be applied to either files or sockets. I noted that as a caveat in one of my messages.
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.
Re: [PATCH v4 2/2] selinux: generate flask headers during kernel build
Quoted 40 lines · Stephen Smalley
Quoted 32 lines · KaiGai Kohei
Quoted 17 lines · Stephen Smalley
There are several legacy permissions that are no longer used by SELinux. We could remove these from the kernel's
classmap.hdefinitions without breaking anything (subsequent permissions would get mapped to policy values appropriately by the new logic), but removing them from the policy would be harder as it would break all kernels that predate these patches. Thus, I'm not sure we benefit from removing them fromclassmap.h.The unused permissions include:
# LSM hook never merged to mainline
file swapon
# compat_net=1 checks
socket {recv_msgsend_msg}
# Only added so that subsequent permissions (execmod) would get the same value as class filechr_file{execute_no_transentrypoint }
# Original socket controls; never merged to mainlinetcp_socket{ connectto newconn acceptfrom }Quoted 8 lines
# legacy network or compat_net=1 checks node { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send enforce_dest dccp_recv dccp_send } # legacy network or compat_net=1 checks netif { tcp_recv tcp_send udp_recv udp_send rawip_recv rawip_send dccp_recv dccp_send } # Original socket controls; never merged to mainline - only connectto is used unix_stream_socket { newconn acceptfrom } # Patches merged prematurely by Fedora, never merged to mainline packet { flow_in flow_out }It is just a report. I could not reach origin of the matter yet.
When I applies your patch as is, build, install and reboot, I could not find any *obvious* matter (such as boot failed). Good.
Quoted 6 lines
Then, I modified the
classmap.hfor the test purpose. The object classes and access vectors are ramdomized as the attachedclaasmap.h.
This patch enables to map value of them using text identifier, so we can expect it works fine independent from the order of classes and access vectors.
Quoted 5 lines
Your
classmap.hfile violates the requirement that the kernel definitions for the common file perms and common sock perms line up with each other for the set of permissions checked by file hooks that can be applied to either files or sockets. I noted that as a caveat in one of my messages.
I'll make that more explicit by separating the shared permissions into separate #define. Also I'll go ahead and split out the common ipc perms.
security/selinux/include/classmap.h +14 -19
@@ -1,14 +1,15 @@ -/* These definitions must match the definitions in av_permissions.h. */ +#define COMMON_FILE_SOCK_PERMS "ioctl", "read", "write", "create", \ + "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append" -#define COMMON_FILE_PERMS "ioctl", "read", "write", "create", "getattr", \ - "setattr", "lock", "relabelfrom", "relabelto", "append", "unlink", \ - "link", "rename", "execute", "swapon", "quotaon", "mounton" +#define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \ + "rename", "execute", "swapon", "quotaon", "mounton" -#define COMMON_SOCK_PERMS "ioctl", "read", "write", "create", "getattr", \ - "setattr", "lock", "relabelfrom", "relabelto", \ - "append", "bind", "connect", "listen", "accept", \ - "getopt", "setopt", "shutdown", "recvfrom", \ - "sendto", "recv_msg", "send_msg", "name_bind" +#define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \ + "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom", \ + "sendto", "recv_msg", "send_msg", "name_bind" + +#define COMMON_IPC_PERMS "create", "destroy", "getattr", "setattr", "read", \ + "write", "associate", "unix_read", "unix_write"struct security_class_mapping secclass_map[] = { {"security" ,
@@ -91,20 +92,14 @@ struct security_class_mapping secclass_map[] = { { COMMON_SOCK_PERMS, NULL } }, {"sem" , - { "create", "destroy", "getattr", "setattr", "read", - "write", "associate", "unix_read", "unix_write", NULL } }, + { COMMON_IPC_PERMS, NULL } }, { "msg", { "send", "receive", NULL } }, { "msgq", - { "create", "destroy", "getattr", "setattr", "read", -"write" ,"associate" ,"unix_read" ,"unix_write" , - "enqueue", NULL } }, + { COMMON_IPC_PERMS, "enqueue", NULL } }, { "shm", - { "create", "destroy", "getattr", "setattr", "read", -"write" ,"associate" ,"unix_read" ,"unix_write" ,"lock" , - NULL } }, + { COMMON_IPC_PERMS, "lock", NULL } }, { "ipc", - { "create", "destroy", "getattr", "setattr", "read", - "write", "associate", "unix_read", "unix_write", NULL } }, + { COMMON_IPC_PERMS, NULL } }, { "netlink_route_socket", { COMMON_SOCK_PERMS, "nlmsg_read", "nlmsg_write", NULL } },
Signature · 8 lines
Stephen Smalley National Security Agency -- 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.