Fix common misspellings
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / signal.c
index 4e3cff10fdceda165e8e9f22c0e9b861dba918d8..f486d10f3b8e889626e3fe2308b195e956735767 100644 (file)
@@ -635,6 +635,27 @@ static inline bool si_fromuser(const struct siginfo *info)
                (!is_si_special(info) && SI_FROMUSER(info));
 }
 
+/*
+ * called with RCU read lock from check_kill_permission()
+ */
+static int kill_ok_by_cred(struct task_struct *t)
+{
+       const struct cred *cred = current_cred();
+       const struct cred *tcred = __task_cred(t);
+
+       if (cred->user->user_ns == tcred->user->user_ns &&
+           (cred->euid == tcred->suid ||
+            cred->euid == tcred->uid ||
+            cred->uid  == tcred->suid ||
+            cred->uid  == tcred->uid))
+               return 1;
+
+       if (ns_capable(tcred->user->user_ns, CAP_KILL))
+               return 1;
+
+       return 0;
+}
+
 /*
  * Bad permissions for sending the signal
  * - the caller must hold the RCU read lock
@@ -642,7 +663,6 @@ static inline bool si_fromuser(const struct siginfo *info)
 static int check_kill_permission(int sig, struct siginfo *info,
                                 struct task_struct *t)
 {
-       const struct cred *cred, *tcred;
        struct pid *sid;
        int error;
 
@@ -656,14 +676,8 @@ static int check_kill_permission(int sig, struct siginfo *info,
        if (error)
                return error;
 
-       cred = current_cred();
-       tcred = __task_cred(t);
        if (!same_thread_group(current, t) &&
-           (cred->euid ^ tcred->suid) &&
-           (cred->euid ^ tcred->uid) &&
-           (cred->uid  ^ tcred->suid) &&
-           (cred->uid  ^ tcred->uid) &&
-           !capable(CAP_KILL)) {
+           !kill_ok_by_cred(t)) {
                switch (sig) {
                case SIGCONT:
                        sid = task_session(t);
@@ -1871,7 +1885,7 @@ relock:
        for (;;) {
                struct k_sigaction *ka;
                /*
-                * Tracing can induce an artifical signal and choose sigaction.
+                * Tracing can induce an artificial signal and choose sigaction.
                 * The return value in @signr determines the default action,
                 * but @info->si_signo is the signal number we will report.
                 */
@@ -2421,9 +2435,13 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, pid, int, sig,
                return -EFAULT;
 
        /* Not even root can pretend to send signals from the kernel.
-          Nor can they impersonate a kill(), which adds source info.  */
-       if (info.si_code >= 0)
+        * Nor can they impersonate a kill()/tgkill(), which adds source info.
+        */
+       if (info.si_code >= 0 || info.si_code == SI_TKILL) {
+               /* We used to allow any < 0 si_code */
+               WARN_ON_ONCE(info.si_code < 0);
                return -EPERM;
+       }
        info.si_signo = sig;
 
        /* POSIX.1b doesn't mention process groups.  */
@@ -2437,9 +2455,13 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, siginfo_t *info)
                return -EINVAL;
 
        /* Not even root can pretend to send signals from the kernel.
-          Nor can they impersonate a kill(), which adds source info.  */
-       if (info->si_code >= 0)
+        * Nor can they impersonate a kill()/tgkill(), which adds source info.
+        */
+       if (info->si_code >= 0 || info->si_code == SI_TKILL) {
+               /* We used to allow any < 0 si_code */
+               WARN_ON_ONCE(info->si_code < 0);
                return -EPERM;
+       }
        info->si_signo = sig;
 
        return do_send_specific(tgid, pid, sig, info);