From nobody Sat Jul 4 19:55:19 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 6BEA227B35F for ; Sat, 4 Jul 2026 14:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783175694; cv=none; b=VNujH/+zJq8fmE99aiCZAmo9DVq7oLoMs1PDiGrjszJaITcfU90eFAgEiCk9WATrIJ8xXphmgOhSqGJ/IVtHxq9J8BmtwsLzXjhk4R+rWgI0Ekr5k8/e6xnvC/hOgu1OStibL3ERztNkAN6P+6g/dY3jEhmBrk3WNRl5O0pQgBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783175694; c=relaxed/simple; bh=DbsDjkSseoxRxma5s1DSiyJ1QA/5+1nrh6krf/Vhc5o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZTRJ58u0hCFteyxcC6Tru3pNiUYkGF0Pzgk8+TtoREgMllPzMYsD1i7epvCPsEllXcL//oOXflRxwbakZb/sVucQzwXriAW1OmRQnN+Znr9CnzQkRNuP3tMv+qLevOrqj9ugWXq4Xd56EdyJEIjGer98JTmC93EPAkzCNrq5Dlg= 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=N8PFrrJ6; arc=none smtp.client-ip=170.10.129.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="N8PFrrJ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783175691; 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=PLKX6ALi2OTJhVPqw2xw1Uizrkq8wyO7vc5IvkywBS0=; b=N8PFrrJ6ywLnpTkiGGMdZwcJI6ph7w/xF+lK2sSI7dCkk2fhV3Xf26xKCMInNAt4n+kH6v GWJpvfRLcmhu2Oxy4CMP/GlpRIOl0Mw3YZTX65SFtGpeUA+eZbki5+S/sH6dRsdoIb6H4K Lq+0IUjaguCQxFSklPlJPm4M4ohAzVM= 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-65-1PUCb7VSN6S_v3XYYpeg-w-1; Sat, 04 Jul 2026 10:34:47 -0400 X-MC-Unique: 1PUCb7VSN6S_v3XYYpeg-w-1 X-Mimecast-MFC-AGG-ID: 1PUCb7VSN6S_v3XYYpeg-w_1783175686 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 5926D1956047; Sat, 4 Jul 2026 14:34:46 +0000 (UTC) Received: from fedora (unknown [10.44.32.112]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 5EF761800370; Sat, 4 Jul 2026 14:34:44 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 4 Jul 2026 16:34:45 +0200 (CEST) Date: Sat, 4 Jul 2026 16:34:42 +0200 From: Oleg Nesterov To: Andrew Morton Cc: Bradley Morgan , Christian Brauner , "Eric W. Biederman" , linux-kernel@vger.kernel.org Subject: [PATCH -mm 1/1] signal: avoid unconditional siginfo copy in send_signal_locked() Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" send_signal_locked() unconditionally copies siginfo before the namespace translation to avoid corrupting a shared siginfo. Not that I think this can actually hurt performance-wise, just it doesn't look clean to me; the copy is only needed in the unlikely case when the translation will actually change something. Defer it to the two cases where si_pid/si_uid are rewritten, and while at it add #ifdef's just for completeness. Signed-off-by: Oleg Nesterov Reviewed-by: Bradley Morgan --- kernel/signal.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 041498ff835e..0f509ee4f42d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1181,7 +1181,7 @@ static inline bool has_si_pid_and_uid(struct kernel_s= iginfo *info) int send_signal_locked(int sig, struct kernel_siginfo *info, struct task_struct *t, enum pid_type type) { - struct kernel_siginfo rewritten; + struct kernel_siginfo __maybe_unused rewritten; /* Should SIGKILL or SIGSTOP be received by a pid namespace init? */ bool force =3D false; =20 @@ -1193,27 +1193,34 @@ int send_signal_locked(int sig, struct kernel_sigin= fo *info, force =3D true; } else if (has_si_pid_and_uid(info)) { /* SIGKILL and SIGSTOP is special or has ids */ +#ifdef CONFIG_USER_NS struct user_namespace *t_user_ns; - - rewritten =3D *info; - info =3D &rewritten; + kuid_t uid; =20 rcu_read_lock(); t_user_ns =3D task_cred_xxx(t, user_ns); if (current_user_ns() !=3D t_user_ns) { - kuid_t uid =3D make_kuid(current_user_ns(), info->si_uid); - info->si_uid =3D from_kuid_munged(t_user_ns, uid); + rewritten =3D *info; + info =3D &rewritten; + uid =3D make_kuid(current_user_ns(), info->si_uid); + rewritten.si_uid =3D from_kuid_munged(t_user_ns, uid); } rcu_read_unlock(); - +#endif /* A kernel generated signal? */ force =3D (info->si_code =3D=3D SI_KERNEL); =20 +#ifdef CONFIG_PID_NS /* From an ancestor pid namespace? */ if (!task_pid_nr_ns(current, task_active_pid_ns(t))) { - info->si_pid =3D 0; + if (info !=3D &rewritten) { + rewritten =3D *info; + info =3D &rewritten; + } + rewritten.si_pid =3D 0; force =3D true; } +#endif } return __send_signal_locked(sig, info, t, type, force); } --=20 2.52.0