NetBSD Problem Report #58610

From www@netbsd.org  Fri Aug 16 18:39:22 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 63B151A9242
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 16 Aug 2024 18:39:22 +0000 (UTC)
Message-Id: <20240816183921.28F9C1A9243@mollari.NetBSD.org>
Date: Fri, 16 Aug 2024 18:39:21 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: localcount(9) races with interrupts
X-Send-Pr-Version: www-1.0

>Number:         58610
>Category:       kern
>Synopsis:       localcount(9) races with interrupts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    riastradh
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 16 18:40:00 +0000 2024
>Closed-Date:    Wed Sep 25 14:38:41 +0000 2024
>Last-Modified:  Wed Sep 25 14:38:41 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The localNetBSD Foundation
>Environment:
>Description:
If localcount_acquire, localcount_release, or localcount_xc is interrupted and the interrupt handler also does localcount_acquire or localcount_release, it may lose counts, leading to deadlock or premature free.
>How-To-Repeat:
code inspection
>Fix:
1. Make localcount_adjust (localcount_acquire/release) use atomic_add_64_ni, and localcount_xc use atomic_swap_64_ni, if available and worthwhile (which pretty much means `on x86').
2. Otherwise, use splhigh/splx in localcount_adjust and localcount_xc.

Alternatively, forbid localcount_acquire/release in (soft) interrupt context, but that makes them less useful and I suspect ipsec(4) uses them in soft interrupt context already, if not in hard interrupt context.

>Release-Note:

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58610 CVS commit: src/sys/kern
Date: Fri, 16 Aug 2024 21:54:17 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Fri Aug 16 21:54:17 UTC 2024

 Modified Files:
 	src/sys/kern: subr_localcount.c

 Log Message:
 localcount: Update per-CPU total at splhigh.

 Otherwise localcount_acquire/release in interrupt context may lose
 counts.

 Duration spent at splhigh is very short.

 PR kern/58610: localcount(9) races with interrupts


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.8 src/sys/kern/subr_localcount.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: kern-bug-people->riastradh
Responsible-Changed-By: riastradh@NetBSD.org
Responsible-Changed-When: Fri, 16 Aug 2024 21:57:05 +0000
Responsible-Changed-Why:
mine


State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Fri, 16 Aug 2024 21:57:05 +0000
State-Changed-Why:
Fixed in HEAD -- maybe suboptimal but safe for pullup-9, pullup-10.


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58610 CVS commit: [netbsd-10] src/sys/kern
Date: Wed, 11 Sep 2024 16:24:06 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Wed Sep 11 16:24:05 UTC 2024

 Modified Files:
 	src/sys/kern [netbsd-10]: subr_localcount.c

 Log Message:
 Pull up following revision(s) (requested by rin in ticket #829):

 	sys/kern/subr_localcount.c: revision 1.8

 localcount: Update per-CPU total at splhigh.

 Otherwise localcount_acquire/release in interrupt context may lose
 counts.

 Duration spent at splhigh is very short.
 PR kern/58610: localcount(9) races with interrupts


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.7.36.1 src/sys/kern/subr_localcount.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58610 CVS commit: [netbsd-9] src/sys/kern
Date: Fri, 13 Sep 2024 14:46:27 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Fri Sep 13 14:46:27 UTC 2024

 Modified Files:
 	src/sys/kern [netbsd-9]: subr_localcount.c

 Log Message:
 Pull up following revision(s) (requested by riastradh in ticket #1888):

 	sys/kern/subr_localcount.c: revision 1.8

 localcount: Update per-CPU total at splhigh.
 Otherwise localcount_acquire/release in interrupt context may lose
 counts.

 Duration spent at splhigh is very short.

 PR kern/58610: localcount(9) races with interrupts


 To generate a diff of this commit:
 cvs rdiff -u -r1.7 -r1.7.10.1 src/sys/kern/subr_localcount.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: needs-pullups->closed
State-Changed-By: rin@NetBSD.org
State-Changed-When: Wed, 25 Sep 2024 14:38:41 +0000
State-Changed-Why:
Pulled up to netbsd-10 and -9.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.