Skip to content

Commit 65881e1

Browse files
Richard Hainespcmoore
authored andcommitted
selinux: allow FIOCLEX and FIONCLEX with policy capability
These ioctls are equivalent to fcntl(fd, F_SETFD, flags), which SELinux always allows too. Furthermore, a failed FIOCLEX could result in a file descriptor being leaked to a process that should not have access to it. As this patch removes access controls, a policy capability needs to be enabled in policy to always allow these ioctls. Based-on-patch-by: Demi Marie Obenour <demiobenour@gmail.com> Signed-off-by: Richard Haines <richard_c_haines@btinternet.com> [PM: subject line tweak] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent b97df7c commit 65881e1

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

security/selinux/hooks.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,12 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd,
36823682
CAP_OPT_NONE, true);
36833683
break;
36843684

3685+
case FIOCLEX:
3686+
case FIONCLEX:
3687+
if (!selinux_policycap_ioctl_skip_cloexec())
3688+
error = ioctl_has_perm(cred, file, FILE__IOCTL, (u16) cmd);
3689+
break;
3690+
36853691
/* default case assumes that the command will go
36863692
* to the file's ioctl() function.
36873693
*/

security/selinux/include/policycap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum {
1111
POLICYDB_CAPABILITY_CGROUPSECLABEL,
1212
POLICYDB_CAPABILITY_NNP_NOSUID_TRANSITION,
1313
POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS,
14+
POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC,
1415
__POLICYDB_CAPABILITY_MAX
1516
};
1617
#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)

security/selinux/include/policycap_names.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const char *selinux_policycap_names[__POLICYDB_CAPABILITY_MAX] = {
1212
"always_check_network",
1313
"cgroup_seclabel",
1414
"nnp_nosuid_transition",
15-
"genfs_seclabel_symlinks"
15+
"genfs_seclabel_symlinks",
16+
"ioctl_skip_cloexec"
1617
};
1718

1819
#endif /* _SELINUX_POLICYCAP_NAMES_H_ */

security/selinux/include/security.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ static inline bool selinux_policycap_genfs_seclabel_symlinks(void)
219219
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_GENFS_SECLABEL_SYMLINKS]);
220220
}
221221

222+
static inline bool selinux_policycap_ioctl_skip_cloexec(void)
223+
{
224+
struct selinux_state *state = &selinux_state;
225+
226+
return READ_ONCE(state->policycap[POLICYDB_CAPABILITY_IOCTL_SKIP_CLOEXEC]);
227+
}
228+
222229
struct selinux_policy_convert_data;
223230

224231
struct selinux_load_state {

0 commit comments

Comments
 (0)