From nobody Wed Feb 11 07:48:27 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 0A92E1EDA12 for ; Thu, 6 Feb 2025 15:23: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=1738855436; cv=none; b=BwswBbGWUbhM/+zWw1yF7CUv9Vx3KiPd9BTVm2hzGHBeddSA9awkQ4Cq8W6VX5L6aDJd1u3yI4ObX7AOp0jLKaFKJWHXY2/n/ei/bqpJ+jP5XUES3PvShM8bPqV35/TvjRUyhSzy1IAHlDzsSmOU+QOj0jjgpgBUKUXDi1uglfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738855436; c=relaxed/simple; bh=I2btI8GjiPwCMk/JEmyQ2h9jMFY4yeGon2YPVUu7jF8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G+FxUKs7imVeoNIclmD7Jis8E/8iBtalVoJTq/HqdOS6rxa13/Qk1MAadWTJKWMJLOtXebXB0o7PT7RnR9bVp49Tr8FmqMLRiLY6BEcTbSiRSp0myHd6IVAo3xS19Hcx14JwkIJx9i8ExPOjdlp6/gkRWmnf90+sWWxos6R18p8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=VCAASXct; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="VCAASXct" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738855431; 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=F9s/EWJ61FKw21RNO/44oIGW7uTIX6AKUVt9aZsJ+fc=; b=VCAASXctMhGbrt44EaWn4CfMMCXkCCX51aWVVC/3JONqtJEiTHQGz3CzmH9A65ZpIzJRP+ oWlUsNNqi3eP98nUVwnz5aiQQPvXDmmu2wBhiy+SSVlickMEWRIML/kLWD249R4XOFVpQd LQ1vYQPbQ0Tjp4NNFKMmaEPvKY1zOuk= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-ZPGkF5MBP5SEFkdDy2P2Ig-1; Thu, 06 Feb 2025 10:23:46 -0500 X-MC-Unique: ZPGkF5MBP5SEFkdDy2P2Ig-1 X-Mimecast-MFC-AGG-ID: ZPGkF5MBP5SEFkdDy2P2Ig Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6F651800875; Thu, 6 Feb 2025 15:23:44 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.44.34.53]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 15F8C19560AE; Thu, 6 Feb 2025 15:23:41 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 6 Feb 2025 16:23:18 +0100 (CET) Date: Thu, 6 Feb 2025 16:23:14 +0100 From: Oleg Nesterov To: Andrew Morton , "Eric W. Biederman" , Frederic Weisbecker , Peter Zijlstra , Thomas Gleixner Cc: Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] exit: change the release_task() paths to call flush_sigqueue() lockless Message-ID: <20250206152314.GA14620@redhat.com> References: <20250206152244.GA14609@redhat.com> 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: <20250206152244.GA14609@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A task can block a signal, accumulate up to RLIMIT_SIGPENDING sigqueues, and exit. In this case __exit_signal()->flush_sigqueue() called with irqs disabled can trigger a hard lockup, see https://lore.kernel.org/all/20190322114917.GC28876@redhat.com/ Fortunately, after the recent posixtimer changes sys_timer_delete() paths no longer try to clear SIGQUEUE_PREALLOC and/or free tmr->sigq, and after the exiting task passes __exit_signal() lock_task_sighand() can't succeed and pid_task(tmr->it_pid) will return NULL. This means that after __exit_signal(tsk) nobody can play with tsk->pending or (if group_dead) with tsk->signal->shared_pending, so release_task() can safely call flush_sigqueue() after write_unlock_irq(&tasklist_lock). TODO: - we can probably shift posix_cpu_timers_exit() as well - do_sigaction() can hit the similar problem Signed-off-by: Oleg Nesterov Reviewed-by: Frederic Weisbecker --- kernel/exit.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 3485e5fc499e..2d7444da743d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -200,20 +200,13 @@ static void __exit_signal(struct task_struct *tsk) __unhash_process(tsk, group_dead); write_sequnlock(&sig->stats_lock); =20 - /* - * Do this under ->siglock, we can race with another thread - * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals. - */ - flush_sigqueue(&tsk->pending); tsk->sighand =3D NULL; spin_unlock(&sighand->siglock); =20 __cleanup_sighand(sighand); clear_tsk_thread_flag(tsk, TIF_SIGPENDING); - if (group_dead) { - flush_sigqueue(&sig->shared_pending); + if (group_dead) tty_kref_put(tty); - } } =20 static void delayed_put_task_struct(struct rcu_head *rhp) @@ -279,6 +272,16 @@ void release_task(struct task_struct *p) proc_flush_pid(thread_pid); put_pid(thread_pid); release_thread(p); + /* + * This task was already removed from the process/thread/pid lists + * and lock_task_sighand(p) can't succeed. Nobody else can touch + * ->pending or, if group dead, signal->shared_pending. We can call + * flush_sigqueue() lockless. + */ + flush_sigqueue(&p->pending); + if (thread_group_leader(p)) + flush_sigqueue(&p->signal->shared_pending); + put_task_struct_rcu_user(p); =20 p =3D leader; --=20 2.25.1.362.g51ebf55 From nobody Wed Feb 11 07:48:27 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 B5C6123642A for ; Thu, 6 Feb 2025 15:24:14 +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=1738855457; cv=none; b=jDuUhRAKqfm3v931u60Bruzop3tyUv1dLzB9aOagi258gJXo6pToTy0/ggqHLrazU3V57WFeW9blO1nGEkERYCMpCJPo4Mp6gKnzbUWX04Zst9ANtarRYb9m62zCxTQFaqCFiQkiEsYI/D1sXlWMDkuVmRyKqJc2hx3bnGkultA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738855457; c=relaxed/simple; bh=6DbGvh/FCA96H1xrg9jUU9tSpSLpf+H4C3O3av3+/MM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=joAR89MArprIOZk9Am47xL4iZ1xJoi8+aidgYqCp9eYTHQr0gcT3R8hptoSD6BR6owH36DGnAREOhxEelAYExpQ2En/7lwGCq7Okd+1B7SSApLBdfxbqnw68g1P8+XuysO5zEn4latOcM2Z17+gdaPH6/Fff7GPPOTgP2l17/W8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=hiGNRe19; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none 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="hiGNRe19" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738855453; 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=zI+yoKQYFqNC43fQb7Bn+MO2AksYYcxsUOssleccmqU=; b=hiGNRe19VOpZ5aSwU+Ek1aP+JKxo7d9jCnhSdAeEK68aImvJFwhVofAvSdcM7aYx4Yg7E/ n/Pji5HQcqkuAJChZbo4M4GMJXziiWzQV6ageb7qOrDUUq0BueXeXEjLmFC5P6+crjdaf+ rt1tVgrSFEgOc4PIKF24oEECdctS4sQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-wfw5Qy8GOsSKEjsGiplpHQ-1; Thu, 06 Feb 2025 10:24:07 -0500 X-MC-Unique: wfw5Qy8GOsSKEjsGiplpHQ-1 X-Mimecast-MFC-AGG-ID: wfw5Qy8GOsSKEjsGiplpHQ Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D74BA1801A17; Thu, 6 Feb 2025 15:24:05 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.44.34.53]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 58D081956051; Thu, 6 Feb 2025 15:24:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 6 Feb 2025 16:23:39 +0100 (CET) Date: Thu, 6 Feb 2025 16:23:34 +0100 From: Oleg Nesterov To: Andrew Morton , "Eric W. Biederman" , Frederic Weisbecker , Peter Zijlstra , Thomas Gleixner Cc: Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] exit: kill the pointless __exit_signal()->clear_tsk_thread_flag(TIF_SIGPENDING) Message-ID: <20250206152334.GB14620@redhat.com> References: <20250206152244.GA14609@redhat.com> 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: <20250206152244.GA14609@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It predates the git history and most probably it was never needed. It doesn't really hurt, but it looks confusing because its purpose is not clear at all. release_task(p) is called when this task has already passed exit_notify() so signal_pending(p) =3D=3D T shouldn't make any difference. And even _if_ there were a subtle reason to clear TIF_SIGPENDING after exit_notify(), this clear_tsk_thread_flag() can't help anyway. If the exiting task is a group leader or if it is ptraced, release_task() will be likely called when this task has already done its last schedule() from do_task_dead(). Signed-off-by: Oleg Nesterov Acked-by: Frederic Weisbecker --- kernel/exit.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/exit.c b/kernel/exit.c index 2d7444da743d..0acb94b17caa 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -204,7 +204,6 @@ static void __exit_signal(struct task_struct *tsk) spin_unlock(&sighand->siglock); =20 __cleanup_sighand(sighand); - clear_tsk_thread_flag(tsk, TIF_SIGPENDING); if (group_dead) tty_kref_put(tty); } --=20 2.25.1.362.g51ebf55