From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 92FCE32C957 for ; Tue, 30 Jun 2026 14:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782828438; cv=none; b=pYMw6wWnh/9p2CZih1NvHbYvfabgk4r+zGWpy4FbSJLP1cjxoL/wiKTo9GEvMFHUgm3wZxBl/ARXgHKOIlykpjqOZ6DkoUzy1pi0foa2iCRdg+fuipFUQbLQziRKg3cLnnYZJ3yGhU4xRie8B2YCVHuy26JehnW/5Lz6nb8h9VY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782828438; c=relaxed/simple; bh=7qVo6MDYC+mBAM7sbhqVq+g7vkJWQpirCojbMF21ZcI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jX4KMAl6TZmBq2I+KHYfLD60vJ4wX2pJkE+8SbwIlBKTdnkcC1ybXikbVg/iimAB02hpxyzf1xU4JPRtIPLeD0jtfrLAP2u8T6xGhzNJPumgDbdDjSo/lqLsnKKvRTW5asG822uZLDkpZr9tm8IB+FYoSD7lXvOLvTYd1jaPQV8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZNM0VTkz; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZNM0VTkz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782828435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wiloxeC2VH7kInMbYLcfoeEPiR7OXcKtKOeKZkyjsnA=; b=ZNM0VTkzetQnBn3aN+t4i6vC5PbzSHQulzujZ6JQbvkWZa4Goox4Lsyl3YPzSvJ1EAedQt gZthwttsrkRwbvSBlAHdVQ8CGTDpkz3Cqxa1JjK7KFfRbo6VY6yEJt8SDPZ7ORdpRcA2V2 6GHYWLvsxwr7fZuPVt3nJQp3Bda5sWQ= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-wlKNI_17OQi435mUHwTjrQ-1; Tue, 30 Jun 2026 10:07:14 -0400 X-MC-Unique: wlKNI_17OQi435mUHwTjrQ-1 X-Mimecast-MFC-AGG-ID: wlKNI_17OQi435mUHwTjrQ_1782828432 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AF9521800869; Tue, 30 Jun 2026 14:07:12 +0000 (UTC) Received: from fedora.flets-east.jp (unknown [10.64.240.15]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8586180057F; Tue, 30 Jun 2026 14:07:10 +0000 (UTC) From: Seiji Nishikawa To: corey@minyard.net Cc: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, snishika@redhat.com Subject: [PATCH] ipmi: si: Fix NULL pointer dereference in start_kcs_transaction() Date: Tue, 30 Jun 2026 23:06:33 +0900 Message-ID: <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-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 try_smi_init() allocates new_smi->si_sm and later calls ipmi_register_smi(), 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. 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