]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - include/linux/device_cgroup.h
1 /* SPDX-License-Identifier: GPL-2.0 */
3 #include <linux/bpf-cgroup.h>
5 #define DEVCG_ACC_MKNOD 1
6 #define DEVCG_ACC_READ 2
7 #define DEVCG_ACC_WRITE 4
8 #define DEVCG_ACC_MASK (DEVCG_ACC_MKNOD | DEVCG_ACC_READ | DEVCG_ACC_WRITE)
10 #define DEVCG_DEV_BLOCK 1
11 #define DEVCG_DEV_CHAR 2
12 #define DEVCG_DEV_ALL 4 /* this represents all devices */
14 #ifdef CONFIG_CGROUP_DEVICE
15 extern int __devcgroup_check_permission(short type
, u32 major
, u32 minor
,
18 static inline int __devcgroup_check_permission(short type
, u32 major
, u32 minor
,
23 #if defined(CONFIG_CGROUP_DEVICE) || defined(CONFIG_CGROUP_BPF)
24 static inline int devcgroup_check_permission(short type
, u32 major
, u32 minor
,
27 int rc
= BPF_CGROUP_RUN_PROG_DEVICE_CGROUP(type
, major
, minor
, access
);
32 return __devcgroup_check_permission(type
, major
, minor
, access
);
35 static inline int devcgroup_inode_permission(struct inode
*inode
, int mask
)
37 short type
, access
= 0;
39 if (likely(!inode
->i_rdev
))
42 if (S_ISBLK(inode
->i_mode
))
43 type
= DEVCG_DEV_BLOCK
;
44 else if (S_ISCHR(inode
->i_mode
))
45 type
= DEVCG_DEV_CHAR
;
50 access
|= DEVCG_ACC_WRITE
;
52 access
|= DEVCG_ACC_READ
;
54 return devcgroup_check_permission(type
, imajor(inode
), iminor(inode
),
58 static inline int devcgroup_inode_mknod(int mode
, dev_t dev
)
62 if (!S_ISBLK(mode
) && !S_ISCHR(mode
))
66 type
= DEVCG_DEV_BLOCK
;
68 type
= DEVCG_DEV_CHAR
;
70 return devcgroup_check_permission(type
, MAJOR(dev
), MINOR(dev
),
75 static inline int devcgroup_inode_permission(struct inode
*inode
, int mask
)
77 static inline int devcgroup_inode_mknod(int mode
, dev_t dev
)