| 1 |
kumaneko |
155 |
/* |
| 2 |
|
|
* security/caitsith/lsm2caitsith.c |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright (C) 2005-2012 NTT DATA CORPORATION |
| 5 |
|
|
* |
| 6 |
kumaneko |
378 |
* Version: 0.2.11 2023/05/27 |
| 7 |
kumaneko |
155 |
*/ |
| 8 |
|
|
|
| 9 |
|
|
#include <linux/path.h> |
| 10 |
|
|
#include <linux/security.h> |
| 11 |
|
|
#include <linux/caitsith.h> |
| 12 |
|
|
|
| 13 |
|
|
int ccs_sb_umount(struct vfsmount *mnt, int flags) |
| 14 |
|
|
{ |
| 15 |
kumaneko |
184 |
return ccs_umount_permission(mnt, flags); |
| 16 |
kumaneko |
155 |
} |
| 17 |
|
|
|
| 18 |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 1, 0) |
| 19 |
|
|
int ccs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) |
| 20 |
|
|
{ |
| 21 |
kumaneko |
184 |
return ccs_getattr_permission(mnt, dentry); |
| 22 |
kumaneko |
155 |
} |
| 23 |
|
|
#else |
| 24 |
|
|
int ccs_inode_getattr(const struct path *path) |
| 25 |
|
|
{ |
| 26 |
kumaneko |
184 |
return ccs_getattr_permission(path->mnt, path->dentry); |
| 27 |
kumaneko |
155 |
} |
| 28 |
|
|
#endif |
| 29 |
|
|
|
| 30 |
|
|
int ccs_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 31 |
|
|
{ |
| 32 |
kumaneko |
184 |
return ccs_ioctl_permission(file, cmd, arg); |
| 33 |
kumaneko |
155 |
} |
| 34 |
|
|
|
| 35 |
|
|
int ccs_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) |
| 36 |
|
|
{ |
| 37 |
kumaneko |
184 |
return ccs_fcntl_permission(file, cmd, arg); |
| 38 |
kumaneko |
155 |
} |
| 39 |
|
|
|
| 40 |
kumaneko |
288 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) || (defined(RHEL_MAJOR) && RHEL_MAJOR == 8) |
| 41 |
kumaneko |
267 |
int ccs_file_open(struct file *file) |
| 42 |
|
|
{ |
| 43 |
|
|
return ccs_open_permission(file); |
| 44 |
|
|
} |
| 45 |
|
|
#else |
| 46 |
kumaneko |
155 |
int ccs_file_open(struct file *file, const struct cred *cred) |
| 47 |
|
|
{ |
| 48 |
kumaneko |
184 |
return ccs_open_permission(file); |
| 49 |
kumaneko |
155 |
} |
| 50 |
kumaneko |
267 |
#endif |
| 51 |
kumaneko |
155 |
|
| 52 |
|
|
int ccs_socket_create(int family, int type, int protocol, int kern) |
| 53 |
|
|
{ |
| 54 |
kumaneko |
184 |
return ccs_socket_create_permission(family, type, protocol); |
| 55 |
kumaneko |
155 |
} |
| 56 |
|
|
|
| 57 |
|
|
int ccs_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) |
| 58 |
|
|
{ |
| 59 |
kumaneko |
184 |
return ccs_socket_bind_permission(sock, address, addrlen); |
| 60 |
kumaneko |
155 |
} |
| 61 |
|
|
|
| 62 |
|
|
int ccs_socket_connect(struct socket *sock, struct sockaddr *address, |
| 63 |
|
|
int addrlen) |
| 64 |
|
|
{ |
| 65 |
kumaneko |
184 |
return ccs_socket_connect_permission(sock, address, addrlen); |
| 66 |
kumaneko |
155 |
} |
| 67 |
|
|
|
| 68 |
|
|
int ccs_socket_listen(struct socket *sock, int backlog) |
| 69 |
|
|
{ |
| 70 |
kumaneko |
184 |
return ccs_socket_listen_permission(sock); |
| 71 |
kumaneko |
155 |
} |
| 72 |
|
|
|
| 73 |
|
|
int ccs_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size) |
| 74 |
|
|
{ |
| 75 |
kumaneko |
184 |
return ccs_socket_sendmsg_permission(sock, msg, size); |
| 76 |
kumaneko |
155 |
} |
| 77 |
|
|
|
| 78 |
kumaneko |
184 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) |
| 79 |
|
|
|
| 80 |
|
|
int ccs_settime(const struct timespec64 *ts, const struct timezone *tz) |
| 81 |
|
|
{ |
| 82 |
|
|
return ccs_capable(CCS_SYS_SETTIME) ? 0 : -EPERM; |
| 83 |
|
|
} |
| 84 |
|
|
|
| 85 |
|
|
int ccs_sb_mount(const char *dev_name, const struct path *path, |
| 86 |
|
|
const char *type, unsigned long flags, void *data) |
| 87 |
|
|
{ |
| 88 |
|
|
return ccs_mount_permission(dev_name, path, type, flags, data); |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
int ccs_sb_pivotroot(const struct path *old_path, const struct path *new_path) |
| 92 |
|
|
{ |
| 93 |
|
|
return ccs_pivot_root_permission(old_path, new_path); |
| 94 |
|
|
} |
| 95 |
|
|
|
| 96 |
kumaneko |
280 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0) |
| 97 |
|
|
int ccs_move_mount(const struct path *from_path, const struct path *to_path) |
| 98 |
|
|
{ |
| 99 |
|
|
return ccs_move_mount_permission(from_path, to_path); |
| 100 |
|
|
} |
| 101 |
|
|
#endif |
| 102 |
|
|
|
| 103 |
kumaneko |
184 |
int ccs_path_unlink(const struct path *dir, struct dentry *dentry) |
| 104 |
|
|
{ |
| 105 |
|
|
return ccs_unlink_permission(dentry, dir->mnt); |
| 106 |
|
|
} |
| 107 |
|
|
|
| 108 |
|
|
int ccs_path_mkdir(const struct path *dir, struct dentry *dentry, umode_t mode) |
| 109 |
|
|
{ |
| 110 |
|
|
return ccs_mkdir_permission(dentry, dir->mnt, mode); |
| 111 |
|
|
} |
| 112 |
|
|
|
| 113 |
|
|
int ccs_path_rmdir(const struct path *dir, struct dentry *dentry) |
| 114 |
|
|
{ |
| 115 |
|
|
return ccs_rmdir_permission(dentry, dir->mnt); |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
int ccs_path_mknod(const struct path *dir, struct dentry *dentry, umode_t mode, |
| 119 |
|
|
unsigned int dev) |
| 120 |
|
|
{ |
| 121 |
|
|
return ccs_mknod_permission(dentry, dir->mnt, mode, dev); |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
kumaneko |
374 |
int ccs_file_truncate(struct file *file) |
| 125 |
|
|
{ |
| 126 |
|
|
return ccs_path_truncate(&file->f_path); |
| 127 |
|
|
} |
| 128 |
|
|
|
| 129 |
kumaneko |
184 |
int ccs_path_truncate(const struct path *path) |
| 130 |
|
|
{ |
| 131 |
|
|
return ccs_truncate_permission(path->dentry, path->mnt); |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
int ccs_path_symlink(const struct path *dir, struct dentry *dentry, |
| 135 |
|
|
const char *old_name) |
| 136 |
|
|
{ |
| 137 |
|
|
return ccs_symlink_permission(dentry, dir->mnt, old_name); |
| 138 |
|
|
} |
| 139 |
|
|
|
| 140 |
|
|
int ccs_path_link(struct dentry *old_dentry, const struct path *new_dir, |
| 141 |
|
|
struct dentry *new_dentry) |
| 142 |
|
|
{ |
| 143 |
|
|
return ccs_link_permission(old_dentry, new_dentry, new_dir->mnt); |
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
kumaneko |
368 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0) |
| 147 |
kumaneko |
184 |
int ccs_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
| 148 |
kumaneko |
368 |
const struct path *new_dir, struct dentry *new_dentry, |
| 149 |
|
|
const unsigned int flags) |
| 150 |
|
|
{ |
| 151 |
|
|
return ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt, flags); |
| 152 |
|
|
} |
| 153 |
|
|
#else |
| 154 |
|
|
int ccs_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
| 155 |
kumaneko |
184 |
const struct path *new_dir, struct dentry *new_dentry) |
| 156 |
|
|
{ |
| 157 |
|
|
return ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt); |
| 158 |
|
|
} |
| 159 |
kumaneko |
368 |
#endif |
| 160 |
kumaneko |
184 |
|
| 161 |
|
|
int ccs_path_chmod(const struct path *path, umode_t mode) |
| 162 |
|
|
{ |
| 163 |
|
|
return ccs_chmod_permission(path->dentry, path->mnt, mode); |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
|
|
int ccs_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
| 167 |
|
|
{ |
| 168 |
|
|
return ccs_chown_permission(path->dentry, path->mnt, uid, gid); |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
|
|
int ccs_path_chroot(const struct path *path) |
| 172 |
|
|
{ |
| 173 |
|
|
return ccs_chroot_permission(path); |
| 174 |
|
|
} |
| 175 |
|
|
|
| 176 |
|
|
#else |
| 177 |
|
|
|
| 178 |
|
|
int ccs_settime(const struct timespec *ts, const struct timezone *tz) |
| 179 |
|
|
{ |
| 180 |
|
|
return ccs_capable(CCS_SYS_SETTIME) ? 0 : -EPERM; |
| 181 |
|
|
} |
| 182 |
|
|
|
| 183 |
|
|
int ccs_sb_mount(const char *dev_name, struct path *path, const char *type, |
| 184 |
|
|
unsigned long flags, void *data) |
| 185 |
|
|
{ |
| 186 |
|
|
return ccs_mount_permission(dev_name, path, type, flags, data); |
| 187 |
|
|
} |
| 188 |
|
|
|
| 189 |
|
|
int ccs_sb_pivotroot(struct path *old_path, struct path *new_path) |
| 190 |
|
|
{ |
| 191 |
|
|
return ccs_pivot_root_permission(old_path, new_path); |
| 192 |
|
|
} |
| 193 |
|
|
|
| 194 |
kumaneko |
155 |
int ccs_path_unlink(struct path *dir, struct dentry *dentry) |
| 195 |
|
|
{ |
| 196 |
kumaneko |
184 |
return ccs_unlink_permission(dentry, dir->mnt); |
| 197 |
kumaneko |
155 |
} |
| 198 |
|
|
|
| 199 |
|
|
int ccs_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode) |
| 200 |
|
|
{ |
| 201 |
kumaneko |
184 |
return ccs_mkdir_permission(dentry, dir->mnt, mode); |
| 202 |
kumaneko |
155 |
} |
| 203 |
|
|
|
| 204 |
|
|
int ccs_path_rmdir(struct path *dir, struct dentry *dentry) |
| 205 |
|
|
{ |
| 206 |
kumaneko |
184 |
return ccs_rmdir_permission(dentry, dir->mnt); |
| 207 |
kumaneko |
155 |
} |
| 208 |
|
|
|
| 209 |
|
|
int ccs_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode, |
| 210 |
|
|
unsigned int dev) |
| 211 |
|
|
{ |
| 212 |
kumaneko |
184 |
return ccs_mknod_permission(dentry, dir->mnt, mode, dev); |
| 213 |
kumaneko |
155 |
} |
| 214 |
|
|
|
| 215 |
|
|
int ccs_path_truncate(struct path *path) |
| 216 |
|
|
{ |
| 217 |
kumaneko |
184 |
return ccs_truncate_permission(path->dentry, path->mnt); |
| 218 |
kumaneko |
155 |
} |
| 219 |
|
|
|
| 220 |
|
|
int ccs_path_symlink(struct path *dir, struct dentry *dentry, |
| 221 |
|
|
const char *old_name) |
| 222 |
|
|
{ |
| 223 |
kumaneko |
184 |
return ccs_symlink_permission(dentry, dir->mnt, old_name); |
| 224 |
kumaneko |
155 |
} |
| 225 |
|
|
|
| 226 |
|
|
int ccs_path_link(struct dentry *old_dentry, struct path *new_dir, |
| 227 |
|
|
struct dentry *new_dentry) |
| 228 |
|
|
{ |
| 229 |
kumaneko |
184 |
return ccs_link_permission(old_dentry, new_dentry, new_dir->mnt); |
| 230 |
kumaneko |
155 |
} |
| 231 |
|
|
|
| 232 |
|
|
int ccs_path_rename(struct path *old_dir, struct dentry *old_dentry, |
| 233 |
|
|
struct path *new_dir, struct dentry *new_dentry) |
| 234 |
|
|
{ |
| 235 |
kumaneko |
184 |
return ccs_rename_permission(old_dentry, new_dentry, new_dir->mnt); |
| 236 |
kumaneko |
155 |
} |
| 237 |
|
|
|
| 238 |
|
|
int ccs_path_chmod(struct path *path, umode_t mode) |
| 239 |
|
|
{ |
| 240 |
kumaneko |
184 |
return ccs_chmod_permission(path->dentry, path->mnt, mode); |
| 241 |
kumaneko |
155 |
} |
| 242 |
|
|
|
| 243 |
|
|
int ccs_path_chown(struct path *path, kuid_t uid, kgid_t gid) |
| 244 |
|
|
{ |
| 245 |
kumaneko |
184 |
return ccs_chown_permission(path->dentry, path->mnt, uid, gid); |
| 246 |
kumaneko |
155 |
} |
| 247 |
|
|
|
| 248 |
|
|
int ccs_path_chroot(struct path *path) |
| 249 |
|
|
{ |
| 250 |
kumaneko |
184 |
return ccs_chroot_permission(path); |
| 251 |
kumaneko |
155 |
} |
| 252 |
|
|
|
| 253 |
kumaneko |
184 |
#endif |
| 254 |
|
|
|
| 255 |
kumaneko |
155 |
#if !defined(CONFIG_SECURITY_PATH) |
| 256 |
|
|
EXPORT_SYMBOL(ccs_path_mkdir); |
| 257 |
|
|
EXPORT_SYMBOL(ccs_path_mknod); |
| 258 |
|
|
EXPORT_SYMBOL(ccs_path_unlink); |
| 259 |
|
|
EXPORT_SYMBOL(ccs_path_rename); |
| 260 |
|
|
#endif |
| 261 |
|
|
|
| 262 |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) && defined(CONFIG_SECURITY) |
| 263 |
|
|
|
| 264 |
|
|
#include <linux/lsm_hooks.h> |
| 265 |
|
|
|
| 266 |
|
|
static struct security_hook_list caitsith_hooks[] = { |
| 267 |
|
|
LSM_HOOK_INIT(settime, ccs_settime), |
| 268 |
|
|
LSM_HOOK_INIT(sb_mount, ccs_sb_mount), |
| 269 |
kumaneko |
280 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0) |
| 270 |
|
|
LSM_HOOK_INIT(move_mount, ccs_move_mount), |
| 271 |
|
|
#endif |
| 272 |
kumaneko |
155 |
LSM_HOOK_INIT(sb_umount, ccs_sb_umount), |
| 273 |
|
|
LSM_HOOK_INIT(sb_pivotroot, ccs_sb_pivotroot), |
| 274 |
|
|
LSM_HOOK_INIT(inode_getattr, ccs_inode_getattr), |
| 275 |
|
|
LSM_HOOK_INIT(file_ioctl, ccs_file_ioctl), |
| 276 |
|
|
LSM_HOOK_INIT(file_fcntl, ccs_file_fcntl), |
| 277 |
|
|
LSM_HOOK_INIT(file_open, ccs_file_open), |
| 278 |
|
|
#if defined(CONFIG_SECURITY_NETWORK) |
| 279 |
|
|
LSM_HOOK_INIT(socket_create, ccs_socket_create), |
| 280 |
|
|
LSM_HOOK_INIT(socket_bind, ccs_socket_bind), |
| 281 |
|
|
LSM_HOOK_INIT(socket_connect, ccs_socket_connect), |
| 282 |
|
|
LSM_HOOK_INIT(socket_listen, ccs_socket_listen), |
| 283 |
|
|
LSM_HOOK_INIT(socket_sendmsg, ccs_socket_sendmsg), |
| 284 |
|
|
#endif |
| 285 |
kumaneko |
374 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 2, 0) |
| 286 |
|
|
LSM_HOOK_INIT(file_truncate, ccs_file_truncate), |
| 287 |
|
|
#endif |
| 288 |
kumaneko |
155 |
#if defined(CONFIG_SECURITY_PATH) |
| 289 |
|
|
LSM_HOOK_INIT(path_unlink, ccs_path_unlink), |
| 290 |
|
|
LSM_HOOK_INIT(path_mkdir, ccs_path_mkdir), |
| 291 |
|
|
LSM_HOOK_INIT(path_rmdir, ccs_path_rmdir), |
| 292 |
|
|
LSM_HOOK_INIT(path_mknod, ccs_path_mknod), |
| 293 |
|
|
LSM_HOOK_INIT(path_truncate, ccs_path_truncate), |
| 294 |
|
|
LSM_HOOK_INIT(path_symlink, ccs_path_symlink), |
| 295 |
|
|
LSM_HOOK_INIT(path_link, ccs_path_link), |
| 296 |
|
|
LSM_HOOK_INIT(path_rename, ccs_path_rename), |
| 297 |
|
|
LSM_HOOK_INIT(path_chmod, ccs_path_chmod), |
| 298 |
|
|
LSM_HOOK_INIT(path_chown, ccs_path_chown), |
| 299 |
|
|
LSM_HOOK_INIT(path_chroot, ccs_path_chroot), |
| 300 |
|
|
#endif |
| 301 |
|
|
}; |
| 302 |
|
|
|
| 303 |
kumaneko |
235 |
static int __init cs_add_hooks(void) |
| 304 |
kumaneko |
155 |
{ |
| 305 |
kumaneko |
235 |
if (caitsith_ops.disabled) |
| 306 |
|
|
return 0; |
| 307 |
kumaneko |
229 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) |
| 308 |
kumaneko |
235 |
security_add_hooks(caitsith_hooks, ARRAY_SIZE(caitsith_hooks), |
| 309 |
|
|
"caitsith"); |
| 310 |
kumaneko |
229 |
#else |
| 311 |
kumaneko |
155 |
security_add_hooks(caitsith_hooks, ARRAY_SIZE(caitsith_hooks)); |
| 312 |
kumaneko |
229 |
#endif |
| 313 |
kumaneko |
235 |
return 0; |
| 314 |
kumaneko |
155 |
} |
| 315 |
kumaneko |
235 |
late_initcall(cs_add_hooks); |
| 316 |
kumaneko |
155 |
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) && defined(CONFIG_SECURITY) */ |