Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9979755ybi; Wed, 24 Jul 2019 13:27:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyuZSyc5GTj6wlet9Ol6sL+dLQNFfZYhljsXR/pGh+2+yQXAFm1keMD+u2ISn6De4ZWigY8 X-Received: by 2002:a62:7d13:: with SMTP id y19mr13049232pfc.62.1564000032773; Wed, 24 Jul 2019 13:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564000032; cv=none; d=google.com; s=arc-20160816; b=l7y5xzXqz2c9Q3536zk5hGRPiLiHqOQmKEaw+1Aj1T01abXTIrN3hoBkTwTmaaPTQR sUA/CPzZpWhN/Ci6ZhS+q/24vY5b1aKCIk8uhiRHHLAjv1KuLcrmc02rdIdLDuAJ73aU v7WUBdc1AMfSD3z6UmEea+d4Ih4i7hWwXrRw6rnBAkVXLP/2UAcGr5S+TJhJF290OaL6 ItfMSAaKxU5h57xQL/MnlFviDxEhZGl0kFbjR0kYC8AtrHb+aKgWLTYo5IybX+Jnxzz1 00wuSNcYxAm3Nj7VLo4qZ/Ki0pM167LWG5rB2GuOIO3ViNA5SHrDwASKbNmoS4W4dmEB h62Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ciWGSCueysEo5y4U+G/S1m5mD3SPnzQDOTAZB0s67hw=; b=z9WFj+DKmzBgVR32ieuV63TDm6DW98UTESXpa7ERqWmkzXtPcqJIWFMkIBR4ZrlDvD LYXVzvQQhC8g7So1astT4GFErAPSPIX5Af0DdDyhnNfN4GWdXGOCMz4g7wX4hfJ5avGe SXONf1RPT6QE0Cdm0/KIzuzUL33TEMD/5ZdTKW6G7FFv9ZzS9SSdFNb1QNdcXMlnfM5i N8+hOkCOCeKPidRaVRdpOp52CYHXZ+etCnV0GOfO0q4cXvBu3qWUEk/+byQzOgNPI1BU ffZtAKLly5rtAxtF0DelVxRp99Fogh5f01RT/EG0jeZdU+M58+FKupCO10E6Mhm49m8i JHDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VHLnPCCW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v141si19406609pgb.183.2019.07.24.13.26.58; Wed, 24 Jul 2019 13:27:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VHLnPCCW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389673AbfGXTjn (ORCPT + 99 others); Wed, 24 Jul 2019 15:39:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:40726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389652AbfGXTjj (ORCPT ); Wed, 24 Jul 2019 15:39:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 205E520665; Wed, 24 Jul 2019 19:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997178; bh=K99YGqzcYsRpCLhamngDaWBaSL9BRD0VjzWdGyWWLWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VHLnPCCWYPd4o7X5dBgvz6fW0tKlfsDLHv9b0adOd40166OfK1RoRB3gjx4Ebm+lE GvAbBcHetKpSKxFs9TKbkMXEdxlL90BJNp4pJH3oOwN2RJ37vcoh3zDM+gxHaLbT2Z EzlDkpCGqUaM1OWQFiKMkmy2rMdp2Q+uA5ssmHpY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Eric W. Biederman" Subject: [PATCH 5.2 341/413] signal: Correct namespace fixups of si_pid and si_uid Date: Wed, 24 Jul 2019 21:20:32 +0200 Message-Id: <20190724191800.223326080@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric W. Biederman commit 7a0cf094944e2540758b7f957eb6846d5126f535 upstream. The function send_signal was split from __send_signal so that it would be possible to bypass the namespace logic based upon current[1]. As it turns out the si_pid and the si_uid fixup are both inappropriate in the case of kill_pid_usb_asyncio so move that logic into send_signal. It is difficult to arrange but possible for a signal with an si_code of SI_TIMER or SI_SIGIO to be sent across namespace boundaries. In which case tests for when it is ok to change si_pid and si_uid based on SI_FROMUSER are incorrect. Replace the use of SI_FROMUSER with a new test has_si_pid_and_used based on siginfo_layout. Now that the uid fixup is no longer present after expanding SEND_SIG_NOINFO properly calculate the si_uid that the target task needs to read. [1] 7978b567d315 ("signals: add from_ancestor_ns parameter to send_signal()") Cc: stable@vger.kernel.org Fixes: 6588c1e3ff01 ("signals: SI_USER: Masquerade si_pid when crossing pid ns boundary") Fixes: 6b550f949594 ("user namespace: make signal.c respect user namespaces") Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- kernel/signal.c | 67 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 27 deletions(-) --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1057,27 +1057,6 @@ static inline bool legacy_queue(struct s return (sig < SIGRTMIN) && sigismember(&signals->signal, sig); } -#ifdef CONFIG_USER_NS -static inline void userns_fixup_signal_uid(struct kernel_siginfo *info, struct task_struct *t) -{ - if (current_user_ns() == task_cred_xxx(t, user_ns)) - return; - - if (SI_FROMKERNEL(info)) - return; - - rcu_read_lock(); - info->si_uid = from_kuid_munged(task_cred_xxx(t, user_ns), - make_kuid(current_user_ns(), info->si_uid)); - rcu_read_unlock(); -} -#else -static inline void userns_fixup_signal_uid(struct kernel_siginfo *info, struct task_struct *t) -{ - return; -} -#endif - static int __send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, enum pid_type type, int from_ancestor_ns) { @@ -1135,7 +1114,11 @@ static int __send_signal(int sig, struct q->info.si_code = SI_USER; q->info.si_pid = task_tgid_nr_ns(current, task_active_pid_ns(t)); - q->info.si_uid = from_kuid_munged(current_user_ns(), current_uid()); + rcu_read_lock(); + q->info.si_uid = + from_kuid_munged(task_cred_xxx(t, user_ns), + current_uid()); + rcu_read_unlock(); break; case (unsigned long) SEND_SIG_PRIV: clear_siginfo(&q->info); @@ -1147,13 +1130,8 @@ static int __send_signal(int sig, struct break; default: copy_siginfo(&q->info, info); - if (from_ancestor_ns) - q->info.si_pid = 0; break; } - - userns_fixup_signal_uid(&q->info, t); - } else if (!is_si_special(info)) { if (sig >= SIGRTMIN && info->si_code != SI_USER) { /* @@ -1197,6 +1175,28 @@ ret: return ret; } +static inline bool has_si_pid_and_uid(struct kernel_siginfo *info) +{ + bool ret = false; + switch (siginfo_layout(info->si_signo, info->si_code)) { + case SIL_KILL: + case SIL_CHLD: + case SIL_RT: + ret = true; + break; + case SIL_TIMER: + case SIL_POLL: + case SIL_FAULT: + case SIL_FAULT_MCEERR: + case SIL_FAULT_BNDERR: + case SIL_FAULT_PKUERR: + case SIL_SYS: + ret = false; + break; + } + return ret; +} + static int send_signal(int sig, struct kernel_siginfo *info, struct task_struct *t, enum pid_type type) { @@ -1206,7 +1206,20 @@ static int send_signal(int sig, struct k from_ancestor_ns = si_fromuser(info) && !task_pid_nr_ns(current, task_active_pid_ns(t)); #endif + if (!is_si_special(info) && has_si_pid_and_uid(info)) { + struct user_namespace *t_user_ns; + + rcu_read_lock(); + t_user_ns = task_cred_xxx(t, user_ns); + if (current_user_ns() != t_user_ns) { + kuid_t uid = make_kuid(current_user_ns(), info->si_uid); + info->si_uid = from_kuid_munged(t_user_ns, uid); + } + rcu_read_unlock(); + if (!task_pid_nr_ns(current, task_active_pid_ns(t))) + info->si_pid = 0; + } return __send_signal(sig, info, t, type, from_ancestor_ns); }