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 760AB3DF018 for ; Tue, 30 Jun 2026 17:44:07 +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=1782841450; cv=none; b=C4mZNXwIsf5eBK1Rcj+VyaCrFhRgX4baquK3GHgrvd0NPFjuR5NhPvls1XwBqltdZmL/YMrBZezywc1gRWtF0aXIf/ODcS3WWb7Zjvh1oKMBUzOIu7dmN4G3hAVFnWszk05nHNQYnBNU2sIjAbgUqzeIJacNS9ZEi77OuwUBK+A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782841450; c=relaxed/simple; bh=C/o3PbRpCmDz3Tbsedrc8VY1qaLWznAggIaTkNE3Dtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PyotvJ7JEgikGrqB6gegEqgCW3Egy8sE5G26DN421ABPLo1OjQTouMtvqcSNzXP5TpaRsh/CtAeEvi7u1i6VNReQPzRgBoyYmpzHA6etn2feqt8+dggAuHty9MAQsTWFOL81i61OukH4xrRgjg/UKB2dBrNggQp8b4zHnijwCLk= 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=Aa+OxThO; 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="Aa+OxThO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782841446; 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: in-reply-to:in-reply-to:references:references; bh=+bbkNqe5YFTxUB0CvY150T/ECqWZsJLYm1FNCJGJ2HE=; b=Aa+OxThOawvtIUBYnMum8QrNoAV/lO9/Ni+cLw3ALMvymsFkHzzriou6Soj8et+yjvBAS2 CUf7dihZwFPOVIwITk2KdhsCefFtv29iocYsHaTqhLQnRBxAqMmNsGhM/qqQskoE8zU90B 04PZfMnHZjvj7KDZUYWHa0g0j+QlhfE= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-Su8BYmuaN-eymNEhhkeaig-1; Tue, 30 Jun 2026 13:44:04 -0400 X-MC-Unique: Su8BYmuaN-eymNEhhkeaig-1 X-Mimecast-MFC-AGG-ID: Su8BYmuaN-eymNEhhkeaig_1782841443 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8CF451955F76; Tue, 30 Jun 2026 17:44:03 +0000 (UTC) Received: from fedora.flets-east.jp (unknown [10.64.240.15]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9607A3000C15; Tue, 30 Jun 2026 17:44:01 +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 v2] ipmi: si: Fix NULL pointer dereference after failed registration Date: Wed, 1 Jul 2026 02:43:48 +0900 Message-ID: <20260630174348.1483814-1-snishika@redhat.com> In-Reply-To: References: 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.4 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. 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