mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-30 06:06:47 +07:00
selinux: simplify ioctl checking
Simplify and improve the robustness of the SELinux ioctl checking by using the "access mode" bits of the ioctl command to determine the permission check rather than dealing with individual command values. This removes any knowledge of specific ioctl commands from SELinux and follows the same guidance we gave to Smack earlier. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: James Morris <jmorris@namei.org>
This commit is contained in:
parent
abc69bb633
commit
242631c49d
@ -42,9 +42,7 @@
|
|||||||
#include <linux/fdtable.h>
|
#include <linux/fdtable.h>
|
||||||
#include <linux/namei.h>
|
#include <linux/namei.h>
|
||||||
#include <linux/mount.h>
|
#include <linux/mount.h>
|
||||||
#include <linux/ext2_fs.h>
|
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/kd.h>
|
|
||||||
#include <linux/netfilter_ipv4.h>
|
#include <linux/netfilter_ipv4.h>
|
||||||
#include <linux/netfilter_ipv6.h>
|
#include <linux/netfilter_ipv6.h>
|
||||||
#include <linux/tty.h>
|
#include <linux/tty.h>
|
||||||
@ -2903,46 +2901,16 @@ static void selinux_file_free_security(struct file *file)
|
|||||||
static int selinux_file_ioctl(struct file *file, unsigned int cmd,
|
static int selinux_file_ioctl(struct file *file, unsigned int cmd,
|
||||||
unsigned long arg)
|
unsigned long arg)
|
||||||
{
|
{
|
||||||
int error = 0;
|
u32 av = 0;
|
||||||
|
|
||||||
switch (cmd) {
|
if (_IOC_DIR(cmd) & _IOC_WRITE)
|
||||||
case FIONREAD:
|
av |= FILE__WRITE;
|
||||||
/* fall through */
|
if (_IOC_DIR(cmd) & _IOC_READ)
|
||||||
case FIBMAP:
|
av |= FILE__READ;
|
||||||
/* fall through */
|
if (!av)
|
||||||
case FIGETBSZ:
|
av = FILE__IOCTL;
|
||||||
/* fall through */
|
|
||||||
case EXT2_IOC_GETFLAGS:
|
|
||||||
/* fall through */
|
|
||||||
case EXT2_IOC_GETVERSION:
|
|
||||||
error = file_has_perm(current, file, FILE__GETATTR);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EXT2_IOC_SETFLAGS:
|
return file_has_perm(current, file, av);
|
||||||
/* fall through */
|
|
||||||
case EXT2_IOC_SETVERSION:
|
|
||||||
error = file_has_perm(current, file, FILE__SETATTR);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* sys_ioctl() checks */
|
|
||||||
case FIONBIO:
|
|
||||||
/* fall through */
|
|
||||||
case FIOASYNC:
|
|
||||||
error = file_has_perm(current, file, 0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KDSKBENT:
|
|
||||||
case KDSKBSENT:
|
|
||||||
error = task_has_capability(current, CAP_SYS_TTY_CONFIG);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* default case assumes that the command will go
|
|
||||||
* to the file's ioctl() function.
|
|
||||||
*/
|
|
||||||
default:
|
|
||||||
error = file_has_perm(current, file, FILE__IOCTL);
|
|
||||||
}
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
|
static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
|
||||||
|
Loading…
Reference in New Issue
Block a user