From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796491944; b=HUFK/tLBum8KnZFLW3jhnJqcsUi2C8QWASog0tF6waFn0/CkWUr7hgNiKe0biQFDiz6l 7CAiduFLZjZ7To6FC1Sftean2xk60JNmKJ1AS/c8fpQRb5p6JdIqv2YW5cD9cYSvUiZx6 u1ybQa8Z4aizRDh/3FX9t1oekbq+tXU/uwwCgEsHfsqlVXJeQi3Qv1Jhchi1193LPjq6r SY5fRFLGLq1p+kBFErOubLkV+AyGe8nf5oDvl++LhCq4Mhhujhapt6jLI+ueusZBpUKms XQ3i7McNoGkXaqlFTPxCZAmAOkh9ZAUi7jBcnnO3rpe85GbAA9omCbb4Rn54zsGpqxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796491944; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=zxtGPsgQILOAkZF/F32p7MqGnP/cxCAXKwQ1Ei5yc8o=; b=WJFHOWpZLHcC9xBKgcRuj+ZyJG8sKCRwYpGxuSminstVhjPlyrZNv73N4j3bX4jhSONC mQSRtV3jEAnDTwoIc0UBsiiNceaRdyG6+2ExpJ/CiLyx9gsF9p3a8xzR6U6apkzH3Onr7 Tx+dDOt7xajSM+IADUTx3Ri0NxrFwD0/zcpec4VuMmGayfVLA7EH8AoIKmjNTkpsUeDx7 +0ovDaBgGuXGICF3BG/aK/IdvYnzKFnKcgqXVdXgh4YuT0rinjl4JC9frwWmTEFNGBsMI iR78MPcAN7eCbHlPsZLc7wfZSDEOj8Ac+TxHwtIYvazB8W6S3Hmgel5ji3ACQavvx8g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=X2FsplbR; arc=none smtp.remote-ip=209.85.216.71 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D496E606A339 for ; Sat, 5 Dec 2026 17:32:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D496E606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=X2FsplbR Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-3b60de2726bso1370506a91.3 for ; Sat, 05 Dec 2026 09:32:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796491943; x=1797096743; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zxtGPsgQILOAkZF/F32p7MqGnP/cxCAXKwQ1Ei5yc8o=; b=X2FsplbRAjAhAPcujAVR6KUvdL48TDyK3uePojJMRogpHq/KWriJqJRDmCFFB1Lo15 Q+P+pImdT4ELUYc0LLmkS9bPDKA/X/qgkNVxRzapNtWVT8bLvovQUQDN3+Tv19pqIbOS mmIH6jpXuT1H3IJ9+iA60/tjoRLJst6U353HVKf++j1H/mNWUaSfERt05hsJ1BFdscpV fNtI0GwhNuPuVUrIIEKXCNRTz1VXT4E1fkZ7vpleXYD28al30Q1qKRBep1No2M7dRjZe Y4cNH7DN/J7GLF7UCwqK+Ooue/jhygGeEkjzqe42ZiG5ugThXX+TMSF6dhe2jEzyrxqB xyyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796491943; x=1797096743; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zxtGPsgQILOAkZF/F32p7MqGnP/cxCAXKwQ1Ei5yc8o=; b=ZiciFh3Xgfz8JKyRsTeDtNQCv5XQthRG09KmQndl9O8tafEDJ4QVVYnedsHuDZtBcp Qu+DdCw/qOfcXyQ8YqBRpPQlC9TDwLQkzBq95NNUoqHXIDWUspE8+6uoHrqPZEr/BbWq 4Y8DhGkwjcTX0ARwiRS7V6NwUOUFmMS/KLHLV7Lo/3zSRDNDThzWinfpGSz54iQ34Q+z 2C0GnJCTVhdWniSYczaDASsERSDpKv7mkIqq8jeHphdXuchLoSwroN3gdXo59FC1nCq4 7Ikxq6wAYj3P4ddcip7Wfhm0sICcBDqUopQXBOJUxUWkU8lBSSt9rLH4BlirP+MLft/c OABQ== X-Forwarded-Encrypted: i=1; AL+hErFPTn7z3gDlNLzcYYusLjHc7waywvoOLULED74SimGsLadxup1I2zEpmXDGV/+tMDlk8Z/itJaq23qc72o=@vger.kernel.org X-Gm-Message-State: AB4q+uFMnCXQYcWUeKlZJ/dkyewZBIhOn3/4YTdZ9QtdODuydHV9J4Jm WPlUy23+d2bhXJ1L1ItgqN37Zo9e2g8Ena4DlzGpctO1GPFt4U3aT2MbXvdRx0rSS8XKgedH+gs jyVPGTLp375p6xnK1mZ41ym7fdMCnEQ== X-Received: from pjl15.prod.google.com ([2002:a17:90b:2f8f:b0:3b5:2f80:73c9]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d88:b0:3b4:1c0c:6863 with SMTP id 98e67ed59e1d1-3b5e046a36cmr4942185a91.0.1796491943071; Sat, 05 Dec 2026 09:32:23 -0800 (PST) Date: Sat, 5 Dec 2026 17:32:22 +0000 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 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261205173222.233754-1-zhenwenliang@google.com> Subject: [PATCH] umh: restore the full barrier in __usermodehelper_disable() From: Zhenwen Liang To: Luis Chamberlain , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" __usermodehelper_disable() stores usermodehelper_disabled, then reads running_helpers; call_usermodehelper_exec() increments running_helpers, issues smp_mb__after_atomic(), then reads usermodehelper_disabled. up_write() is only a release, so on weakly ordered CPUs (not x86) the disable side can report that no helper is running while a helper is still queued afterwards. This has not been reproduced. The smp_mb() after the store, added by commit ccd4b65aef4b ("PM: prevent frozen user mode helpers from failing the freezing of tasks"), was lost when the store was moved under umhelper_sem. Restore it, and use WRITE_ONCE()/READ_ONCE() for the store and the lockless check. The problem was found, and this patch prepared, with the help of a formal analysis tool we are developing that uses AI assistance; I have reviewed the analysis and the patch. Fixes: b298d289c792 ("PM / Sleep: Fix freezer failures due to racy usermodehelper_is_disabled()") Signed-off-by: Zhenwen Liang --- Compile-tested only (arm64, W=1). The barrier is only on the suspend, hibernate and shutdown path. The requirement was stated in the 2007 review: https://lore.kernel.org/all/20070625104332.GA147@tv-sign.ru/ kernel/umh.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/umh.c b/kernel/umh.c index 512dc01..610ede7 100644 --- a/kernel/umh.c +++ b/kernel/umh.c @@ -296,8 +296,10 @@ int __usermodehelper_disable(enum umh_disable_depth depth) return -EINVAL; down_write(&umhelper_sem); - usermodehelper_disabled = depth; + WRITE_ONCE(usermodehelper_disabled, depth); up_write(&umhelper_sem); + /* Pairs with smp_mb__after_atomic() in helper_lock() */ + smp_mb(); /* * From now on call_usermodehelper_exec() won't start any new @@ -407,7 +409,7 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait) return -EINVAL; } helper_lock(); - if (usermodehelper_disabled) { + if (READ_ONCE(usermodehelper_disabled)) { retval = -EBUSY; goto out; }