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=1796277036; b=sTNDltJrIKUUK+doP0CbM829heHFAIFAR+cRPUfTHU76dCf+KtvT9qn+ajaCHbonNESA rDlGZcm5qenfhGkeRYfDIHpQhxiE1JWlXpEewKSJuMbatw0RIBvigyPstamyOmttwMNr6 hx19Wug4vZcakkSSWNfJp35rimh6yQ15OpPCnwHl5wsSXfrqdXOkL+DwWN5b2xdAR5DKW QMtHcp1jFgMbx6zicK0AkQfckMzLOykghf5s52Ow9oef1YrforsYxQma8zFjboIlRrOqO IY+sAYSH6YiGuj6ewy0JhxeUWw95G9olZ+GWFbL+yv1PvY5jESxcHdM7sbEQqKCk7Rg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796277036; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-Id: In-Reply-To:References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=ZwyYcX34c3k44AykDFKlemUiiGH/fP5P6dPnfP0Xk2I=; b=PQqHOpMYeWxcXgqrlZyNNPbYLQynooewK4lRlu2Yk64RxCbiyg4AWdqhahXRCDXfwh6n a7BiM4AWbeEy+8G8HQmhs1wsIJ602YN2WWcRCiCbNKD6OBdvlXhv67QXI61d3R6mpE24e LsPeYvHs85V2yLtGAk4B2W6mNkG5TsQXIwqBfqqJ88zvdblFFJVz2Urc75k1USAswdVc3 UZGWkQQiHp2T0IvLboZZNS8Sx1RiYsSGOf9XNZJZ1Pt9NAeeHyKq/wetlLGM+WtqcCi+E zeFzRYDt1du4TNbvJoS8voXEVBjhJV0eopc71cyPlBpW0QqjxXOVW0wUnnShKCYlYmg== 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=UnpdjMwp; 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 70E14606A322 for ; Thu, 3 Dec 2026 05:50:36 +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=UnpdjMwp Received: by smtp.kernel.org (Postfix) with ESMTPSA id A87701F00893; Thu, 3 Dec 2026 05:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796277035; bh=ZwyYcX34c3k44AykDFKlemUiiGH/fP5P6dPnfP0Xk2I=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=UnpdjMwpB5F3Xz9rZ3RHsSrF0rNCDXz3zmUy7Kk4OSgf/HW+SwtWaIGWqBn5STATd 8Zkex1xDNFfAwWYxdd0H7Rt6UOH4lbO2Vld0EQFzHXtCU8x3ggWqTazSbzBWGxMjX5 4xNCZ1Kc9J+TUwPXJy8redncjVukXDsGg1w3usZ0= Date: Wed, 2 Dec 2026 21:50:35 -0800 From: Andrew Morton To: Bradley Morgan Cc: "Rafael J . Wysocki" , Dmitry Osipenko , Max Filippov , Chris Zankel , Andrew Davis , Oleg Nesterov , Petr Mladek , linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] reboot: fix platform sys_off handler reuse with NULL cb_data Message-Id: <20261202215035.d1fd85e7da5b4f9071e84dcb@linux-foundation.org> In-Reply-To: <20261126214754.3630965-2-bradley.morgan@linux.dev> References: <20261126214754.3630965-1-bradley.morgan@linux.dev> <20261126214754.3630965-2-bradley.morgan@linux.dev> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 26 Nov 2026 21:47:53 +0000 Bradley Morgan wrote: > 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. > > ... > > --- a/kernel/reboot.c > +++ b/kernel/reboot.c > @@ -394,7 +396,9 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) > > 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)) But `handler' can be allocated with kzalloc_obj(), so comparing that pointer with the statically allocated array members isn't meaningful?