Skip to content

Commit 7470d0d

Browse files
cgzonespcmoore
authored andcommitted
selinux: allow kernfs symlinks to inherit parent directory context
Currently symlinks on kernel filesystems, like sysfs, are labeled on creation with the parent filesystem root sid. Allow symlinks to inherit the parent directory context, so fine-grained kernfs labeling can be applied to symlinks too and checking contexts doesn't complain about them. For backward-compatibility this behavior is contained in a new policy capability: genfs_seclabel_symlinks Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 06c2efe commit 7470d0d

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,9 @@ static int inode_doinit_with_dentry(struct inode *inode, struct dentry *opt_dent
14781478
/* Default to the fs superblock SID. */
14791479
sid = sbsec->sid;
14801480

1481-
if ((sbsec->flags & SE_SBGENFS) && !S_ISLNK(inode->i_mode)) {
1481+
if ((sbsec->flags & SE_SBGENFS) &&
1482+
(!S_ISLNK(inode->i_mode) ||
1483+
selinux_policycap_genfs_seclabel_symlinks())) {
14821484
/* We must have a dentry to determine the label on
14831485
* procfs inodes */
14841486
if (opt_dentry) {

‎security/selinux/include/security.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ enum {
7979
POLICYDB_CAPABILITY_ALWAYSNETWORK,
8080
POLICYDB_CAPABILITY_CGROUPSECLABEL,
8181
POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION,
82+
POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS,
8283
__POLICYDB_CAPABILITY_MAX
8384
};
8485
#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
@@ -213,6 +214,13 @@ static inline bool selinux_policycap_nnp_nosuid_transition(void)
213214
return state->policycap[POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION];
214215
}
215216

217+
static inline bool selinux_policycap_genfs_seclabel_symlinks(void)
218+
{
219+
struct selinux_state *state = &selinux_state;
220+
221+
return state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS];
222+
}
223+
216224
int security_mls_enabled(struct selinux_state *state);
217225
int security_load_policy(struct selinux_state *state,
218226
void *data, size_t len);

‎security/selinux/ss/services.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = {
7272
"extended_socket_class",
7373
"always_check_network",
7474
"cgroup_seclabel",
75-
"nnp_nosuid_transition"
75+
"nnp_nosuid_transition",
76+
"genfs_seclabel_symlinks"
7677
};
7778

7879
static struct selinux_ss selinux_ss;

0 commit comments

Comments
 (0)