SELinux: create new open permission
PATCH 1/1 SELinux: create new open permission
Adds a new open permission inside SELinux when 'opening' a file. The idea is that opening a file and reading/writing to that file are not the same thing. Its different if a program had its stdout redirected to /tmp/output than if the program tried to directly open /tmp/output. This should allow policy writers to more liberally give read/write permissions across the policy while still blocking many design and programing flaws SELinux is so good at catching today.
---
As an example, process1 in httpd_t opened a bunch of files of type user_tmp_t. It then called process2 running as ntpd_t which did nothing but accept those open fd's and terminate. Notice proc1 needed open perms and proc2 only needed read and write.
#============= httpd_t ==============
allow httpd_t tmp_t:dir open;
allow httpd_t user_tmp_t:blk_file { read write open }; allow httpd_t user_tmp_t:chr_file { read write open }; allow httpd_t user_tmp_t:dir { read open };
allow httpd_t user_tmp_t:fifo_file { read write open }; allow httpd_t user_tmp_t:file { read write execute entrypoint open }; allow httpd_t user_tmp_t:lnk_file read;
#============= ntpd_t ==============
allow ntpd_t user_tmp_t:blk_file { read write }; allow ntpd_t user_tmp_t:chr_file { read write }; allow ntpd_t user_tmp_t:dir read;
allow ntpd_t user_tmp_t:fifo_file { read write }; allow ntpd_t user_tmp_t:file { read write entrypoint };
security/selinux/hooks.c | 31 +++++++++++++++++++++++++- security/selinux/include/av_perm_to_string.h | 5 ++++ security/selinux/include/av_permissions.h | 5 ++++ security/selinux/include/security.h | 2 + security/selinux/selinuxfs.c | 1 + security/selinux/ss/services.c | 3 ++ 6 files changed, 46 insertions(+), 1 deletions(-)
security/selinux/hooks.c +30 -1
@@ -1599,6 +1599,35 @@ static inline u32 file_mask_to_av(int mode, int mask)return av; } +/* +* Convert a file mask to an access vector and include the correct open +* open permission. +*/ +static inline u32 open_file_mask_to_av (int mode,int mask) +{ +u32 av =file_mask_to_av (mode, mask); + +if (selinux_policycap_openperm) { +/* +* lnk files and socks do not really have an 'open' +*/ +if (S_ISREG (mode)) + av |=FILE__OPEN ; +else if (S_ISCHR (mode)) + av |=CHR_FILE__OPEN ; +else if (S_ISBLK (mode)) + av |=BLK_FILE__OPEN ; +else if (S_ISFIFO (mode)) + av |=FIFO_FILE__OPEN ; +else if (S_ISDIR (mode)) + av |=DIR__OPEN ; +else +printk (KERN_ERR "SELinux: WARNING: inside open_file_to_av " +"with unknown mode:%x\n" , mode); + } +return av; +} +/* Convert a Linux file to an access vector. */ static inline u32 file_to_av (struct file *file) {
@@ -2517,7 +2546,7 @@ static int selinux_inode_permission(struct inode *inode, int mask, }return inode_has_perm (current, inode, -file_mask_to_av (inode->i_mode, mask),NULL ); +open_file_mask_to_av (inode->i_mode, mask),NULL ); }static int selinux_inode_setattr (struct dentry *dentry,struct iattr *iattr)
security/selinux/include/av_perm_to_string.h +5 -0
@@ -14,12 +14,17 @@ S_(SECCLASS_DIR, DIR__REPARENT, "reparent") S_(SECCLASS_DIR, DIR__SEARCH, "search") S_(SECCLASS_DIR, DIR__RMDIR, "rmdir") + S_(SECCLASS_DIR, DIR__OPEN, "open") S_(SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, "execute_no_trans") S_(SECCLASS_FILE, FILE__ENTRYPOINT, "entrypoint") S_(SECCLASS_FILE, FILE__EXECMOD, "execmod") + S_(SECCLASS_FILE, FILE__OPEN, "open") S_(SECCLASS_CHR_FILE, CHR_FILE__EXECUTE_NO_TRANS, "execute_no_trans") S_(SECCLASS_CHR_FILE, CHR_FILE__ENTRYPOINT, "entrypoint") S_(SECCLASS_CHR_FILE, CHR_FILE__EXECMOD, "execmod") + S_(SECCLASS_CHR_FILE, CHR_FILE__OPEN, "open") + S_(SECCLASS_BLK_FILE, BLK_FILE__OPEN, "open") + S_(SECCLASS_FIFO_FILE, FIFO_FILE__OPEN, "open") S_(SECCLASS_FD, FD__USE, "use") S_(SECCLASS_TCP_SOCKET, TCP_SOCKET__CONNECTTO, "connectto")S_ (SECCLASS_TCP_SOCKET ,TCP_SOCKET__NEWCONN ,"newconn" )
security/selinux/include/av_permissions.h +5 -0
@@ -79,6 +79,7 @@#define DIR__REPARENT 0x00080000UL#define DIR__SEARCH 0x00100000UL#define DIR__RMDIR 0x00200000UL +#define DIR__OPEN 0x00400000UL#define FILE__IOCTL 0x00000001UL#define FILE__READ 0x00000002UL#define FILE__WRITE 0x00000004UL
@@ -99,6 +100,7 @@#define FILE__EXECUTE_NO_TRANS 0x00020000UL#define FILE__ENTRYPOINT 0x00040000UL#define FILE__EXECMOD 0x00080000UL +#define FILE__OPEN 0x00100000UL#define LNK_FILE__IOCTL 0x00000001UL#define LNK_FILE__READ 0x00000002UL#define LNK_FILE__WRITE 0x00000004UL
@@ -136,6 +138,7 @@#define CHR_FILE__EXECUTE_NO_TRANS 0x00020000UL#define CHR_FILE__ENTRYPOINT 0x00040000UL#define CHR_FILE__EXECMOD 0x00080000UL +#define CHR_FILE__OPEN 0x00100000UL#define BLK_FILE__IOCTL 0x00000001UL#define BLK_FILE__READ 0x00000002UL#define BLK_FILE__WRITE 0x00000004UL
@@ -153,6 +156,7 @@#define BLK_FILE__SWAPON 0x00004000UL#define BLK_FILE__QUOTAON 0x00008000UL#define BLK_FILE__MOUNTON 0x00010000UL +#define BLK_FILE__OPEN 0x00020000UL#define SOCK_FILE__IOCTL 0x00000001UL#define SOCK_FILE__READ 0x00000002UL#define SOCK_FILE__WRITE 0x00000004UL
@@ -187,6 +191,7 @@#define FIFO_FILE__SWAPON 0x00004000UL#define FIFO_FILE__QUOTAON 0x00008000UL#define FIFO_FILE__MOUNTON 0x00010000UL +#define FIFO_FILE__OPEN 0x00020000UL#define FD__USE 0x00000001UL#define SOCKET__IOCTL 0x00000001UL#define SOCKET__READ 0x00000002UL
security/selinux/include/security.h +2 -0
@@ -43,11 +43,13 @@ extern int selinux_mls_enabled;/* Policy capabilities */ enum {POLICYDB_CAPABILITY_NETPEER , +POLICYDB_CAPABILITY_OPENPERM , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)extern int selinux_policycap_netpeer; +extern int selinux_policycap_openperm;int security_load_policy (void * data,size_t len);
security/selinux/selinuxfs.c +1 -0
@@ -43,6 +43,7 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" +"open_perms" };unsigned int selinux_checkreqprot =CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE ;
security/selinux/ss/services.c +3 -0
@@ -61,6 +61,7 @@ extern void selnl_notify_policyload(u32 seqno);unsigned int policydb_loaded_version;int selinux_policycap_netpeer; +int selinux_policycap_openperm;/* * This is declared in avc.c
@@ -1306,6 +1307,8 @@ static void security_load_policycaps(void) { selinux_policycap_netpeer =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_NETPEER ); + selinux_policycap_openperm =ebitmap_get_bit (&policydb.policycaps, +POLICYDB_CAPABILITY_OPENPERM ); }extern void selinux_complete_init (void );
--
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.
Quoted 9 lines · Eric Paris
Adds a new open permission inside SELinux when 'opening' a file. The idea is that opening a file and reading/writing to that file are not the same thing. Its different if a program had its stdout redirected to
/tmp/outputthan if the program tried to directly open/tmp/output. This should allow policy writers to more liberally give read/write permissions across the policy while still blocking many design and programing flaws SELinux is so good at catching today.Signed-off-by Eric Paris <[email protected]>
Looks good.
Quoted 199 lines
---
As an example, process1 inhttpd_topened a bunch of files of typeuser_tmp_t. It then called process2 running asntpd_twhich did nothing but accept those open fd's and terminate. Notice proc1 needed open perms and proc2 only needed read and write.#=============
httpd_t==============
allowhttpd_ttmp_t:dir open;
allowhttpd_tuser_tmp_t:blk_file { read write open }; allowhttpd_tuser_tmp_t:chr_file { read write open }; allowhttpd_tuser_tmp_t:dir { read open };
allowhttpd_tuser_tmp_t:fifo_file { read write open }; allowhttpd_tuser_tmp_t:file { read write execute entrypoint open }; allowhttpd_tuser_tmp_t:lnk_file read;#=============
ntpd_t==============
allowntpd_tuser_tmp_t:blk_file { read write }; allowntpd_tuser_tmp_t:chr_file { read write }; allowntpd_tuser_tmp_t:dir read;
allowntpd_tuser_tmp_t:fifo_file { read write }; allowntpd_tuser_tmp_t:file { read write entrypoint };security/selinux/hooks.c | 31 +++++++++++++++++++++++++- security/selinux/include/av_perm_to_string.h | 5 ++++ security/selinux/include/av_permissions.h | 5 ++++ security/selinux/include/security.h | 2 + security/selinux/selinuxfs.c | 1 + security/selinux/ss/services.c | 3 ++ 6 files changed, 46 insertions(+), 1 deletions(-)security/selinux/hooks.c +30
-1@@ -1599,6 +1599,35 @@ static inline u32 file_mask_to_av(int mode, int mask)return av; } +/* +* Convert a file mask to an access vector and include the correct open +* open permission. +*/ +static inline u32 open_file_mask_to_av (int mode,int mask) +{ +u32 av =file_mask_to_av (mode, mask); + +if (selinux_policycap_openperm) { +/* +* lnk files and socks do not really have an 'open' +*/ +if (S_ISREG (mode)) + av |=FILE__OPEN ; +else if (S_ISCHR (mode)) + av |=CHR_FILE__OPEN ; +else if (S_ISBLK (mode)) + av |=BLK_FILE__OPEN ; +else if (S_ISFIFO (mode)) + av |=FIFO_FILE__OPEN ; +else if (S_ISDIR (mode)) + av |=DIR__OPEN ; +else +printk (KERN_ERR "SELinux: WARNING: inside open_file_to_av " +"with unknown mode:%x\n" , mode); + } +return av; +} +/* Convert a Linux file to an access vector. */ static inline u32 file_to_av (struct file *file) {@@ -2517,7 +2546,7 @@ static int selinux_inode_permission(struct inode *inode, int mask, }return inode_has_perm (current, inode, -file_mask_to_av (inode->i_mode, mask),NULL ); +open_file_mask_to_av (inode->i_mode, mask),NULL ); }static int selinux_inode_setattr (struct dentry *dentry,struct iattr *iattr)security/selinux/include/av_perm_to_string.h +5
-0@@ -14,12 +14,17 @@ S_(SECCLASS_DIR, DIR__REPARENT, "reparent") S_(SECCLASS_DIR, DIR__SEARCH, "search") S_(SECCLASS_DIR, DIR__RMDIR, "rmdir") + S_(SECCLASS_DIR, DIR__OPEN, "open") S_(SECCLASS_FILE, FILE__EXECUTE_NO_TRANS, "execute_no_trans") S_(SECCLASS_FILE, FILE__ENTRYPOINT, "entrypoint") S_(SECCLASS_FILE, FILE__EXECMOD, "execmod") + S_(SECCLASS_FILE, FILE__OPEN, "open") S_(SECCLASS_CHR_FILE, CHR_FILE__EXECUTE_NO_TRANS, "execute_no_trans") S_(SECCLASS_CHR_FILE, CHR_FILE__ENTRYPOINT, "entrypoint") S_(SECCLASS_CHR_FILE, CHR_FILE__EXECMOD, "execmod") + S_(SECCLASS_CHR_FILE, CHR_FILE__OPEN, "open") + S_(SECCLASS_BLK_FILE, BLK_FILE__OPEN, "open") + S_(SECCLASS_FIFO_FILE, FIFO_FILE__OPEN, "open") S_(SECCLASS_FD, FD__USE, "use") S_(SECCLASS_TCP_SOCKET, TCP_SOCKET__CONNECTTO, "connectto")S_ (SECCLASS_TCP_SOCKET ,TCP_SOCKET__NEWCONN ,"newconn" )security/selinux/include/av_permissions.h +5
-0@@ -79,6 +79,7 @@#define DIR__REPARENT 0x00080000UL#define DIR__SEARCH 0x00100000UL#define DIR__RMDIR 0x00200000UL +#define DIR__OPEN 0x00400000UL#define FILE__IOCTL 0x00000001UL#define FILE__READ 0x00000002UL#define FILE__WRITE 0x00000004UL@@ -99,6 +100,7 @@#define FILE__EXECUTE_NO_TRANS 0x00020000UL#define FILE__ENTRYPOINT 0x00040000UL#define FILE__EXECMOD 0x00080000UL +#define FILE__OPEN 0x00100000UL#define LNK_FILE__IOCTL 0x00000001UL#define LNK_FILE__READ 0x00000002UL#define LNK_FILE__WRITE 0x00000004UL@@ -136,6 +138,7 @@#define CHR_FILE__EXECUTE_NO_TRANS 0x00020000UL#define CHR_FILE__ENTRYPOINT 0x00040000UL#define CHR_FILE__EXECMOD 0x00080000UL +#define CHR_FILE__OPEN 0x00100000UL#define BLK_FILE__IOCTL 0x00000001UL#define BLK_FILE__READ 0x00000002UL#define BLK_FILE__WRITE 0x00000004UL@@ -153,6 +156,7 @@#define BLK_FILE__SWAPON 0x00004000UL#define BLK_FILE__QUOTAON 0x00008000UL#define BLK_FILE__MOUNTON 0x00010000UL +#define BLK_FILE__OPEN 0x00020000UL#define SOCK_FILE__IOCTL 0x00000001UL#define SOCK_FILE__READ 0x00000002UL#define SOCK_FILE__WRITE 0x00000004UL@@ -187,6 +191,7 @@#define FIFO_FILE__SWAPON 0x00004000UL#define FIFO_FILE__QUOTAON 0x00008000UL#define FIFO_FILE__MOUNTON 0x00010000UL +#define FIFO_FILE__OPEN 0x00020000UL#define FD__USE 0x00000001UL#define SOCKET__IOCTL 0x00000001UL#define SOCKET__READ 0x00000002ULsecurity/selinux/include/security.h +2
-0@@ -43,11 +43,13 @@ extern int selinux_mls_enabled;/* Policy capabilities */ enum {POLICYDB_CAPABILITY_NETPEER , +POLICYDB_CAPABILITY_OPENPERM , __POLICYDB_CAPABILITY_MAX };#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)extern int selinux_policycap_netpeer; +extern int selinux_policycap_openperm;int security_load_policy (void * data,size_t len);security/selinux/selinuxfs.c +1
-0@@ -43,6 +43,7 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" +"open_perms" };unsigned int selinux_checkreqprot =CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE ;security/selinux/ss/services.c +3
-0@@ -61,6 +61,7 @@ extern void selnl_notify_policyload(u32 seqno);unsigned int policydb_loaded_version;int selinux_policycap_netpeer; +int selinux_policycap_openperm;/* * This is declared in avc.c @@ -1306,6 +1307,8 @@ static void security_load_policycaps(void) { selinux_policycap_netpeer =ebitmap_get_bit (&policydb.policycaps,POLICYDB_CAPABILITY_NETPEER ); + selinux_policycap_openperm =ebitmap_get_bit (&policydb.policycaps, +POLICYDB_CAPABILITY_OPENPERM ); }extern void selinux_complete_init (void );
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.
security/selinux/selinuxfs.c line 47
Quoted 10 lines · Eric Paris
(quoted diff) +0
-0
b/security/selinux/selinuxfs.cindex 0341567..6e31ce6 100644security/selinux/selinuxfs.c +1
-0@@ -43,6 +43,7 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" +"open_perms" };
I think you're missing a comma here :)
This is easy to test by simply checking the /selinux/policy_capabilities directory.
Signature · 7 lines
paul moore linux security @ 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.
Quoted 14 lines · Paul Moore
security/selinux/selinuxfs.c line 47
Quoted 10 lines · Eric Paris
(quoted diff) +0
-0
b/security/selinux/selinuxfs.cindex 0341567..6e31ce6 100644security/selinux/selinuxfs.c +1
-0@@ -43,6 +43,7 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" +"open_perms" };I think you're missing a comma here :)
Quoted 2 lines
This is easy to test by simply checking the /selinux/policy_capabilities directory.
You mean its not supposed to look like this?
[root@sun-x8420-01 policy_capabilities]# ls network_peer_controlsopen_permissions_checking unknown
fixed patch in 10 minutes. it would be faster but this machine takes forever to reboot.
-Eric
--
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.
Quoted 13 lines · Paul Moore
security/selinux/selinuxfs.c line 47
Quoted 10 lines · Eric Paris
(quoted diff) +0
-0
b/security/selinux/selinuxfs.cindex 0341567..6e31ce6 100644security/selinux/selinuxfs.c +1
-0@@ -43,6 +43,7 @@/* Policy capability filenames */ static char *policycap_names[] = {"network_peer_controls" +"open_perms" };I think you're missing a comma here :)
Ah, good catch - I missed that omission. Thanks.
Quoted 4 lines
This is easy to test by simply checking the /selinux/policy_capabilities directory.
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.