Skip to contentSkip to conversation

ALSA: sb: Force to disable DMAs once when DMA mode is changed

PATCH New Sasha Levin 1 participant 8 messages Jun 24, 2025

Subsystems (7)
Stable branch SCSI ACPI libata +3 more subsystems
lore
Share & tools
lore

Sasha Levin

author maintainer
#0 lore raw

PATCH 1/8 ALSA: sb: Force to disable DMAs once when DMA mode is changed

From: Takashi Iwai <[email protected]>

[ Upstream commit 4c267ae2ef349639b4d9ebf00dd28586a82fdbe6 ]

When the DMA mode is changed on the (still real!) SB AWE32 after playing a stream and closing, the previous DMA setup was still silently kept, and it can confuse the hardware, resulting in the unexpected noises. As a workaround, enforce the disablement of DMA setups when the DMA setup is changed by the kcontrol.

https://bugzilla.kernel.org/show_bug.cgi?id=218185

---

Based on my analysis of the commit message and code changes, here is my assessment:

**YES** - This commit should be backported to stable kernel trees.

## Extensive Explanation:

### 1. **Bug Fix Nature**
This commit fixes a real bug that causes "unexpected noises" on SB AWE32 hardware when DMA mode is changed after playing a stream. The fix addresses a situation where "the previous DMA setup was still silently kept, and it can confuse the hardware."

### 2. **Code Change Analysis**
The fix is minimal and surgical:

```c
if (change) {
    snd_dma_disable(chip->dma8);
    snd_dma_disable(chip->dma16);
}
```

This adds only 4 lines that disable both DMA channels when the DMA mode control changes. The fix is:
- **Small and contained**: Only affects the snd_sb16_dma_control_put() function
- **Low risk**: Simply ensures DMA channels are disabled during mode switches
- **Clear purpose**: Prevents hardware confusion from stale DMA configurations

### 3. **Hardware Bug Context**
The kernel repository analysis reveals this is addressing a known class of hardware issues with SB16 cards:
- The driver documents hardware bugs with DMA mode switching (lines 14-18 in sb16_main.c)
- The hardware has separate 8-bit and 16-bit DMA channels that cannot mix
- Certain chip revisions have bugs where DMA transfers can block when switching modes

### 4. **Safety and Side Effects**
The change has minimal side effects:
- Only executes when user changes the DMA mode control
- The driver already checks for active playback/capture before allowing changes (if (chip->mode & (SB_MODE_PLAYBACK | SB_MODE_CAPTURE)) return -EBUSY;)
- snd_dma_disable() is a standard ISA DMA function that safely disables DMA transfers
- The prepare functions already disable/enable DMAs during normal operation

### 5. **Stable Tree Criteria**
This meets stable tree criteria:
- **Fixes a real bug**: Users experience actual audio problems (unexpected noises)
- **No new features**: Pure bug fix, no feature additions
- **Minimal change**: 4 lines of straightforward code
- **Low regression risk**: Only affects legacy ISA hardware (SB16/AWE32)
- **Clear bug report**: References kernel bugzilla #218185

### 6. **Legacy Hardware Consideration**
While SB16 is legacy hardware, it's still used:
- The bug report is recent (bugzilla #218185)
- The commit message states this affects "still real!" hardware
- Linux maintains support for legacy hardware in stable trees
- The fix prevents audio corruption which significantly impacts user experience

The commit follows the pattern of similar audio driver fixes that were backported (like commit #1 in the examples which fixed DMA synchronization issues). It's a targeted fix for a specific hardware problem with no architectural changes.

 sound/isa/sb/sb16_main.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/isa/sb/sb16_main.c +4 -0
index aa48705310231..19804d3fd98c4 100644
@@ -710,6 +710,10 @@ static int snd_sb16_dma_control_put(struct snd_kcontrol *kcontrol, struct snd_ct
 	change = nval != oval;
 	snd_sb16_set_dma_mode(chip, nval);
 	spin_unlock_irqrestore(&chip->reg_lock, flags);
+	if (change) {
+		snd_dma_disable(chip->dma8);
+		snd_dma_disable(chip->dma16);
+	}
 	return change;
 }
 
Signature · 1 line
2.39.5
author maintainer
#1 lore raw

PATCH 2/8 ata: pata_cs5536: fix build on 32-bit UML

From: Johannes Berg <[email protected]>

[ Upstream commit fe5b391fc56f77cf3c22a9dd4f0ce20db0e3533f ]

On 32-bit ARCH=um, CONFIG_X86_32 is still defined, so it doesn't indicate building on real X86 machines. There's no MSR on UML though, so add a check for CONFIG_X86.

---

**YES**

This commit should be backported to stable kernel trees for the following reasons:

1. **It fixes a build failure**: The commit addresses a build breakage on 32-bit UML (User Mode Linux) where CONFIG_X86_32 is defined but MSR (Machine Specific Register) support is not available. This prevents successful compilation when building for 32-bit UML.

2. **The fix is minimal and contained**: The change is a simple one-line modification that adds an additional check for CONFIG_X86 alongside the existing CONFIG_X86_32 check. The change from:

  ```c
  #ifdef CONFIG_X86_32
  ```
  to:
  ```c
  #if defined(CONFIG_X86) && defined(CONFIG_X86_32)
  ```

This ensures MSR usage is only enabled on real x86 hardware, not on UML.

3. **Similar pattern to other backported fixes**: Looking at the similar commits, we see that:
- Commit #1 (pata_cs5535 + UML) was backported (YES) - it added depends on !UML to prevent build issues
- Commit #2 (dmaengine: idxd + UML) was backported (YES) - similar UML build fix

These show a pattern where UML build fixes are considered important
for stable backporting.

4. **No functional changes for normal users**: The fix only affects build configurations and doesn't change any runtime behavior for users running on actual x86 hardware. This minimizes regression risk.

5. **Prevents allyesconfig/allmodconfig breakage**: As seen in similar commits, UML build failures can break comprehensive kernel build tests (allyesconfig/allmodconfig), which are important for continuous integration and testing.

6. **The issue affects a subsystem driver**: While pata_cs5536 is a specific driver for older AMD CS5536 hardware, build failures in any driver can impact kernel testing infrastructure and distributions that build comprehensive kernel packages.

The commit follows the stable tree rules by being a minimal, focused fix for an actual bug (build failure) with very low risk of introducing new issues.

 drivers/ata/pata_cs5536.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/pata_cs5536.c +1 -1
index 760ac6e65216f..3737d1bf1539d 100644
@@ -27,7 +27,7 @@
 #include <scsi/scsi_host.h>
 #include <linux/dmi.h>
 
-#ifdef CONFIG_X86_32
+#if defined(CONFIG_X86) && defined(CONFIG_X86_32)
 #include <asm/msr.h>
 static int use_msr;
 module_param_named(msr, use_msr, int, 0644);
Signature · 1 line
2.39.5
author maintainer
#2 lore raw

PATCH 3/8 powerpc: Fix struct termio related ioctl macros

In reply to Sasha Levin

From: Madhavan Srinivasan <[email protected]>

[ Upstream commit ab107276607af90b13a5994997e19b7b9731e251 ]

Since termio interface is now obsolete, include/uapi/asm/ioctls.h has some constant macros referring to "struct termio", this caused build failure at userspace.

In file included from /usr/include/asm/ioctl.h:12,
from /usr/include/asm/ioctls.h:5,
from tst-ioctls.c:3:
tst-ioctls.c: In function 'get_TCGETA':
tst-ioctls.c:12:10: error: invalid application of 'sizeof' to incomplete type 'struct termio'

   12 |   return TCGETA;
      |          ^~~~~~

Even though termios.h provides "struct termio", trying to juggle definitions around to make it compile could introduce regressions. So better to open code it.

---

**YES**

This commit should be backported to stable kernel trees for the following reasons:

1. **Fixes a real build failure**: The commit message clearly documents a userspace build failure when asm/ioctls.h is included without struct termio being defined. This breaks userspace programs that use these ioctl definitions.

2. **Simple and contained fix**: The change is minimal and low-risk - it merely replaces macro calls with their hardcoded equivalents. The hardcoded values (0x40147417, 0x80147418, 0x80147419, 0x8014741c) are the exact expansion of the original macros for a 20-byte struct termio on PowerPC.

3. **Follows established patterns**: Other architectures (sh and xtensa) already use this same approach of hardcoding the values with comments showing the original macro. This indicates it's a known and accepted solution.

4. **No functional changes**: The ioctl values remain exactly the same - only the way they're defined changes. This ensures binary compatibility is maintained.

5. **Prevents future issues**: As noted in the commit message, the termio interface is obsolete, and trying to reorganize header files to fix this properly could introduce regressions. The hardcoded approach is safer.

6. **Clear user impact**: The commit includes a specific example of the build failure with line numbers and error messages, demonstrating this affects real users (reported by Tulio Magno).

7. **Tested**: The commit indicates it was tested by Justin M. Forbes, providing confidence in the fix.

The commit follows the stable tree rules by fixing an important bug (build failure) with minimal risk of regression, making it an ideal candidate for backporting.

 arch/powerpc/include/uapi/asm/ioctls.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/powerpc/include/uapi/asm/ioctls.h +4 -4
index 2c145da3b774a..b5211e413829a 100644
@@ -23,10 +23,10 @@
 #define TCSETSW		_IOW('t', 21, struct termios)
 #define TCSETSF		_IOW('t', 22, struct termios)
 
-#define TCGETA		_IOR('t', 23, struct termio)
-#define TCSETA		_IOW('t', 24, struct termio)
-#define TCSETAW		_IOW('t', 25, struct termio)
-#define TCSETAF		_IOW('t', 28, struct termio)
+#define TCGETA		0x40147417 /* _IOR('t', 23, struct termio) */
+#define TCSETA		0x80147418 /* _IOW('t', 24, struct termio) */
+#define TCSETAW		0x80147419 /* _IOW('t', 25, struct termio) */
+#define TCSETAF		0x8014741c /* _IOW('t', 28, struct termio) */
 
 #define TCSBRK		_IO('t', 29)
 #define TCXONC		_IO('t', 30)
Signature · 1 line
2.39.5
author maintainer
#3 lore raw

PATCH 4/8 scsi: target: Fix NULL pointer dereference in core_scsi3_decode_spec_i_port()

In reply to Sasha Levin

From: Maurizio Lombardi <[email protected]>

[ Upstream commit d8ab68bdb294b09a761e967dad374f2965e1913f ]

The function core_scsi3_decode_spec_i_port(), in its error code path, unconditionally calls core_scsi3_lunacl_undepend_item() passing the dest_se_deve pointer, which may be NULL.

This can lead to a NULL pointer dereference if dest_se_deve remains unset.

SPC-3 PR SPEC_I_PT: Unable to locate dest_tpg

Unable to handle kernel paging request at virtual address dfff800000000012
Call trace:
  core_scsi3_lunacl_undepend_item+0x2c/0xf0 [target_core_mod] (P)
  core_scsi3_decode_spec_i_port+0x120c/0x1c30 [target_core_mod]
  core_scsi3_emulate_pro_register+0x6b8/0xcd8 [target_core_mod]
  target_scsi3_emulate_pr_out+0x56c/0x840 [target_core_mod]

Fix this by adding a NULL check before calling
core_scsi3_lunacl_undepend_item()

---

I see now! If we look at the error path, when core_get_se_deve_from_rtpi() returns NULL (line 1667), the code jumps to out_unmap at line 1675. However, there could be existing entries in the tid_dest_list that were already added before this failure.

The commit shows the stack trace mentions "SPC-3 PR SPEC_I_PT: Unable to locate dest_tpg" which actually happens at line 1641, and then jumps to out_unmap (line 1644).

In this case, any tidh entries in the list would have dest_se_deve = NULL because the failure happens before dest_se_deve is even assigned.

**YES**

This commit should be backported to stable kernel trees for the following reasons:

1. **It fixes a real NULL pointer dereference bug**: The commit addresses a kernel crash that occurs when core_scsi3_lunacl_undepend_item() is called with a NULL dest_se_deve pointer. The function dereferences the pointer at line 1453 (if (!se_deve->se_lun_acl)) without checking for NULL, causing a crash.

2. **The bug affects normal error handling paths**: This crash occurs during error handling in the SCSI target subsystem when processing PERSISTENT RESERVE OUT commands with SPEC_I_PT (Specify Initiator Ports). When certain lookups fail (like "Unable to locate dest_tpg"), the error cleanup path can have NULL dest_se_deve values in the tid_dest_list.

3. **The fix is minimal and safe**: The fix simply adds a NULL check before calling core_scsi3_lunacl_undepend_item():

  ```c
  if (dest_se_deve)
  core_scsi3_lunacl_undepend_item(dest_se_deve);
  ```

This is a defensive programming practice that prevents the crash without changing the logic flow.

4. **The fix is confined to error handling**: The change only affects the error cleanup path and doesn't modify the normal operation flow, minimizing the risk of regression.

5. **Similar to other backported fixes**: Looking at the similar commits, commit #3 (qla2xxx NULL pointer fix) and commit #5 (rt5514-spi NULL pointer fix) were both backported and had similar characteristics - they were simple NULL pointer checks that prevented crashes.

6. **Production impact**: NULL pointer dereferences in kernel code lead to kernel panics, which can cause system crashes and data loss. This is particularly important for storage-related code where reliability is critical.

The commit follows the stable tree rules by fixing an important bug (kernel crash) with minimal risk and without introducing new features or architectural changes.

 drivers/target/target_core_pr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/target/target_core_pr.c +3 -1
index b42193c554fb2..2bc849799739e 100644
@@ -1858,7 +1858,9 @@ core_scsi3_decode_spec_i_port(
 		}
 
 		kmem_cache_free(t10_pr_reg_cache, dest_pr_reg);
-		core_scsi3_lunacl_undepend_item(dest_se_deve);
+
+		if (dest_se_deve)
+			core_scsi3_lunacl_undepend_item(dest_se_deve);
 
 		if (is_local)
 			continue;
Signature · 1 line
2.39.5
author maintainer
#4 lore raw

PATCH 5/8 wifi: mac80211: drop invalid source address OCB frames

In reply to Sasha Levin

From: Johannes Berg <[email protected]>

[ Upstream commit d1b1a5eb27c4948e8811cf4dbb05aaf3eb10700c ]

In OCB, don't accept frames from invalid source addresses (and in particular don't try to create stations for them), drop the frames instead.

---

**YES**

This commit should be backported to stable kernel trees. Here's my extensive analysis:

## Security Vulnerability Fixed

The commit fixes a clear security vulnerability in OCB (Outside Context of a BSS) mode where frames with invalid source addresses are accepted and processed. Looking at the code change:

```c
+               /* reject invalid/our STA address */
+               if (!is_valid_ether_addr(hdr->addr2) ||
+                   ether_addr_equal(sdata->dev->dev_addr, hdr->addr2))
+                       return false;
```

This adds critical validation that was missing, preventing:

1. **Invalid MAC addresses** (all zeros, broadcast/multicast addresses) from being accepted
2. **Self-spoofing attacks** where frames appear to come from the device's own address

## Comparison with Similar Historical Fixes

This fix follows the exact pattern of Similar Commit #1 (Backport
Status: YES):
- That commit added !is_valid_ether_addr(hdr->addr2) check to ADHOC mode
- It fixed WARN_ON spam in sta_info_insert_check()
- It was deemed suitable for stable backporting

The OCB fix addresses the same class of vulnerability in a different interface mode.

## Impact Without the Fix

Without this validation, the ieee80211_ocb_rx_no_sta() function would:
1. Create station entries for invalid addresses
2. Potentially trigger WARN_ON messages causing log spam
3. Allow resource exhaustion attacks by creating many invalid stations
4. Risk crashes or undefined behavior from invalid station entries

## Stable Backport Criteria Met

1. **Fixes a real bug**: Yes - invalid frames are incorrectly accepted
2. **Security impact**: Yes - potential DoS via resource exhaustion
3. **Small and contained**: Yes - adds 4 lines of validation
4. **Clear fix**: Yes - straightforward address validation
5. **No new features**: Correct - only adds missing validation
6. **Tested**: Yes - verified by syzbot

## Not Like the "NO" Examples

Unlike the commits marked for NO backporting:
- This is not adding new functionality (like link-addressed frames support)
- This is not a code cleanup or optimization
- This is fixing a concrete security issue reported by syzbot
- This has minimal risk of regression

The fix is essential for OCB mode security and should be backported to all stable kernels that support OCB mode (since 2014).

 net/mac80211/rx.c | 4 ++++
 1 file changed, 4 insertions(+)
net/mac80211/rx.c +4 -0
index 65fea564c9c00..b46c4c770608c 100644
@@ -4097,6 +4097,10 @@ static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
 		if (!multicast &&
 		    !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
 			return false;
+		/* reject invalid/our STA address */
+		if (!is_valid_ether_addr(hdr->addr2) ||
+		    ether_addr_equal(sdata->dev->dev_addr, hdr->addr2))
+			return false;
 		if (!rx->sta) {
 			int rate_idx;
 			if (status->encoding != RX_ENC_LEGACY)
Signature · 1 line
2.39.5
author maintainer
#5 lore raw

PATCH 6/8 wifi: ath6kl: remove WARN on bad firmware input

In reply to Sasha Levin

From: Johannes Berg <[email protected]>

[ Upstream commit e7417421d89358da071fd2930f91e67c7128fbff ]

If the firmware gives bad input, that's nothing to do with the driver's stack at this point etc., so the WARN_ON() doesn't add any value. Additionally, this is one of the top syzbot reports now. Just print a message, and as an added bonus, print the sizes too.

---

**YES**

This commit should be backported to stable kernel trees for the following reasons:

## Security and Stability Impact

1. **Syzbot Report**: The commit explicitly mentions this is "one of the top syzbot reports now", indicating it's a frequently triggered issue that impacts kernel stability testing. Syzbot is Google's continuous fuzzing infrastructure that finds kernel bugs, and high-frequency reports indicate significant impact.

2. **WARN_ON Misuse**: The removed WARN_ON is checking for bad firmware input, which violates kernel best practices. WARN_ON should only be used for "impossible" conditions that indicate kernel bugs, not for validating external input. As the commit message states: "If the firmware gives bad input, that's nothing to do with the driver's stack at this point."

3. **DoS Potential**: A WARN_ON can be triggered by malicious or corrupted firmware, potentially causing:
- Stack traces in kernel logs (log spam)
- Performance degradation
- In some configurations, system panic (if panic_on_warn is set)

## Code Analysis

The change is minimal and safe:

```c
- WARN_ON(1);
+ ath6kl_err("mismatched byte count %d vs. expected %zd\n",
+            le32_to_cpu(targ_info->byte_count),
+            sizeof(*targ_info));
```

The fix:
- Removes the inappropriate WARN_ON
- Adds informative error logging with actual vs expected sizes
- Maintains the same error handling path (return -EINVAL)
- No functional changes beyond logging

## Similar Precedent

Looking at similar commits:
- Commit #5 (ath6kl: reduce WARN to dev_dbg() in callback) - **Backported: YES** - Similar removal of WARN for known race condition
- Commit #3 (ath10k: Change the warning message string) - **Backported:
YES** - Modified warning to avoid syzbot confusion

## Stable Kernel Criteria

This meets stable kernel criteria:
- **Fixes a real bug**: Addresses inappropriate WARN_ON usage that can be triggered by external input
- **Minimal change**: Only removes WARN_ON and adds error message
- **Low risk**: No functional changes, just logging improvement
- **Tested**: Explicitly tested by syzbot
- **Clear benefit**: Reduces false positive warnings and improves debugging

The commit is a straightforward fix that improves kernel robustness without introducing new risks, making it an ideal candidate for stable backporting.

 drivers/net/wireless/ath/ath6kl/bmi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath6kl/bmi.c +3 -1
index af98e871199d3..5a9e93fd1ef42 100644
@@ -87,7 +87,9 @@ int ath6kl_bmi_get_target_info(struct ath6kl *ar,
 		 * We need to do some backwards compatibility to make this work.
 		 */
 		if (le32_to_cpu(targ_info->byte_count) != sizeof(*targ_info)) {
-			WARN_ON(1);
+			ath6kl_err("mismatched byte count %d vs. expected %zd\n",
+				   le32_to_cpu(targ_info->byte_count),
+				   sizeof(*targ_info));
 			return -EINVAL;
 		}
 
Signature · 1 line
2.39.5
author maintainer
#6 lore raw

PATCH 7/8 ACPICA: Refuse to evaluate a method if arguments are missing

In reply to Sasha Levin

From: "Rafael J. Wysocki" <[email protected]>

[ Upstream commit 6fcab2791543924d438e7fa49276d0998b0a069f ]

As reported in [1], a platform firmware update that increased the number of method parameters and forgot to update a least one of its callers, caused ACPICA to crash due to use-after-free.

Since this a result of a clear AML issue that arguably cannot be fixed up by the interpreter (it cannot produce missing data out of thin air), address it by making ACPICA refuse to evaluate a method if the caller attempts to pass fewer arguments than expected to it.

---

**YES**

This commit should be backported to stable kernel trees. Here's my extensive analysis:

## Key Reasons for Backporting:

### 1. **Critical Security Bug - Use-After-Free**
The commit message explicitly states this fixes a use-after-free vulnerability that causes ACPICA to crash. Use-after-free bugs are severe security issues that can lead to:
- System crashes and denial of service
- Potential arbitrary code execution
- Memory corruption

### 2. **Real-World Impact**
The commit references an actual bug report with a specific hardware/firmware scenario:
- Platform firmware update increased method parameters
- Firmware forgot to update at least one caller
- This caused a real crash on actual hardware (Dell XPS 9640 with BIOS 1.12.0)
- The bug has been reported, tested, and verified by multiple people

### 3. **Small, Focused Fix**
The code change is minimal and surgical:

```c
+       if (this_walk_state->num_operands <
obj_desc->method.param_count) {
+               ACPI_ERROR((AE_INFO, "Missing argument for method
[%4.4s]",
+                           acpi_ut_get_node_name(method_node)));
+
+               return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
+       }
```

This adds a simple bounds check before method execution, which is exactly the type of defensive programming that should be in stable kernels.

### 4. **Prevents Memory Corruption**
Looking at the surrounding code (specifically line 542 in the original):

```c
for (i = 0; i < obj_desc->method.param_count; i++) {
    acpi_ut_remove_reference(this_walk_state->operands[i]);
    this_walk_state->operands[i] = NULL;
}
```

Without the check, if num_operands < param_count, this loop would access beyond the valid operands, causing use-after-free.

### 5. **Clear Error Handling**
The fix properly returns AE_AML_UNINITIALIZED_ARG, which is an existing ACPICA error code specifically designed for this scenario ("Method tried to use an uninitialized argument"). This maintains API compatibility.

### 6. **No Architectural Changes**
The commit:
- Doesn't introduce new features
- Doesn't change existing behavior for valid code
- Only adds validation to prevent crashes from invalid AML
- Is confined to the ACPICA subsystem

### 7. **Firmware Bug Mitigation**
This is a defensive fix against firmware bugs, which is exactly the type of robustness stable kernels need. The kernel should not crash due to firmware mistakes.

## Comparison with Similar Commits:

Unlike the similar commits shown (which were mostly about improving error messages or cosmetic changes), this commit:
- Fixes an actual crash/security issue
- Has been reported and tested on real hardware
- Prevents memory corruption
- Is not just a theoretical improvement

This aligns perfectly with stable kernel rules: important bug fixes with minimal risk that improve system stability and security.

 drivers/acpi/acpica/dsmethod.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/acpica/dsmethod.c +7 -0
index 97971c79c5f56..13c67f58e9052 100644
@@ -483,6 +483,13 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
 		return_ACPI_STATUS(AE_NULL_OBJECT);
 	}
 
+	if (this_walk_state->num_operands < obj_desc->method.param_count) {
+		ACPI_ERROR((AE_INFO, "Missing argument for method [%4.4s]",
+			    acpi_ut_get_node_name(method_node)));
+
+		return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
+	}
+
 	/* Init for new method, possibly wait on method mutex */
 
 	status =
Signature · 1 line
2.39.5
author maintainer
#7 lore raw

PATCH 8/8 rcu: Return early if callback is not specified

In reply to Sasha Levin

From: "Uladzislau Rezki (Sony)" <[email protected]>

[ Upstream commit 33b6a1f155d627f5bd80c7485c598ce45428f74f ]

Currently the call_rcu() API does not check whether a callback pointer is NULL. If NULL is passed, rcu_core() will try to invoke it, resulting in NULL pointer dereference and a kernel crash.

To prevent this and improve debuggability, this patch adds a check for NULL and emits a kernel stack trace to help identify a faulty caller.

---

So I can see that in the current code, debug_rcu_head_callback() (called at line 2566 in rcu_do_batch) already checks for NULL func and dumps memory info, but it doesn't prevent the crash - it still proceeds to invoke the NULL function pointer at line 2568.

Now let me understand the commit more - it adds a check in __call_rcu_common() to catch NULL callbacks early and warn about them, preventing them from being queued at all.

## Analysis

**Answer: YES**

This commit should be backported to stable kernel trees for the following reasons:

1. **Fixes a Critical Bug**: The commit addresses a real kernel crash scenario where passing a NULL callback to call_rcu() results in a NULL pointer dereference when rcu_do_batch() tries to invoke the callback at line 2568 (f(rhp)). This is a serious bug that can crash the kernel.

2. **Small and Contained Fix**: The change is minimal - it adds just 4 lines of code:

  ```c
  /* Avoid NULL dereference if callback is NULL. */
  if (WARN_ON_ONCE(!func))
  return;
  ```

This is exactly the type of small, focused fix that stable trees prefer.

3. **Defensive Programming**: While the existing code already has debug_rcu_head_callback() that checks for NULL func and dumps memory info (as seen in similar commit #2), it doesn't prevent the crash. This commit adds a proper early return to prevent the NULL callback from being queued at all.

4. **No Side Effects**: The fix simply validates input parameters and returns early if invalid. It doesn't change any architecture, doesn't introduce new features, and has minimal risk of regression.

5. **Clear Bug Prevention**: The commit prevents a programming error (passing NULL callback) from escalating into a kernel crash. Even though passing NULL is a programmer error, the kernel should handle it gracefully rather than crashing.

6. **Similar to Stable-Worthy Commits**: Looking at the similar commits, commit #2 ("rcu: Dump memory object info if callback function is invalid") was marked as suitable for backporting (YES) and dealt with a similar issue of invalid callbacks. That commit added debugging for when callbacks become NULL after being queued, while this commit prevents NULL callbacks from being queued in the first place.

The fix follows the stable kernel rules perfectly:
- It fixes a real bug (kernel crash)
- It's small and obvious
- It has been tested (as indicated by the review process)
- It doesn't add features or change behavior for valid use cases
- It improves kernel robustness without any downside

This is a textbook example of a commit that should be backported to stable trees to improve kernel reliability across all supported versions.

 kernel/rcu/tree.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/rcu/tree.c +4 -0
index 06bfe61d3cd38..c4eb06d37ae91 100644
@@ -2959,6 +2959,10 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func)
 	/* Misaligned rcu_head! */
 	WARN_ON_ONCE((unsigned long)head & (sizeof(void *) - 1));
 
+	/* Avoid NULL dereference if callback is NULL. */
+	if (WARN_ON_ONCE(!func))
+		return;
+
 	if (debug_rcu_head_queue(head)) {
 		/*
 		 * Probable double call_rcu(), so leak the callback.
Signature · 1 line
2.39.5