From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 5F2C5374A0B for ; Tue, 30 Jun 2026 15:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782834231; cv=none; b=J/fH7Xq7kpZu4o9RW9kRg9nKUECmKM5Da34t2yiKtxjTLcvztSXId1zNMp0u0d/EonEPt2Hth9bMFO2SYpv1v7dpW9FIMOt6/Oz4hnUBBhZAZUobsb47MkBbyfF2+CYS4buij9itsLgEXZo/Xoq01cROYRMOmv2gnuObf6lkxRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782834231; c=relaxed/simple; bh=saKsY4+YUQVmqxsDpYVygiQmKDl9USbAQtLmlkNtEH8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iaEFjW/u6aGo1vVAYuSf9wc6JlmaH8FGCmExW9GbLi8YiI72OJOH80sJuir0/8gcbTCPoeWO1yWTA50lodqjCiUk7/fC71Q1zrn9ZdPfLtYR/4bDtx6/4Tu+kBt03o9Z9m6YyFihBwHivOqBZHCro+mDnKI3E+gbrTzEVZLbHZQ= 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=Wu7P7Csn; arc=none smtp.client-ip=209.85.167.170 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="Wu7P7Csn" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-48751bd4abeso2052722b6e.0 for ; Tue, 30 Jun 2026 08:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=minyard.net; s=google; t=1782834228; x=1783439028; 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=TAfkRgXWz9THLu90aX4PXdlkyOPjYY1bhpxPkmPz80o=; b=Wu7P7CsnpsxJW/OR9YFAGho+X7UrDBmfltdni4Pu4xaMJxLFMITnciLE3p8dcLYszf 5l4NF5/hA+raRXpRAi8qQ6gnDSMY2T3/Fk+1EiR+jvpimAj126GIeyQ14ACdYxKx5rHb +GW3GTQnc/kUKqCq/vRzpr90Hklf2MKiA4dc/Z5L9LpB5ZFBRqqkZckJVNJIkFcZDkR+ F2zwHeXjcNw2Tb1dyG9E8upZWZJbdrobofCPSQw9FDO7U9vpHnMV1SJIC9P7KtrA8dYZ 8TT85okyo5peYDVoAdFf5oiQ3lmtfn/Ln8T7lXjyccd12ZwSKRaz5FtyaW6A9Vebw4MD VZfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782834228; x=1783439028; 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=TAfkRgXWz9THLu90aX4PXdlkyOPjYY1bhpxPkmPz80o=; b=D4COPhMkTh9EGmIOyNGfZzdbG0eckoGOEILfxXdpZbF4ByHDlfDr589+VXF9bh7yDQ 8muJmglfWYkGvqlTZ0UnZ14qa2Z9y9HRBhFHVAzoAkLyHeJXM5WMHUKHKmGy1jsYVtnY 4VsSZrtIi4ab4wVreaiE4IgBmm6i1FSwaLf6gaMiK95HxUYPGiWqb+2lDOZQ4XIG8WBx C2jR1Xm3rP/wrRoyHMwJp9P7DwVIhRbiSoIcEMjHTaTzRibaJWXI+X/TiJ24K1QcRZNa cjWdoaOJ2f2ZTYxyhFCG2VV6fn/Qva7eD0BgW5pt1ryBjJ8+QD1EvKKCgCRP1wcFhpo2 /QuA== X-Forwarded-Encrypted: i=1; AFNElJ8H74fmG8AOtuGY+PhJLMyAmp99gEnIcwLuP12+Fn+Jzwjd8NV+j7W2gtN1JP5hRe0MjBDWgT2QmjWArmI=@vger.kernel.org X-Gm-Message-State: AOJu0YyoldcoEc8KT69Z70Tx+9gV6WkkB+FKrKN0jXBt7+cEzc/gj7t8 n/K7JTuWB83CeDsAKwPKiFxnbXVotduWDmdG5FQ+jstjqCw9hXayAabEZgneg6ZgchMYq3Ql9oe xhuxI X-Gm-Gg: AfdE7cnP4jKBXZliIOGPZUVdqmmKUjVkSFVJWlxTV5MevGIoAbtKRQ3wQZehlUFdPDH reTRnYFdRJJEKviWFyLATUZWlTss7Irr6aVz4G6k5dDth6dzVkdecoT7joqszahWuJgSrHVqICw K092baSXMiiw8T03K7p4FfAlWg0i7ZkKU2hJZ2UbCRiMEN3t4hmr/MFFVDCIfxfyvzCrSkGMmov qOwFOaJid9DojioMizkpRw/FghUuPyTGCh08/7fWC1PCelSt1pL5ViAe5cbASfrOwTzeTXQ9Oz0 CLBpCAIjpAVwO6PGvkSoP9INxtN3iJJ77YDhNjYNqclReNyyZK4AuL6Xwj6mwto/8udWz0HXmI+ GY9Ig4isNRu0/M/mrzJ/2EbtdixZD0RHwy0j/c90izAFQBQjVc+t8d4yZ51o6evJvB4+HtklItP vYFhkAJwckxlTVrIRztwFjWbN2Zszuo61CtjenQ5xHuga9MmO/m+1XyzrdC+Jb5uJWWCunOiks3 WWj0RQb/AYabOrXo2vY1Ieu4Czf/LyZv5aN X-Received: by 2002:a05:6808:150e:b0:489:6f90:2f45 with SMTP id 5614622812f47-495eadb3750mr3017719b6e.1.1782834227928; Tue, 30 Jun 2026 08:43:47 -0700 (PDT) Received: from mail.minyard.net ([2001:470:b8f6:1b:b3ac:de10:3c66:13b]) by smtp.gmail.com with ESMTPSA id 5614622812f47-49354e517dfsm8890265b6e.11.2026.06.30.08.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2026 08:43:47 -0700 (PDT) Date: Tue, 30 Jun 2026 10:43:43 -0500 From: Corey Minyard To: Seiji Nishikawa Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ipmi: si: Fix NULL pointer dereference in start_kcs_transaction() Message-ID: Reply-To: corey@minyard.net References: <20260630140633.1410091-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: <20260630140633.1410091-1-snishika@redhat.com> On Tue, Jun 30, 2026 at 11:06:33PM +0900, Seiji Nishikawa wrote: > try_smi_init() allocates new_smi->si_sm and later calls > ipmi_register_smi(), which maps to ipmi_add_smi(). Thank you, the analysis is correct and very good. I don't think the fix is right, though. I believe the right way to handle this is to set intf->in_shutdown right after out_err_started: in ipmi_add_smi(). That was the intent, this case was missed. And that way it's fixed for the other IPMI interfaces. Do you agree? -corey > > 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. > > kfree(smi_info->si_sm); > smi_info->si_sm = NULL; > > smi_info->intf = NULL; > > However, the smi_info can still be reached later. In the observed case, the > redo_bmc_reg work item retried BMC device-id probing after shutdown_smi() > had already cleared smi_info->si_sm. The 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 > > start_next_msg() and smi_event_handler() both invoke the selected SI state > machine handlers with smi_info->si_sm without checking whether the state > machine data has already been freed and cleared. > > Add NULL checks before calling into the selected SI state machine handlers. > If the state machine data has already been removed, treat the interface as > idle and avoid dereferencing the cleared state. > > Signed-off-by: Seiji Nishikawa > --- > drivers/char/ipmi/ipmi_si_intf.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c > index 9a9d12be9bf7..d13d5024352a 100644 > --- a/drivers/char/ipmi/ipmi_si_intf.c > +++ b/drivers/char/ipmi/ipmi_si_intf.c > @@ -320,6 +320,9 @@ static enum si_sm_result start_next_msg(struct smi_info *smi_info) > { > int rv; > > + if (unlikely(!smi_info->si_sm)) > + return SI_SM_IDLE; > + > if (!smi_info->waiting_msg) { > smi_info->curr_msg = NULL; > rv = SI_SM_IDLE; > @@ -800,6 +803,9 @@ static enum si_sm_result smi_event_handler(struct smi_info *smi_info, > { > enum si_sm_result si_sm_result; > > + if (unlikely(!smi_info->si_sm)) > + return SI_SM_IDLE; > + > restart: > if (smi_info->si_state == SI_HOSED) > /* Just in case, hosed state is only left from the timeout. */ > -- > 2.54.0 >