From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from devianza.investici.org (devianza.investici.org [198.167.222.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C90C2374E42 for ; Thu, 6 Aug 2026 13:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.167.222.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786023019; cv=none; b=Cv9NXZCpLtpwq6ldq3f6ompFUXRK7fdZWzFkjK8PThpTpKi5JmAp55QNV0SENwFiYfeLCLgSUZuagegN6h2hPJRuHBf9Zd4dsZb5qM+l7F7xePU3GqUVGZYZafiFg/Zoe38O6dRHBNxhy/T/sFJeVdM3szDMDdx6Mh5O1QwtoVE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786023019; c=relaxed/simple; bh=gtFHU850F0JB+wU1WNxg+1xiT1ISABWA/8vUS0fq3Zs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=F7QxZ3yM+Pzga15MWMY9CxEMzCDAGj4Es2NltxmLJsvDzJMlgu6iRigTYUlszVfzronxTFVthXdC+mzRwV8i/lT4W9j0izKHi70sD4J+x4jJfrI0J626jHImefTWhlWCaLAZ72Vhqs1qHQ2Tguuq5J8+jGQ4ap6aXFezU7qumYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net; spf=pass smtp.mailfrom=grrlz.net; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b=BkdDuy++; arc=none smtp.client-ip=198.167.222.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grrlz.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b="BkdDuy++" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grrlz.net; s=stigmate; t=1786023013; bh=QoSlv8mLChWpnU7CGYm5o7FCFqDLdbO7t5CEQp7VNmU=; h=From:To:Cc:Subject:Date:From; b=BkdDuy++Nl6XV7nx2ApHcxfZF4fzLIeCyHZ0CA8CLXsCNnzKYiUmU7M48CoN9mRCM MPk/sYLFigLHPz62oq3u5AzSDt5VeXDj3B1hagCOHXGnDkd6wt5L7NoSrm8xfLe3Tx 6F+IyNizfti7JRI8uSmMFa0XujTNZSUTNZdI70U0= Received: from mx2.investici.org (unknown [127.0.0.1]) by devianza.investici.org (Postfix) with UTF8SMTP id 4hG7SP34fkz6vfb; Thu, 06 Aug 2026 13:30:13 +0000 (UTC) Received: by mx2.investici.org (Postfix) id 4hG7SN71F1z4y43; Thu, 06 Aug 2026 13:30:12 +0000 (UTC) From: Bradley Morgan To: Oleg Nesterov Cc: Andrew Morton , Christian Brauner , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH v2] signal: factor out the kernel reserved si_code check Date: Thu, 6 Aug 2026 13:30:13 +0000 Message-ID: <20260806133013.4341-1-include@grrlz.net> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The check that prevents userspace from sending siginfo with si_code values reserved to the kernel is duplicated across do_rt_sigqueueinfo(), do_rt_tgsigqueueinfo() and do_pidfd_send_signal(). Move the check into a helper so the rule lives in one place. Signed-off-by: Bradley Morgan --- Changes since v1: - use the wording Oleg suggested for the comment kernel/signal.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index fdee0b012a11..a5e15bf09d31 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3944,6 +3944,15 @@ static void prepare_kill_siginfo(int sig, struct kernel_siginfo *info, info->si_uid = from_kuid_munged(current_user_ns(), current_uid()); } +/* + * Not even root can pretend to send SI_FROMKERNEL() signals. + * Nor can they impersonate kill()/tgkill(), which have si_pid/uid + */ +static bool si_code_reserved_to_kernel(int si_code) +{ + return si_code >= 0 || si_code == SI_TKILL; +} + /** * sys_kill - send a signal to a process * @pid: the PID of the process @@ -4035,7 +4044,7 @@ static int do_pidfd_send_signal(struct pid *pid, int sig, enum pid_type type, /* Only allow sending arbitrary signals to yourself. */ if ((task_pid(current) != pid || type > PIDTYPE_TGID) && - (kinfo.si_code >= 0 || kinfo.si_code == SI_TKILL)) + si_code_reserved_to_kernel(kinfo.si_code)) return -EPERM; } else { prepare_kill_siginfo(sig, &kinfo, type); @@ -4190,11 +4199,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, sig) static int do_rt_sigqueueinfo(pid_t pid, int sig, kernel_siginfo_t *info) { - /* Not even root can pretend to send signals from the kernel. - * Nor can they impersonate a kill()/tgkill(), which adds source info. - */ - if ((info->si_code >= 0 || info->si_code == SI_TKILL) && - (task_pid_vnr(current) != pid)) + if (si_code_reserved_to_kernel(info->si_code) && + task_pid_vnr(current) != pid) return -EPERM; /* POSIX.1b doesn't mention process groups. */ @@ -4237,11 +4243,8 @@ static int do_rt_tgsigqueueinfo(pid_t tgid, pid_t pid, int sig, kernel_siginfo_t if (pid <= 0 || tgid <= 0) return -EINVAL; - /* Not even root can pretend to send signals from the kernel. - * Nor can they impersonate a kill()/tgkill(), which adds source info. - */ - if ((info->si_code >= 0 || info->si_code == SI_TKILL) && - (task_pid_vnr(current) != pid)) + if (si_code_reserved_to_kernel(info->si_code) && + task_pid_vnr(current) != pid) return -EPERM; return do_send_specific(tgid, pid, sig, info); -- 2.47.3