From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795962889; b=2aj8WR0WOuhEpgvhnew4q/9DCHFUgk1P9hTiStccXDTJ7FjXVIlZy5Uh2a1JLpENfe+c 3WuompwI4PkXvRJNq1faMeYLjfAi7W3XhaK7mfLmVVvYeWKQDf1UGgybh2U5MyDMk0+eD aAm2B83FbnGieqig9IXJIj6KScwU2YdY35nahUhJEDMOXrqI7qHTCCCeeH9t8d9YB2/w8 1ef8BWtA5y1rRA6M4BVEsaoKF0Q87KNdAmpO194QrSyF0qc6rYe52lutu3+4yE4lxZhrY 4UE2ugpZ3na33zRkgfMw+vjOSIMLbBHWJ7eez1YlKj0VVFo7ukrTX/YohQMifb72Yig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795962889; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:Received:Date:From:To:Cc: Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition: X-Scanned-By; bh=sgJIwIeW5ROiNQhbhIh2C9gFg0pKJM3Q5lqW397zsj8=; b=MNMe1qV7/QmyLt9XV37g6sL1wcb/1JR2tqEbZunDTWj71EFZFRbRvZKKkjNbutLCbv71 zapdONsm8e+LMeq++uquEOqXpLUe4AyCxGONQ30LXZ3KOwp5y1JyLB4cCyvtURdV6fMP4 Zf/8eJNFU/QlXtMJngPQdhNyAMONd4SJguK00xsOMlMDVYN6ZrjcLfFp6IClNtOHXz8gD Pgz4qoAIlVScYDmcQxzIKJcG1/PLGpUmVd6Ga73UfqQYyvvDH+Y8Wm8pzCRzjDLisJ2GP DVbnMyPhKRwC8dY/NXESJvAgWDPsLkk2FGK5a4AneQvE9zdJjRB/PX2TNx7VJ2K1iGA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EHyvDjdY; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB382606A323 for ; Sun, 29 Nov 2026 14:34:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB382606A323 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.a=rsa-sha256 header.s=mimecast20190719 header.b=EHyvDjdY DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795962886; 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; bh=sgJIwIeW5ROiNQhbhIh2C9gFg0pKJM3Q5lqW397zsj8=; b=EHyvDjdYh3HD3yfBCZIxq66pgZ2nOfplf5w8hJndAQaPigKqE2ugJeg4/Fu9XWDgfmDkZo 1kbL5SGG0iYW3kCXv7WCpNiqS15JcLnVfWkyll8X8Mvjjwx64e5yqD2kH3noETEkPlipZl rdtAeKEnq2aHMYCYu+fyAvS+Bz4J6Bs= 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-300-xHSb8sHsPOu28IXexAAGsA-1; Sun, 29 Nov 2026 14:34:40 +0000 X-MC-Unique: xHSb8sHsPOu28IXexAAGsA-1 X-Mimecast-MFC-AGG-ID: xHSb8sHsPOu28IXexAAGsA_1795962878 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 7DC7B1956048; Sun, 29 Nov 2026 14:34:38 +0000 (UTC) Received: from onestero-thinkpadp1gen7.tpbc.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 003C0180197D; Sun, 29 Nov 2026 14:34:36 +0000 (UTC) Received: by onestero-thinkpadp1gen7.tpbc.csb (nbSMTP-1.00) for uid 13628 oleg@redhat.com; Sun, 29 Nov 2026 15:34:38 +0100 (CET) Date: Sun, 29 Nov 2026 15:34:35 +0100 From: Oleg Nesterov To: Andrew Morton Cc: Avi Weiss , Christian Brauner , "Eric W . Biederman" , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] signal: fix/simplify .si_signo checks in dequeue_synchronous_signal() Message-ID: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 - Use SI_FROMKERNEL() instead of the open-coded check. - Pre-calculate the unblocked synchronous signal "mask" to avoid checking .si_signo twice. - Use siginmask() instead of sigmask() to avoid shift UB if .si_signo >= SIGRTMIN (on 32-bit, or on MIPS where _NSIG is 128). This can only happen if a task sends a SI_FROMKERNEL RT signal to itself and we could probably disallow this, but siginmask() makes the code cleaner anyway. Signed-off-by: Oleg Nesterov --- kernel/signal.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index dd770e68faee..482db380a498 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -676,21 +676,17 @@ static int dequeue_synchronous_signal(kernel_siginfo_t *info) struct task_struct *tsk = current; struct sigpending *pending = &tsk->pending; struct sigqueue *q, *sync = NULL; + unsigned long mask; - /* - * Might a synchronous signal be in the queue? - */ - if (!((pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK)) + /* Might a synchronous signal be in the queue? */ + mask = (pending->signal.sig[0] & ~tsk->blocked.sig[0]) & SYNCHRONOUS_MASK; + if (!mask) return 0; - /* - * Return the first unblocked synchronous signal in the queue. - */ + /* Return the first synchronous signal in the queue. */ list_for_each_entry(q, &pending->list, list) { - /* Synchronous signals have a positive si_code */ - if ((q->info.si_code > SI_USER) && - (sigmask(q->info.si_signo) & SYNCHRONOUS_MASK) && - !sigismember(&tsk->blocked, q->info.si_signo)) { + if (SI_FROMKERNEL(&q->info) && + siginmask(q->info.si_signo, mask)) { sync = q; goto next; } -- 2.55.0