Archive-only list for patches
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Jinhui Guo <guojinhui.liam@bytedance.com>,
	Corey Minyard <corey@minyard.net>,
	Sasha Levin <sashal@kernel.org>,
	openipmi-developer@lists.sourceforge.net
Subject: [PATCH AUTOSEL 6.18-5.10] ipmi: Fix the race between __scan_channels() and deliver_response()
Date: Tue,  9 Dec 2025 22:49:01 -0500	[thread overview]
Message-ID: <20251210034915.2268617-20-sashal@kernel.org> (raw)
In-Reply-To: <20251210034915.2268617-1-sashal@kernel.org>

From: Jinhui Guo <guojinhui.liam@bytedance.com>

[ Upstream commit 936750fdba4c45e13bbd17f261bb140dd55f5e93 ]

The race window between __scan_channels() and deliver_response() causes
the parameters of some channels to be set to 0.

1.[CPUA] __scan_channels() issues an IPMI request and waits with
         wait_event() until all channels have been scanned.
         wait_event() internally calls might_sleep(), which might
         yield the CPU. (Moreover, an interrupt can preempt
         wait_event() and force the task to yield the CPU.)
2.[CPUB] deliver_response() is invoked when the CPU receives the
         IPMI response. After processing a IPMI response,
         deliver_response() directly assigns intf->wchannels to
         intf->channel_list and sets intf->channels_ready to true.
         However, not all channels are actually ready for use.
3.[CPUA] Since intf->channels_ready is already true, wait_event()
         never enters __wait_event(). __scan_channels() immediately
         clears intf->null_user_handler and exits.
4.[CPUB] Once intf->null_user_handler is set to NULL, deliver_response()
         ignores further IPMI responses, leaving the remaining
	 channels zero-initialized and unusable.

CPUA                             CPUB
-------------------------------  -----------------------------
__scan_channels()
 intf->null_user_handler
       = channel_handler;
 send_channel_info_cmd(intf,
       0);
 wait_event(intf->waitq,
       intf->channels_ready);
  do {
   might_sleep();
                                 deliver_response()
                                  channel_handler()
                                   intf->channel_list =
				         intf->wchannels + set;
                                   intf->channels_ready = true;
                                   send_channel_info_cmd(intf,
                                         intf->curr_channel);
   if (condition)
    break;
   __wait_event(wq_head,
          condition);
  } while(0)
 intf->null_user_handler
       = NULL;
                                 deliver_response()
                                  if (!msg->user)
                                   if (intf->null_user_handler)
                                    rv = -EINVAL;
                                  return rv;
-------------------------------  -----------------------------

Fix the race between __scan_channels() and deliver_response() by
deferring both the assignment intf->channel_list = intf->wchannels
and the flag intf->channels_ready = true until all channels have
been successfully scanned or until the IPMI request has failed.

Signed-off-by: Jinhui Guo <guojinhui.liam@bytedance.com>
Message-ID: <20250930074239.2353-2-guojinhui.liam@bytedance.com>
Signed-off-by: Corey Minyard <corey@minyard.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Summary Analysis

### 1. BUG MECHANISM

This commit fixes a **race condition** between two IPMI functions:

- `__scan_channels()`: Initiates channel scanning, sets
  `null_user_handler = channel_handler`, then waits for `channels_ready`
- `channel_handler()` (called via `deliver_response()`): Processes IPMI
  responses for each channel

**The Bug** (introduced in commit 31b0b0730ad2a from September 2017):

In `channel_handler()`, after processing channel N's response (where N <
IPMI_MAX_CHANNELS-1):
1. Lines 3420-3421 set `channels_ready = true` **prematurely**
2. Then sends request for channel N+1
3. `__scan_channels()` may see `channels_ready == true` and exit the
   wait loop early
4. `__scan_channels()` sets `null_user_handler = NULL`
5. Responses for channels N+1, N+2, etc. arrive but are **discarded**
   because `null_user_handler` is NULL
6. Remaining channels are **zero-initialized and unusable**

### 2. THE FIX

The fix simply **removes 2 lines** that prematurely set `channels_ready
= true` in the `else` branch. After the fix, `channels_ready = true` is
only set when:
- All channels have been scanned (`curr_channel >= IPMI_MAX_CHANNELS`),
  OR
- An error occurs (`rv != 0`)

### 3. CLASSIFICATION

| Criteria | Assessment |
|----------|------------|
| Bug type | Race condition causing data corruption (zero-init channels)
|
| Impact | IPMI channels become unusable on affected systems |
| Size | 2 lines removed - minimal and surgical |
| Risk | Very LOW - only removes premature assignments |
| Subsystem | IPMI - used for server management |

### 4. STABLE BACKPORT CRITERIA

| Criterion | Status |
|-----------|--------|
| Obviously correct | ✅ Yes - simply delays setting flag until the right
time |
| Fixes real bug | ✅ Yes - race causes channels to be zero-initialized |
| User impacting | ✅ Yes - affects IPMI hardware management |
| Small and contained | ✅ Yes - 2 lines in single file |
| No new features | ✅ Correct - pure bug fix |
| No API changes | ✅ Correct - internal change only |

### 5. SIGNALS

**Positive signals:**
- Fixes a real race condition with clear cause and effect
- Minimal, surgical fix (2 lines removed)
- Bug has existed since 2017 (31b0b0730ad2a) - affects all current LTS
  kernels
- IPMI maintainer (Corey Minyard) signed off
- Detailed commit message explains the race with CPU timing diagram

**Missing signals:**
- No explicit `Cc: stable@vger.kernel.org` tag
- No explicit `Fixes: 31b0b0730ad2a` tag (though it should have one)
- No Tested-by/Reviewed-by tags

### 6. RISK vs BENEFIT

- **Benefit**: Fixes a race condition that makes IPMI channels unusable
  on servers
- **Risk**: Extremely low - the fix only removes code that ran at the
  wrong time; the correct code paths for setting `channels_ready` are
  untouched
- **Affected users**: Server/data center users relying on IPMI for
  hardware management

### 7. DEPENDENCIES

The fix is standalone and doesn't depend on other commits. The affected
code has existed unchanged since 2017, so it should apply cleanly to all
active stable kernels.

### CONCLUSION

This is a clear backport candidate. The commit fixes a real race
condition that causes IPMI channels to become unusable. The fix is
minimal (2 lines removed), obviously correct (simply delays a flag until
the right time), and carries virtually no regression risk. IPMI is
critical infrastructure for server management, making this fix important
for stable users.

**YES**

 drivers/char/ipmi/ipmi_msghandler.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 3700ab4eba3e7..d3f84deee4513 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -3417,8 +3417,6 @@ channel_handler(struct ipmi_smi *intf, struct ipmi_recv_msg *msg)
 			intf->channels_ready = true;
 			wake_up(&intf->waitq);
 		} else {
-			intf->channel_list = intf->wchannels + set;
-			intf->channels_ready = true;
 			rv = send_channel_info_cmd(intf, intf->curr_channel);
 		}
 
-- 
2.51.0


      parent reply	other threads:[~2025-12-10  3:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10  3:48 [PATCH AUTOSEL 6.18-6.17] functionfs: fix the open/removal races Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] scsi: qla2xxx: Use reinit_completion on mbx_intr_comp Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] via_wdt: fix critical boot hang due to unnamed resource allocation Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] ti-sysc: allow OMAP2 and OMAP4 timers to be reserved on AM33xx Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.15] scsi: qla2xxx: Fix lost interrupts with qlini_mode=disabled Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] exfat: zero out post-EOF page cache on file extension Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] scsi: smartpqi: Add support for Hurray Data new controller PCI device Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.12] scsi: ufs: host: mediatek: Fix shutdown/suspend race condition Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] powerpc/addnote: Fix overflow on 32-bit builds Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.6] fuse: Invalidate the page cache after FOPEN_DIRECT_IO write Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] ipmi: Fix __scan_channels() failing to rescan channels Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] scsi: qla2xxx: Fix initiator mode with qlini_mode=exclusive Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.17] um: init cpu_tasks[] earlier Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] reset: fix BIT macro reference Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] clk: mvebu: cp110 add CLK_IGNORE_UNUSED to pcie_x10, pcie_x11 & pcie_x4 Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.6] fuse: Always flush the page cache before FOPEN_DIRECT_IO write Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-5.10] firmware: imx: scu-irq: Init workqueue before request mbox channel Sasha Levin
2025-12-10  3:48 ` [PATCH AUTOSEL 6.18-6.17] scsi: lpfc: Fix reusing an ndlp that is marked NLP_DROPPED during FLOGI Sasha Levin
2025-12-10  3:49 ` [PATCH AUTOSEL 6.18-5.10] exfat: fix remount failure in different process environments Sasha Levin
2025-12-10  3:49 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251210034915.2268617-20-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=corey@minyard.net \
    --cc=guojinhui.liam@bytedance.com \
    --cc=openipmi-developer@lists.sourceforge.net \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox