^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/fdtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kcmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/eventpoll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * We don't expose the real in-memory order of objects for security reasons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * But still the comparison results should be suitable for sorting. So we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * obfuscate kernel pointers values and compare the production instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * The obfuscation is done in two steps. First we xor the kernel pointer with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * a random value, which puts pointer into a new position in a reordered space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Secondly we multiply the xor production with a large odd random number to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * permute its bits even more (the odd multiplier guarantees that the product
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * is unique ever after the high bits are truncated, since any odd number is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * relative prime to 2^n).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Note also that the obfuscation itself is invisible to userspace and if needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * it can be changed to an alternate scheme.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static unsigned long cookies[KCMP_TYPES][2] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static long kptr_obfuscate(long v, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return (v ^ cookies[type][0]) * cookies[type][1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * 0 - equal, i.e. v1 = v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * 1 - less than, i.e. v1 < v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * 2 - greater than, i.e. v1 > v2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * 3 - not equal but ordering unavailable (reserved for future)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int kcmp_ptr(void *v1, void *v2, enum kcmp_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) long t1, t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) t1 = kptr_obfuscate((long)v1, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) t2 = kptr_obfuscate((long)v2, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return (t1 < t2) | ((t1 > t2) << 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /* The caller must have pinned the task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static struct file *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) get_file_raw_ptr(struct task_struct *task, unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct file *file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) task_lock(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (task->files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) file = fcheck_files(task->files, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) task_unlock(task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static void kcmp_unlock(struct rw_semaphore *l1, struct rw_semaphore *l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (likely(l2 != l1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) up_read(l2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) up_read(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int kcmp_lock(struct rw_semaphore *l1, struct rw_semaphore *l2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (l2 > l1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) swap(l1, l2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) err = down_read_killable(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!err && likely(l1 != l2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) err = down_read_killable_nested(l2, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) up_read(l1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef CONFIG_EPOLL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int kcmp_epoll_target(struct task_struct *task1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct task_struct *task2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned long idx1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct kcmp_epoll_slot __user *uslot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct file *filp, *filp_epoll, *filp_tgt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct kcmp_epoll_slot slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct files_struct *files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (copy_from_user(&slot, uslot, sizeof(slot)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) filp = get_file_raw_ptr(task1, idx1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (!filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) files = get_files_struct(task2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (!files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) spin_lock(&files->file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) filp_epoll = fcheck_files(files, slot.efd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (filp_epoll)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) get_file(filp_epoll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) filp_tgt = ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) spin_unlock(&files->file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) put_files_struct(files);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (filp_epoll) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) filp_tgt = get_epoll_tfile_raw_ptr(filp_epoll, slot.tfd, slot.toff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) fput(filp_epoll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (IS_ERR(filp_tgt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return PTR_ERR(filp_tgt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return kcmp_ptr(filp, filp_tgt, KCMP_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int kcmp_epoll_target(struct task_struct *task1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct task_struct *task2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) unsigned long idx1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct kcmp_epoll_slot __user *uslot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned long, idx1, unsigned long, idx2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct task_struct *task1, *task2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Tasks are looked up in caller's PID namespace only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) task1 = find_task_by_vpid(pid1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) task2 = find_task_by_vpid(pid2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (!task1 || !task2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) goto err_no_task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) get_task_struct(task1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) get_task_struct(task2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * One should have enough rights to inspect task details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ret = kcmp_lock(&task1->signal->exec_update_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) &task2->signal->exec_update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (!ptrace_may_access(task1, PTRACE_MODE_READ_REALCREDS) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) !ptrace_may_access(task2, PTRACE_MODE_READ_REALCREDS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ret = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) goto err_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case KCMP_FILE: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct file *filp1, *filp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) filp1 = get_file_raw_ptr(task1, idx1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) filp2 = get_file_raw_ptr(task2, idx2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (filp1 && filp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ret = kcmp_ptr(filp1, filp2, KCMP_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ret = -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case KCMP_VM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ret = kcmp_ptr(task1->mm, task2->mm, KCMP_VM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case KCMP_FILES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ret = kcmp_ptr(task1->files, task2->files, KCMP_FILES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) case KCMP_FS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) ret = kcmp_ptr(task1->fs, task2->fs, KCMP_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case KCMP_SIGHAND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) ret = kcmp_ptr(task1->sighand, task2->sighand, KCMP_SIGHAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) case KCMP_IO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ret = kcmp_ptr(task1->io_context, task2->io_context, KCMP_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) case KCMP_SYSVSEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #ifdef CONFIG_SYSVIPC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) ret = kcmp_ptr(task1->sysvsem.undo_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) task2->sysvsem.undo_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) KCMP_SYSVSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case KCMP_EPOLL_TFD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ret = kcmp_epoll_target(task1, task2, idx1, (void *)idx2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) err_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) kcmp_unlock(&task1->signal->exec_update_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) &task2->signal->exec_update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) put_task_struct(task1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) put_task_struct(task2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) err_no_task:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static __init int kcmp_cookies_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) get_random_bytes(cookies, sizeof(cookies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) for (i = 0; i < KCMP_TYPES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) cookies[i][1] |= (~(~0UL >> 1) | 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) arch_initcall(kcmp_cookies_init);