From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 03A1A33A9F8 for ; Mon, 27 Jul 2026 23:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785193675; cv=none; b=VeFCuggntKMlh9vCHw1HeADdLg8zBlGFflmay5M5kJMhB8O6Uw7PAIfsHk4fEHdp7fC51CYw9x1g3lk0mEJ8G6hVNJmlUKmIb/by/lAuVjf07aajWGayKSz+Z/sqQ/QZYGmrHjRXoJRsh+UJTgYFe5lrAn63GmbqLMlLul0fCUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785193675; c=relaxed/simple; bh=sopkOIuzSCB4T8MmzuHSi7+aLFRjOEjAmlanHKIzDpk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=RTv4aOgNkOq2i+JdhNah6yiMvD2NN8g3ZHacW5jQKIaNXu7m3R+tmMBx4Wtdp0wRsjAknxU7rF8BWwVpHZshIO/CNarxH2ImRQx0qXnrUaHVtvvD1c/TXrWeZS/OM3G4p8q+BA9Xr29YNDZBUPMMKrMBqNAAS5DbAUazcpQhMNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=K6jn3QwN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="K6jn3QwN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 752E51F000E9; Mon, 27 Jul 2026 23:07:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1785193673; bh=GIHVTWFhHFMaz6emts1ykQvNesc/DEj4O+gFfir0o7I=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=K6jn3QwN74u+VQY8D5quCxl1UG5UBZI41rdgVOBjKeV74nsnYCN/gWQ0OLmplCRtc bEymWPO0ZlcNJtq+t5cMf2i9nHkuXQqzCgxmiiBXZh/pScsrru1FDUqfLavFCvwlmy 98ZHJRg/Ib/0Xccv33AqM+pdWYo21+PUT6Pfm9Kk= Date: Mon, 27 Jul 2026 16:07:53 -0700 From: Andrew Morton To: Bradley Morgan Cc: Kees Cook , linux-kernel@vger.kernel.org, Geert Uytterhoeven , Dmitry Osipenko , Rafael J. Wysocki Subject: Re: [PATCH] reboot: don't use cb_data to tell if the static sys-off handler is free Message-Id: <20260727160753.57df153ccc25cb5273ac4a8d@linux-foundation.org> In-Reply-To: <20260726225541.13304-1-include@grrlz.net> References: <20260726225541.13304-1-include@grrlz.net> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 26 Jul 2026 22:55:41 +0000 Bradley Morgan wrote: > There is one static handler for SYS_OFF_PRIO_PLATFORM, shared by all > modes, so the second platform priority registration has to fail with > -EBUSY. alloc_sys_off_handler() decides that by testing cb_data. > > cb_data is caller data though, and nothing says it has to be set. A > registration that passes NULL for it leaves the static handler > looking free, so the next one gets the same struct back while the > first is still live: sys_off_cb and list get overwritten, and the > same notifier_block is registered into a second chain. A > notifier_block has one next pointer, so both chains end up wrong. > > register_platform_power_off() always passes the power off callback as > cb_data, which is why this held up when the static handler was added. > Callers using register_sys_off_handler() directly have no such rule. > > Test sys_off_cb instead. Every handler has one, it is what the > callback path actually needs, and it is set for as long as the > handler is registered. > > Fixes: 587b9bfe0668 ("kernel/reboot: Use static handler for register_platform_power_off()") Please do try to hunt down the people who are best situated to review proposed changes. `git show 587b9bfe0668' ain't hard! I assume you saw the possible pre-existing thing: https://sashiko.dev/#/patchset/20260726225541.13304-1-include@grrlz.net > > ... > > --- a/kernel/reboot.c > +++ b/kernel/reboot.c > @@ -366,7 +366,7 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) > */ > if (priority == SYS_OFF_PRIO_PLATFORM) { > handler = &platform_sys_off_handler; > - if (handler->cb_data) > + if (handler->sys_off_cb) > return ERR_PTR(-EBUSY); > } else { > if (system_state > SYSTEM_RUNNING) > -- > 2.47.3