Verifying user rights on the ioctl command

I am implementing a char driver (Linux), and there are certain IOCTL commands in my driver that only ADMIN should execute.

My question is how can I verify user rights as part of my implementation of the ioctl command and restrict the access of an unprivileged user to IOCTL.

+4
source share
2 answers

You can use a function bool capable(int cap)that returns true if the user requests an opportunity. Possible cap values ​​are listed in the kernel sources in include/uapi/linux/capability.h(macros begin with CAP _).

, - . , . CAP_SYS_ADMIN.

+3

ioctl, . , ioctl, struct file *file, , file->f_mode FMODE_WRITE.

if (!(file->f_mode & FMODE_WRITE))
        return -EACCES;

, . , , -, , .

open() O_RDONLY, , .

ioctl , (CAP_SYS_ADMIN, , ).

if (!capable(CAP_SYS_ADMIN))
        return -EACCES;
+2

Source: https://habr.com/ru/post/1584866/


All Articles