From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796333408; b=hGDEbNQfXQeazN0ZXJ7ymrrRnvgcWvumbi1KzJKfqMaGJKeffpQL+LRQTIMW9grCKWCX tD6lkO/SC905DINDeGT1kuRppYIf+m8iQXqWGH2D8ocJah2/nzXr1LvAiLfhcbXrABEun btijbo0R96S25xgmL53HAprnmLexvzQAtSRVl5ceRqCYB+FRaHRxpeF0bjK1K+NS6n7qt xlmPtpDwoh7lbU8b02xsFkt5NBNqurWWp4tzhJLiACKH8fOLFqhBnPzDz/3LoIb2aGOQT hrKMbapdEHdEOM5RsxoccuvTRzxzswgkLIQID5X0gH1nGROPvacml7uwGVhb7/PyOpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796333408; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=ZkKMDeamFmoShGi8mcZmWwACgMPppS6U04HVb+fpWm0=; b=2HZHtBJYo6CrGe61DVTl1zXqzM2lDpHu5TNgZZZKh9t/4IbCCdE4bGM2DknvqvXY9Nu8 kiuFishkcC5AVNJMzJW/SmQ3cI7daCWwlVLXOSAJzO1OFcAfchxvl02VlkghycvlYbMI0 ST2aB2phsx06ZJZ3+IML3MJrOHl9mS3jz5SKRqPMkJGv+2JsOiBqR4f5pR+woyik0+Nix Ab1PjwnlOPUhGreweClWUSQwU6QSAw63IdFH5v/xmtLKNsdqlXrHTo49MLZ8LGeTUAXiR Hue3bdWyp5Ig2KO+U1ThjDHBgZ1qBCgJIVL/GKwf+i0ZtpzxRYrRZ3SNnxE0l1HStbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=aZyfqYYP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8E2F606A334 for ; Thu, 3 Dec 2026 21:30:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=aZyfqYYP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 314321F000C2; Thu, 3 Dec 2026 21:30:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796333408; bh=ZkKMDeamFmoShGi8mcZmWwACgMPppS6U04HVb+fpWm0=; h=Date:To:From:In-Reply-To:References:Subject; b=aZyfqYYPT/6s5BahlpCojIALM0V7wWgHa9a/AUMynUieLIFy1VMNtfNAJ3s8GEXEs 7qqC9ZTyaePqoEJNdnUXHVyz5a1jLIuEJpSyq7nocKVuMhWsIVZhTAft21VM9BnXr6 4crGHs0hvSST28TJlh6Is7V1YG+gUJpCvuIJIs5A= Date: Thu, 03 Dec 2026 13:30:07 -0800 To: mm-commits@vger.kernel.org,rafael@kernel.org,pmladek@suse.com, oleg@redhat.com,jcmvbkbc@gmail.com,dmitry.osipenko@collabora.com, chris@zankel.net,afd@ti.com,bradley.morgan@linux.dev, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261126214754.3630965-2-bradley.morgan@linux.dev> References: <20261126214754.3630965-2-bradley.morgan@linux.dev> Subject: + reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data.patch added to mm-nonmm-unstable branch Message-Id: <20261203213008.314321F000C2@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: reboot: fix platform sys_off handler reuse with NULL cb_data has been added to the -mm mm-nonmm-unstable branch. Its filename is reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Bradley Morgan Subject: reboot: fix platform sys_off handler reuse with NULL cb_data Date: Thu, 26 Nov 2026 21:47:53 +0000 Patch series "Fix a few snafus in the reboot code". In reboot, i have found a few small snafus which i have fixed, Patch 1 fixes a small snafu in platform_sys_off_handler, where **IF** a caller passes NULL for cb_data, a second SYS_OFF_PRIO_PLATFORM registration thinks that platform_sys_off_handler is still free, hence, it reuses the **SAME** struct, then links the same notifier_block into two lists at once... Patch 2 also fixes a snafu, where do_kernel_power_off() registers a pm_power_off quickly, and then ends up allocating with GFP_KERNEL or calling synchronize_rcu() with interrupts off and other CPUs stopped. This patch (of 2): In alloc_sys_off_handler(), the check for whether the static platform_sys_off_handler is already in use checks handler->cb_data, which is a weird assumption since cb_data is optional and callers can just pass NULL. If a caller registers at SYS_OFF_PRIO_PLATFORM with NULL cb_data, a second SYS_OFF_PRIO_PLATFORM registration gets the same struct back, overwrites its fields, and links the same notifier_block into another chain while it is still on the first one. For example, on xtensa ISS platform_setup() registers iss_restart and iss_power_off this way, so restarting calls iss_power_off() instead and splices the two lists together if any lower priority poweroff handler is around. To fix this, resolve the mode and list first, keep one static handler per mode in platform_sys_off_handlers[], and check handler->list instead of handler->cb_data so a NULL cb_data cannot slip past -EBUSY. Link: https://lore.kernel.org/20261126214754.3630965-1-bradley.morgan@linux.dev Link: https://patch.msgid.link/20261126214754.3630965-2-bradley.morgan@linux.dev Fixes: 587b9bfe0668 ("kernel/reboot: Use static handler for register_platform_power_off()") Signed-off-by: Bradley Morgan Signed-off-by: Andrew Morton Cc: Rafael J . Wysocki Cc: Dmitry Osipenko Cc: Max Filippov Cc: Chris Zankel Cc: Andrew Davis Cc: Oleg Nesterov Cc: Petr Mladek kernel/reboot.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) --- a/kernel/reboot.c~reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data +++ a/kernel/reboot.c @@ -363,9 +363,11 @@ static int sys_off_notify(struct notifie return handler->sys_off_cb(&data); } -static struct sys_off_handler platform_sys_off_handler; +static struct sys_off_handler + platform_sys_off_handlers[SYS_OFF_MODE_RESTART + 1]; -static struct sys_off_handler *alloc_sys_off_handler(int priority) +static struct sys_off_handler *alloc_sys_off_handler(enum sys_off_mode mode, + int priority) { struct sys_off_handler *handler; gfp_t flags; @@ -375,8 +377,8 @@ static struct sys_off_handler *alloc_sys * at the early boot time because memory allocator isn't available yet. */ if (priority == SYS_OFF_PRIO_PLATFORM) { - handler = &platform_sys_off_handler; - if (handler->cb_data) + handler = &platform_sys_off_handlers[mode]; + if (handler->list) return ERR_PTR(-EBUSY); } else { if (system_state > SYSTEM_RUNNING) @@ -394,7 +396,9 @@ static struct sys_off_handler *alloc_sys static void free_sys_off_handler(struct sys_off_handler *handler) { - if (handler == &platform_sys_off_handler) + if (handler >= platform_sys_off_handlers && + handler < platform_sys_off_handlers + + ARRAY_SIZE(platform_sys_off_handlers)) memset(handler, 0, sizeof(*handler)); else kfree(handler); @@ -428,36 +432,40 @@ register_sys_off_handler(enum sys_off_mo void *cb_data) { struct sys_off_handler *handler; + bool blocking = false; + void *list; int err; - handler = alloc_sys_off_handler(priority); - if (IS_ERR(handler)) - return handler; - switch (mode) { case SYS_OFF_MODE_POWER_OFF_PREPARE: - handler->list = &power_off_prep_handler_list; - handler->blocking = true; + list = &power_off_prep_handler_list; + blocking = true; break; case SYS_OFF_MODE_POWER_OFF: - handler->list = &power_off_handler_list; + list = &power_off_handler_list; break; case SYS_OFF_MODE_RESTART_PREPARE: - handler->list = &restart_prep_handler_list; - handler->blocking = true; + list = &restart_prep_handler_list; + blocking = true; break; case SYS_OFF_MODE_RESTART: - handler->list = &restart_handler_list; + list = &restart_handler_list; break; default: - free_sys_off_handler(handler); return ERR_PTR(-EINVAL); } + handler = alloc_sys_off_handler(mode, priority); + if (IS_ERR(handler)) + return handler; + + handler->list = list; + handler->blocking = blocking; + handler->nb.notifier_call = sys_off_notify; handler->nb.priority = priority; handler->sys_off_cb = callback; _ Patches currently in -mm which might be from bradley.morgan@linux.dev are reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data.patch reboot-register-legacy-pm_power_off-once-at-boot.patch