From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A7D5B3A0E99 for ; Wed, 5 Aug 2026 19:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785958040; cv=none; b=lHm9W0Fn0ME1lCsq5fGuWxDbinip1kTXtweDXysTbph0oztn3sCYPdj6HZtpyJ/KhY2eZugN6T+rz5OQtb1M4flC/S+vg79+8JZMUM5Pbqe6scWk83023Qv7AbcvwdbuDCeLKwKxz1ZyaQr80r0dAH+ORyNmV0KWZSaM+MOwja0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785958040; c=relaxed/simple; bh=MdfUpg069cpRu/pQf8R0qgvawBLtq8sZIOiMVYcTtLs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jgeCtBiaM7sxQKrnOzut90uVhyD6G9bccQVEDmQf+s+kvBUsVwNXBFlkCEX9J69qlIy9BUf3eFE1TbBFJQTqwulAxLNIRd4AwsRUg8L97AKKq0j/TECjMSBwt0eBeKkuI2PTNE0caajeHucIoOBx4U+lRR8Cr6jZzJNlLUKXws8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CfORdZk9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CfORdZk9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785958038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rpLFUZuDCTZimfHDGge0KE4wEhNdelCfG8JfZJuL8j0=; b=CfORdZk90qtSvaArv2siThCMs1WmwgYqbt+oQlshnR0JTbuTl3T3RXV742SqT8tveI28fz fQzZG3DYlnsaq7Ku4OyOPnBp2spmq/8ch0NPa7LAOQatQsTjsngBhVsjn2zbN+p3T8//ZU NR8WVoua3+E8o/mwBl36DOvZ1/VuqiY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-Tj-wXtunPJaLULfCD8V22A-1; Wed, 05 Aug 2026 15:26:55 -0400 X-MC-Unique: Tj-wXtunPJaLULfCD8V22A-1 X-Mimecast-MFC-AGG-ID: Tj-wXtunPJaLULfCD8V22A_1785958014 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9B4C919560BB; Wed, 5 Aug 2026 19:26:52 +0000 (UTC) Received: from fedora (unknown [10.44.32.54]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id B8C9530001A2; Wed, 5 Aug 2026 19:26:49 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 5 Aug 2026 21:26:52 +0200 (CEST) Date: Wed, 5 Aug 2026 21:26:47 +0200 From: Oleg Nesterov To: Bradley Morgan Cc: brauner@kernel.org, akpm@linux-foundation.org, tglx@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] signal: add a helper for the si_code kernel impersonation check Message-ID: References: <20260706124003.8000-1-include@grrlz.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260706124003.8000-1-include@grrlz.net> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 07/06, Bradley Morgan wrote: > > +/* > + * si_code values >= 0 and SI_TKILL are reserved to the kernel. Not even > + * root can use them to pretend a signal was sent by the kernel or by > + * kill()/tgkill(), except when signaling itself. > + */ > +static bool si_code_reserved_to_kernel(int si_code) > +{ > + return si_code >= 0 || si_code == SI_TKILL; > +} ... > 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) Well, technically this (cosmetic) change is obviouly correct. And I do agree it makes sense to factor out these checks and (more importantly) the comments. But. IMO, the new comment looks a bit worse. The old comment has "impersonate a kill()/tgkill(), which adds source info" and this in fact explains that si_code == 0 or si_code == SI_TKILL come with the real/valid .si_pid and .si_uid and the reciever can trust them. As for the naming... I would like to suggest a better name for the new helper but I can't ;) Oleg.