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=1796277237; b=skAA7vwaX0mFpnn+SheYf39hnxy2ywmbXw9ZVdaKUJypDD0fIP8wLCHg7gisZtSXDVQ0 vVxN6PGmCDC0SFech8b3GsCfub1lin8tF9560vhmdZsPc8GKN4eS8gCwWAnKaxJ6aj0UV 4S6YW7rYYdi20c+VDEjrqlovAJLP5WdMByEDk/+39/3Is13DHyqHkE7wNTsZom+Id6wut 9bb42JX39NjTW4ovMq0AGjDI0s/r+EavCszPKn7OCgFc5AUFcCF84cYsQQHefAWFgXZcD 0uweGD4rvxCdUHCN11BRm1JBal9d74NEbWZn2fAahL/g4eaHsGt4qSw38Ia1R+N39Lg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796277237; h=Received:DKIM-Signature:Date:From:To:Subject:Message-Id:In-Reply-To: References:X-Mailer:Mime-Version:Content-Type: Content-Transfer-Encoding; bh=xulsp70KeTIrT8g1ziaNa0IzLaB363+XzKh/EV2/gg8=; b=iBpbNAE4lK4tzQBUea0MaXYnuprH1YfCz92gNkvcjlbrxdDHV5S9eeprAucCjzqUvBES XHviAMGimHaY7Bugm8867QlbL2ydEyosqsLpMk7MPpkZ4FL8AMBD2Zdfzqf9ZvMu1tFKG +exrzHXlYkZlKVrRc6CPQn7NzkXnFnDjvjRNSqRl7phdj+tfqH1dgpG1M/TgSgCJ+jxcj USmlw5mhdLv4SBRrQrGF2epIP/QcunNCXYdyZKV5aB1u2nFcc1fcTQnypZioPx2EWcBID ODYVgogKAF1w3TcalY2sPG9iZAfOR3MBuddTplJjRMtfM8jj1U8T/Ry6tZ/13vINpQA== 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=B+P3CVwO; 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 7C878606A32C for ; Thu, 3 Dec 2026 05:53:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=B+P3CVwO Received: by smtp.kernel.org (Postfix) with ESMTPSA id B900F1F00893; Thu, 3 Dec 2026 05:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796277237; bh=xulsp70KeTIrT8g1ziaNa0IzLaB363+XzKh/EV2/gg8=; h=Date:From:To:Subject:In-Reply-To:References; b=B+P3CVwOZJTnEtiEb1g8nB+M6vb8w/42pAFomUZHVJa+v8uAgsEoBgpTwinbzsQFa nq7qmUAtU1fVkGWLLj+XQQ19/pb2UBAkJUx3NqcNHz4TR4LSw/zAm8StzzQLzbh7gb 6taUlPBRT7hBHwYc/squ0VZBpugC8ppTZ7uIOXiY= Date: Wed, 2 Dec 2026 21:53:56 -0800 From: Andrew Morton To: Bradley Morgan , "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: <20261202215356.7c73b7e8983c231771825931@linux-foundation.org> In-Reply-To: <20261202215035.d1fd85e7da5b4f9071e84dcb@linux-foundation.org> References: <20261126214754.3630965-1-bradley.morgan@linux.dev> <20261126214754.3630965-2-bradley.morgan@linux.dev> <20261202215035.d1fd85e7da5b4f9071e84dcb@linux-foundation.org> 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 Wed, 2 Dec 2026 21:50:35 -0800 Andrew Morton wrote: > 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? > Well. The comparison is officially undefined in C. But I can see what you're doing there and I'm sure it's OK in kernel ;) But can the comparisons easily be avoided? Or at least commented.