From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19F8B4071E0 for ; Thu, 2 Jul 2026 11:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782992344; cv=none; b=gMSvLAqyOlSP4GTHGHnIqjHuHaEkSSfpHmTjJTeCiE8vpdZhCt3cp9eK7YbMWsIu2CaU5NbvBG6pN3BE75TJNsPfvf+GiWPnvv7lI5Jy95iAu2qK6PMpX5Ii3ctJo19BEtviPmHccp7NJuGrluYnbCac01UajcO/4byaLOS+0g4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782992344; c=relaxed/simple; bh=se3yv6rBer5VixDVOkny1+xad+hcgTQxRyiB6jlNQsY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bNdMwffB3I7LLqvHixh3huPFwuFOzP1HHVF/sY2b2tJT+ymozT3fuFXJCyqtEc5GMQPOEOrEOi6LiFzhbmehHTs0Xkp5R1lDHgPgZOhQTvxpGuNZDa0cxS9y4AVlcJuH383NZhnQ+6l6vAYw69KtGR+LfLJGGaRjoY3X9hXAh/c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=minyard.net; spf=pass smtp.mailfrom=minyard.net; dkim=pass (2048-bit key) header.d=minyard.net header.i=@minyard.net header.b=o/RWHFX+; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=minyard.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=minyard.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=minyard.net header.i=@minyard.net header.b="o/RWHFX+" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7e9eaf04bfaso528744a34.1 for ; Thu, 02 Jul 2026 04:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1782992339; x=1783597139; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Lyt4xoV2v8jyxl4ZpFcYw7RBDGThjZWpi44qBzlWcC8=; b=o/RWHFX+XNLzLAYudZExMgJDkAPrV0nnk3vPoRVWLjehq27kUXgnEa5CWx6qZG+lfI AXbunaVIJtiQBQU9yQ7z3LIjtL/5w7wkWWlzWv/12VDtmwxvGpmqDLK1xfQPHYOBfaCT JeLSoFqdJ335eiV/iFszsyb78VLtOWgxseR54ZD7r8JLjNJdAs+jMbgDEGxejAOEy1Z7 p3km826Yrl3vLPuIO8Yp9CNnqmh79T0Y8TBeq1+X0S+hZMkI8duG32yp5s/S7uiiOfNb oZErLot1hYlCpAeOx4ZILiZTR7LWJV5PfrFaWLAKdYQczwLnkDDbGtgG5ZXHm+7FNwcr JcIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782992339; x=1783597139; h=in-reply-to:content-disposition:mime-version:references:reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Lyt4xoV2v8jyxl4ZpFcYw7RBDGThjZWpi44qBzlWcC8=; b=c5Yypfe34lels7h1FQKZblaVux21zTrEEbsb7TkD/zL160XvW4gR3ocDnpR0lJ601D sYoyLn3zEgqzkQHTnkOOk7koZcmNvmiYHd9H98NAwWo8BKNdYGX2glqB/Jcz/idAL3gC J3THe8wM4fUK6/y6MQizXhzlH8ZrtTcWBBcGqBKfS9+dSjjqe+4kD9kEcRhDFvawTJAY viATbOQ7sz+SXX2a2B8Vgx5zj8ZViZipDFDo6pg1x6aclqYuXc22RRl44jMeXGsrUYC/ 5kS4FGEIL3OsSqV73pO9kdxYkDTzbrR4fc4As7NCgnqgmdDvn+3cUWPnl3tgNVGLJIwY Vmcg== X-Forwarded-Encrypted: i=1; AFNElJ+9kZpTkvwJU4AXNtybzz0rj2PkiJDei7tzC7jWySLcJl7U2Kr6GmDLFDg06elHayBel63dSu/H7DvhDhc=@vger.kernel.org X-Gm-Message-State: AOJu0YwEZCEvXNk4jCOqxfFrkTKNq9dddDoI34WlGX1QqpCpTBUIrdeb hj6F8mzyL7bc8SfW8bmpCw+eqxRxbUHPKwOL0vfIsHzlQivizdOyfXzod2QrOfrvHI8= X-Gm-Gg: AfdE7ckil+vdFMcW+u9WRAQmYHGPAqEdCak4Fr21vbHPXSJmph0kmrCr1rshHYJVVQy NTLs3DKJTxeH3N4H85g2Dlr/DEtuLC0/94iI4e9WOeBqzJlHtWz88vfhEpwQt1ZK0MXqJm8LeGQ ucmvaPx1sOWP7jak5LySG398ZEGxPmYN1iNLoxzd3Vam5n2nbu3HFQO1nMdRU/tyv+Dlx0K2qma xNVH76ZUrNdVpiaoYi+j56GIIOgnbVoBZUZi6VnNNHztm0sY03oprqJ25CjBoU1Ls9eTgCjhgqP WV2u/XA6ld8OPjIM/WlGPXGnPKXwsO2Ans2ofZSk7e7oydHmD48LOewMJOqaS7Qk98fcemqK//E UYiAqkuWRvDsrdcbA3jY2NdQj60/d+zvFXBH5riLjTKdicC3FtDdTsqxGpwZVdC/ap2AD2peMvi xnIpzEmQqLWJVvVVV2wBXiWV1iAij2DHnCjw/t/CioB2ZNHoERhkq4TzVGogC37F2LWVtoGMvwn CGOF9M02SL2XKhMRy9+nmr5xBrv8GVIiLrlzQ== X-Received: by 2002:a05:6808:1305:b0:495:dea9:3b6 with SMTP id 5614622812f47-4960ef48c80mr4664523b6e.26.1782992339428; Thu, 02 Jul 2026 04:38:59 -0700 (PDT) Received: from mail.minyard.net ([2001:470:b8f6:1b:cbfe:43f3:70c2:f4b2]) by smtp.gmail.com with ESMTPSA id 5614622812f47-497d1b43cfcsm1414670b6e.14.2026.07.02.04.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2026 04:38:57 -0700 (PDT) Date: Thu, 2 Jul 2026 06:38:54 -0500 From: Corey Minyard To: Seiji Nishikawa Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] ipmi: si: Fix NULL pointer dereference after failed registration Message-ID: Reply-To: corey@minyard.net References: <20260630174348.1483814-1-snishika@redhat.com> 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-Disposition: inline In-Reply-To: <20260630174348.1483814-1-snishika@redhat.com> On Wed, Jul 01, 2026 at 02:43:48AM +0900, Seiji Nishikawa wrote: > try_smi_init() allocates new_smi->si_sm and later calls > ipmi_register_smi_mod(), which maps to ipmi_add_smi(). > > During ipmi_add_smi(), the upper IPMI message handler obtains the > initial BMC device information through __bmc_get_device_id(). This can > fail if the BMC does not return a successful response to the Get Device > ID command. > > When the BMC returns a nonzero completion code, the device-id helper > retries the command and eventually returns -EIO if the device ID still > cannot be fetched. > > On this failure path, ipmi_add_smi() logs "Unable to get the device id" > and goes to out_err_started, where it invokes the lower driver's > shutdown callback. try_smi_init() then logs the returned registration > failure: > > ipmi_si IPI0001:00: IPMI message handler: Unable to get the device id: -5 > ipmi_si IPI0001:00: Unable to register device: error -5 > > For ipmi_si, the shutdown callback is shutdown_smi(), which cleans up > the SI state machine data, frees smi_info->si_sm, and sets > smi_info->si_sm and smi_info->intf to NULL. > > However, intf->in_shutdown is not set on this failed-registration > rollback path. Therefore, the asynchronous redo_bmc_reg work item can > still retry BMC device-id probing after the lower driver has already > cleared its SI state machine data. In the observed case, that retry path > reached start_next_msg(), which passed the NULL smi_info->si_sm pointer > to the selected KCS state machine handler: > > BUG: unable to handle kernel NULL pointer dereference at 0000000000000000 > Workqueue: events redo_bmc_reg [ipmi_msghandler] > RIP: start_kcs_transaction+0x2c/0x190 [ipmi_si] > Call Trace: > start_next_msg+0x50/0x80 [ipmi_si] > check_start_timer_thread.part.9+0x3b/0x50 [ipmi_si] > sender+0x69/0x80 [ipmi_si] > i_ipmi_request+0x2ac/0x9d0 [ipmi_msghandler] > __get_device_id.isra.29+0xaa/0x180 [ipmi_msghandler] > __bmc_get_device_id+0xef/0x950 [ipmi_msghandler] > redo_bmc_reg+0x52/0x60 [ipmi_msghandler] > process_one_work+0x1a7/0x360 > > Set intf->in_shutdown on the out_err_started path before invoking the > lower driver's shutdown callback. This prevents later redo_bmc_reg > retries from using an interface whose lower driver state has been > cleaned up, and applies the same shutdown state to other IPMI interfaces > as well. > > Signed-off-by: Seiji Nishikawa > --- > Thanks, I agree. I moved the fix to the ipmi_add_smi() rollback path in v2 > and dropped the SI-side NULL checks. Thanks, this is in my for-next tree. -corey > > Changes in v2: > - Move the fix to ipmi_add_smi() by setting intf->in_shutdown on the > out_err_started path, as suggested by Corey. > - Drop the NULL checks in ipmi_si_intf.c. > > drivers/char/ipmi/ipmi_msghandler.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > index ab4c85f3d6fe..8d9f2e647d9b 100644 > --- a/drivers/char/ipmi/ipmi_msghandler.c > +++ b/drivers/char/ipmi/ipmi_msghandler.c > @@ -3757,6 +3757,7 @@ int ipmi_add_smi(struct module *owner, > out_err_bmc_reg: > ipmi_bmc_unregister(intf); > out_err_started: > + intf->in_shutdown = true; > if (intf->handlers->shutdown) > intf->handlers->shutdown(intf->send_info); > out_err: > -- > 2.54.0 >