patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	Jens Axboe <axboe@kernel.dk>, Sasha Levin <sashal@kernel.org>,
	io-uring@vger.kernel.org
Subject: [PATCH AUTOSEL 6.17] io_uring: fix unexpected placement on same size resizing
Date: Mon, 27 Oct 2025 20:38:57 -0400	[thread overview]
Message-ID: <20251028003940.884625-13-sashal@kernel.org> (raw)
In-Reply-To: <20251028003940.884625-1-sashal@kernel.org>

From: Pavel Begunkov <asml.silence@gmail.com>

[ Upstream commit 437c23357d897f5b5b7d297c477da44b56654d46 ]

There might be many reasons why a user is resizing a ring, e.g. moving
to huge pages or for some memory compaction using IORING_SETUP_NO_MMAP.
Don't bypass resizing, the user will definitely be surprised seeing 0
while the rings weren't actually moved to a new place.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## BACKPORT RECOMMENDATION: **YES**

### DETAILED ANALYSIS

#### 1. Semantic Code Analysis Performed

**Tools Used:**
- `mcp__semcode__find_function`: Located `io_register_resize_rings`
  function definition in `io_uring/register.c:401-585`
- `mcp__semcode__find_callers`: Identified that the function is called
  by `__io_uring_register`
- Git analysis: Traced the syscall path from user-space →
  `sys_io_uring_register` → `__io_uring_register` →
  `io_register_resize_rings`
- Historical analysis: Determined the resize feature was introduced in
  kernel v6.13 (October 2024)

**Call Graph Analysis:**
```
user-space (io_uring_register syscall with IORING_REGISTER_RESIZE_RINGS
opcode)
  └→ sys_io_uring_register (SYSCALL_DEFINE4)
      └→ __io_uring_register
          └→ io_register_resize_rings  [BUG HERE]
```

#### 2. Nature of the Bug

**What Changed:**
The commit removes 7 lines of code (io_uring/register.c:421-427) that
implemented an optimization:
```c
/* nothing to do, but copy params back */
if (p.sq_entries == ctx->sq_entries && p.cq_entries == ctx->cq_entries)
{
    if (copy_to_user(arg, &p, sizeof(p)))
        return -EFAULT;
    return 0;  // Returns success WITHOUT actually resizing
}
```

**Why It's a Bug:**
This optimization incorrectly assumes that if the ring size parameters
match, there's nothing to do. However, users have legitimate reasons to
resize with the same dimensions:

1. **Memory relocation to huge pages**: Using `IORING_SETUP_NO_MMAP`
   flag to move rings to huge page-backed memory for better TLB
   performance
2. **Memory compaction**: Consolidating memory allocations
3. **Memory region changes**: Moving rings to different physical memory
   locations

The kernel returns success (0) but silently doesn't perform the
requested operation, breaking the user-space API contract.

#### 3. Impact Assessment

**Severity: Medium**

**Who is affected:**
- Applications using `IORING_REGISTER_RESIZE_RINGS` (added in v6.13)
- Specific scenario: Resizing to same dimensions for memory management
  purposes
- Use cases: Performance-critical applications optimizing memory layout
  via huge pages

**User-space exposure:**
- **Directly exposed via syscall**: Yes, through `io_uring_register(fd,
  IORING_REGISTER_RESIZE_RINGS, ...)`
- **Exploitability**: Not a security issue, but causes silent functional
  failure
- **Data corruption risk**: None, but causes application logic bugs when
  applications expect memory to be reallocated

#### 4. Backport Suitability Analysis

**Positive Indicators:**
1. ✅ **Bug fix, not a feature**: Removes broken optimization
2. ✅ **Small, contained change**: Only 7 lines removed, no new code
   added
3. ✅ **No architectural changes**: Doesn't modify data structures or
   APIs
4. ✅ **Low regression risk**: Removes code rather than adding complex
   logic
5. ✅ **Clear functional issue**: Kernel claims success but doesn't
   perform requested operation
6. ✅ **Affects real use cases**: Huge page optimization is documented in
   commit message as legitimate use case

**Context:**
- Feature introduced: v6.13 (October 2024)
- Bug exists: v6.13 through v6.17
- Fix landed: v6.18-rc2
- No explicit `Fixes:` or `Cc: stable` tags in the commit (oversight by
  author)

**Stable Tree Compliance:**
- Bug fixes: ✅ YES
- New features: ✅ NO
- Security fixes: ✅ NO (but functional correctness issue)
- Performance optimizations: ⚠️ Removes a broken optimization
- Architectural changes: ✅ NO

#### 5. Dependencies and Prerequisites

The fix requires:
- `IORING_REGISTER_RESIZE_RINGS` support (present in v6.13+)
- No other dependencies identified

**Version compatibility:** This should be backported to stable kernels
v6.13+

#### 6. Risk Assessment

**Regression risk: VERY LOW**

The change **removes** code rather than adding it:
- The removed code was an optimization that caused incorrect behavior
- Removing it makes the function always perform the full resize
  operation
- All existing code paths after the removed check remain unchanged
- The function already handles the case where source and destination
  sizes match (it copies entries correctly)

**Testing considerations:**
- Test case: Call `IORING_REGISTER_RESIZE_RINGS` with same size +
  `IORING_SETUP_NO_MMAP` flag
- Expected: Memory should be reallocated to new location
- Current broken behavior: Returns 0 but doesn't reallocate

### CONCLUSION

**BACKPORT: YES to stable v6.13+ kernels**

This is a clear functional bug in a newly added feature. While it lacks
explicit stable tree tags, it meets all criteria for backporting:
- Fixes incorrect behavior exposed to user-space
- Small, contained, low-risk change
- Affects legitimate use cases (huge page optimization)
- No dependencies or architectural complexity
- Removes broken code rather than adding risky new logic

The absence of `Fixes:` or `Cc: stable` tags appears to be an oversight,
not an indication that backporting is inappropriate. The commit message
explicitly describes the bug and its user-space impact, making this a
suitable candidate for stable tree inclusion.

 io_uring/register.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/io_uring/register.c b/io_uring/register.c
index b1772a470bf6e..dacbe8596b5c2 100644
--- a/io_uring/register.c
+++ b/io_uring/register.c
@@ -426,13 +426,6 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
 	if (unlikely(ret))
 		return ret;
 
-	/* nothing to do, but copy params back */
-	if (p.sq_entries == ctx->sq_entries && p.cq_entries == ctx->cq_entries) {
-		if (copy_to_user(arg, &p, sizeof(p)))
-			return -EFAULT;
-		return 0;
-	}
-
 	size = rings_size(p.flags, p.sq_entries, p.cq_entries,
 				&sq_array_offset);
 	if (size == SIZE_MAX)
-- 
2.51.0


  parent reply	other threads:[~2025-10-28  0:40 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  0:38 [PATCH AUTOSEL 6.17-6.1] smb/server: fix possible memory leak in smb2_read() Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-5.4] NFS4: Fix state renewals missing after boot Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-6.12] drm/amdgpu: remove two invalid BUG_ON()s Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-5.15] NFS: check if suid/sgid was cleared after a write as needed Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-6.12] HID: logitech-hidpp: Add HIDPP_QUIRK_RESET_HI_RES_SCROLL Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-5.4] ASoC: max98090/91: fixed max98091 ALSA widget powering up/down Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17] ALSA: hda/realtek: Fix mute led for HP Omen 17-cb0xxx Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-5.10] RISC-V: clear hot-unplugged cores from all task mm_cpumasks to avoid rfence errors Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17] ASoC: nau8821: Avoid unnecessary blocking in IRQ handler Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-5.4] HID: quirks: avoid Cooler Master MM712 dongle wakeup bug Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17] drm/amdkfd: fix suspend/resume all calls in mes based eviction path Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-6.12] exfat: fix improper check of dentry.stream.valid_size Sasha Levin
2025-10-28  0:38 ` Sasha Levin [this message]
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17] drm/amd: Disable ASPM on SI Sasha Levin
2025-10-28  0:38 ` [PATCH AUTOSEL 6.17-6.6] riscv: acpi: avoid errors caused by probing DT devices when ACPI is used Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.1] drm/amd/pm: Disable MCLK switching on SI at high pixel clocks Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.12] drm/amdgpu: hide VRAM sysfs attributes on GPUs without VRAM Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17] fs: return EOPNOTSUPP from file_setattr/file_getattr syscalls Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.12] NFS4: Apply delay_retrans to async operations Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.1] drm/amdgpu: Fix NULL pointer dereference in VRAM logic for APU devices Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17] ixgbe: handle IXGBE_VF_FEATURES_NEGOTIATE mbox cmd Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17] ixgbe: handle IXGBE_VF_GET_PF_LINK_STATE mailbox operation Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.6] HID: quirks: Add ALWAYS_POLL quirk for VRS R295 steering wheel Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17] HID: intel-thc-hid: intel-quickspi: Add ARL PCI Device Id's Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.12] HID: nintendo: Wait longer for initial probe Sasha Levin
2025-10-28  0:39 ` [PATCH AUTOSEL 6.17-6.1] smb/server: fix possible refcount leak in smb2_sess_setup() Sasha Levin

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=20251028003940.884625-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).