aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/ss
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2008-06-18 09:50:04 -0400
committerJames Morris <jmorris@namei.org>2008-07-14 01:02:04 -0400
commit811f3799279e567aa354c649ce22688d949ac7a9 (patch)
tree2a4d8c30821de84d5adcf37a09562ebba92f9f23 /security/selinux/ss
parent65fc7668006b537f7ae8451990c0ed9ec882544e (diff)
SELinux: allow fstype unknown to policy to use xattrs if present
Currently if a FS is mounted for which SELinux policy does not define an fs_use_* that FS will either be genfs labeled or not labeled at all. This decision is based on the existence of a genfscon rule in policy and is irrespective of the capabilities of the filesystem itself. This patch allows the kernel to check if the filesystem supports security xattrs and if so will use those if there is no fs_use_* rule in policy. An fstype with a no fs_use_* rule but with a genfs rule will use xattrs if available and will follow the genfs rule. This can be particularly interesting for things like ecryptfs which actually overlays a real underlying FS. If we define excryptfs in policy to use xattrs we will likely get this wrong at times, so with this path we just don't need to define it! Overlay ecryptfs on top of NFS with no xattr support: SELinux: initialized (dev ecryptfs, type ecryptfs), uses genfs_contexts Overlay ecryptfs on top of ext4 with xattr support: SELinux: initialized (dev ecryptfs, type ecryptfs), uses xattr It is also useful as the kernel adds new FS we don't need to add them in policy if they support xattrs and that is how we want to handle them. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'security/selinux/ss')
-rw-r--r--security/selinux/ss/services.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index b52f923ce680..8e42da120101 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1934,7 +1934,8 @@ out:
1934int security_fs_use( 1934int security_fs_use(
1935 const char *fstype, 1935 const char *fstype,
1936 unsigned int *behavior, 1936 unsigned int *behavior,
1937 u32 *sid) 1937 u32 *sid,
1938 bool can_xattr)
1938{ 1939{
1939 int rc = 0; 1940 int rc = 0;
1940 struct ocontext *c; 1941 struct ocontext *c;
@@ -1948,6 +1949,7 @@ int security_fs_use(
1948 c = c->next; 1949 c = c->next;
1949 } 1950 }
1950 1951
1952 /* look for labeling behavior defined in policy */
1951 if (c) { 1953 if (c) {
1952 *behavior = c->v.behavior; 1954 *behavior = c->v.behavior;
1953 if (!c->sid[0]) { 1955 if (!c->sid[0]) {
@@ -1958,14 +1960,23 @@ int security_fs_use(
1958 goto out; 1960 goto out;
1959 } 1961 }
1960 *sid = c->sid[0]; 1962 *sid = c->sid[0];
1963 goto out;
1964 }
1965
1966 /* labeling behavior not in policy, use xattrs if possible */
1967 if (can_xattr) {
1968 *behavior = SECURITY_FS_USE_XATTR;
1969 *sid = SECINITSID_FS;
1970 goto out;
1971 }
1972
1973 /* no behavior in policy and can't use xattrs, try GENFS */
1974 rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid);
1975 if (rc) {
1976 *behavior = SECURITY_FS_USE_NONE;
1977 rc = 0;
1961 } else { 1978 } else {
1962 rc = security_genfs_sid(fstype, "/", SECCLASS_DIR, sid); 1979 *behavior = SECURITY_FS_USE_GENFS;
1963 if (rc) {
1964 *behavior = SECURITY_FS_USE_NONE;
1965 rc = 0;
1966 } else {
1967 *behavior = SECURITY_FS_USE_GENFS;
1968 }
1969 } 1980 }
1970 1981
1971out: 1982out: