|
18 | 18 |
|
19 | 19 | #include "common.h" |
20 | 20 | #include "cred.h" |
| 21 | +#include "fs.h" |
21 | 22 | #include "ruleset.h" |
22 | 23 | #include "setup.h" |
23 | 24 | #include "task.h" |
@@ -242,12 +243,67 @@ static int hook_unix_may_send(struct socket *const sock, |
242 | 243 | return 0; |
243 | 244 | } |
244 | 245 |
|
| 246 | +static int hook_task_kill(struct task_struct *const p, |
| 247 | + struct kernel_siginfo *const info, const int sig, |
| 248 | + const struct cred *const cred) |
| 249 | +{ |
| 250 | + bool is_scoped; |
| 251 | + const struct landlock_ruleset *dom; |
| 252 | + |
| 253 | + if (cred) { |
| 254 | + /* Dealing with USB IO. */ |
| 255 | + dom = landlock_cred(cred)->domain; |
| 256 | + } else { |
| 257 | + dom = landlock_get_current_domain(); |
| 258 | + } |
| 259 | + |
| 260 | + /* Quick return for non-landlocked tasks. */ |
| 261 | + if (!dom) |
| 262 | + return 0; |
| 263 | + |
| 264 | + rcu_read_lock(); |
| 265 | + is_scoped = domain_is_scoped(dom, landlock_get_task_domain(p), |
| 266 | + LANDLOCK_SCOPE_SIGNAL); |
| 267 | + rcu_read_unlock(); |
| 268 | + if (is_scoped) |
| 269 | + return -EPERM; |
| 270 | + |
| 271 | + return 0; |
| 272 | +} |
| 273 | + |
| 274 | +static int hook_file_send_sigiotask(struct task_struct *tsk, |
| 275 | + struct fown_struct *fown, int signum) |
| 276 | +{ |
| 277 | + const struct landlock_ruleset *dom; |
| 278 | + bool is_scoped = false; |
| 279 | + |
| 280 | + /* Lock already held by send_sigio() and send_sigurg(). */ |
| 281 | + lockdep_assert_held(&fown->lock); |
| 282 | + dom = landlock_file(fown->file)->fown_domain; |
| 283 | + |
| 284 | + /* Quick return for unowned socket. */ |
| 285 | + if (!dom) |
| 286 | + return 0; |
| 287 | + |
| 288 | + rcu_read_lock(); |
| 289 | + is_scoped = domain_is_scoped(dom, landlock_get_task_domain(tsk), |
| 290 | + LANDLOCK_SCOPE_SIGNAL); |
| 291 | + rcu_read_unlock(); |
| 292 | + if (is_scoped) |
| 293 | + return -EPERM; |
| 294 | + |
| 295 | + return 0; |
| 296 | +} |
| 297 | + |
245 | 298 | static struct security_hook_list landlock_hooks[] __ro_after_init = { |
246 | 299 | LSM_HOOK_INIT(ptrace_access_check, hook_ptrace_access_check), |
247 | 300 | LSM_HOOK_INIT(ptrace_traceme, hook_ptrace_traceme), |
248 | 301 |
|
249 | 302 | LSM_HOOK_INIT(unix_stream_connect, hook_unix_stream_connect), |
250 | 303 | LSM_HOOK_INIT(unix_may_send, hook_unix_may_send), |
| 304 | + |
| 305 | + LSM_HOOK_INIT(task_kill, hook_task_kill), |
| 306 | + LSM_HOOK_INIT(file_send_sigiotask, hook_file_send_sigiotask), |
251 | 307 | }; |
252 | 308 |
|
253 | 309 | __init void landlock_add_task_hooks(void) |
|
0 commit comments