public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Szymon Wilczek <szymonwilczek@gmx.com>,
	syzbot+405dcd13121ff75a9e16@syzkaller.appspotmail.com,
	Mike Isely <isely@pobox.com>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-5.10] media: pvrusb2: fix URB leak in pvr2_send_request_ex
Date: Fri, 13 Feb 2026 19:59:47 -0500	[thread overview]
Message-ID: <20260214010245.3671907-107-sashal@kernel.org> (raw)
In-Reply-To: <20260214010245.3671907-1-sashal@kernel.org>

From: Szymon Wilczek <szymonwilczek@gmx.com>

[ Upstream commit a8333c8262aed2aedf608c18edd39cf5342680a7 ]

When pvr2_send_request_ex() submits a write URB successfully but fails to
submit the read URB (e.g. returns -ENOMEM), it returns immediately without
waiting for the write URB to complete. Since the driver reuses the same
URB structure, a subsequent call to pvr2_send_request_ex() attempts to
submit the still-active write URB, triggering a 'URB submitted while
active' warning in usb_submit_urb().

Fix this by ensuring the write URB is unlinked and waited upon if the read
URB submission fails.

Reported-by: syzbot+405dcd13121ff75a9e16@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=405dcd13121ff75a9e16
Signed-off-by: Szymon Wilczek <szymonwilczek@gmx.com>
Acked-by: Mike Isely <isely@pobox.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis of pvrusb2 URB Leak Fix

### 1. Commit Message Analysis

The commit message is clear and well-structured:
- **Subject**: Explicitly says "fix URB leak" — this is a bug fix
- **Problem**: When the write URB is submitted successfully but the read
  URB submission fails, the function returns without waiting for the
  write URB to complete. The URB structure is reused, so a subsequent
  call tries to submit a still-active URB.
- **Symptom**: Triggers a `'URB submitted while active'` warning in
  `usb_submit_urb()`, which is a well-known USB core warning indicating
  a real bug.
- **Reporter**: syzbot — fuzzer-found, reproducible bug
- **Acked-by**: Mike Isely (pvrusb2 maintainer) — subsystem maintainer
  approved
- **Signed-off-by**: Hans Verkuil (media subsystem maintainer) — proper
  review chain

### 2. Code Change Analysis

The fix adds 5 lines of code in a single error path:

```c
if (hdw->ctl_write_pend_flag) {
    usb_unlink_urb(hdw->ctl_write_urb);
    while (hdw->ctl_write_pend_flag)
        wait_for_completion(&hdw->ctl_done);
}
```

**What it does**: When the read URB submission fails (`status < 0`), but
the write URB was already submitted and is pending
(`ctl_write_pend_flag` set), the fix:
1. Unlinks (cancels) the still-active write URB
2. Waits for the write URB completion callback to fire (which clears
   `ctl_write_pend_flag`)

This is the correct pattern — it mirrors what the existing code already
does in the normal path (the `while (hdw->ctl_write_pend_flag ||
hdw->ctl_read_pend_flag)` loop further down), but adapted for this
specific error path.

### 3. Bug Classification

- **Type**: Resource leak / URB lifecycle mismanagement
- **Trigger**: Read URB submission failure (e.g., -ENOMEM) after
  successful write URB submission
- **Consequence**:
  - Active URB left dangling
  - Next call to the same function triggers `'URB submitted while
    active'` warning
  - Could lead to undefined behavior with the USB subsystem, potential
    data corruption or crashes
- **Reproducibility**: syzbot found it — reproducible with a concrete
  trigger

### 4. Scope and Risk Assessment

- **Lines changed**: +5 lines added in a single file
- **Files affected**: 1 file (`drivers/media/usb/pvrusb2/pvrusb2-hdw.c`)
- **Complexity**: Very low — straightforward error path cleanup
- **Risk**: Minimal. The fix uses standard USB patterns
  (`usb_unlink_urb` + wait for completion) that are well-established
  throughout the kernel. The `ctl_write_pend_flag` check ensures we only
  unlink if the write URB is actually active.
- **Regression potential**: Very low. This code path only executes when
  read URB submission fails, and the fix ensures proper cleanup before
  proceeding — strictly better than the current behavior.

### 5. User Impact

- **Affected users**: Anyone using pvrusb2 USB TV capture devices
- **Severity**: Medium-high — while pvrusb2 is not a widely-used driver,
  submitting a still-active URB can cause USB core issues, kernel
  warnings, and potentially crashes
- **Trigger likelihood**: Moderate — memory pressure situations can
  cause `-ENOMEM` from `usb_submit_urb()`

### 6. Stability and Trust Indicators

- **Reported-by**: syzbot (automated, reproducible)
- **Acked-by**: Subsystem maintainer (Mike Isely)
- **Merged by**: Media subsystem maintainer (Hans Verkuil)
- **Fix pattern**: Standard, well-understood USB cleanup pattern

### 7. Dependencies

The fix is self-contained — it uses existing infrastructure
(`usb_unlink_urb`, `wait_for_completion`, existing flags) that has been
present in the pvrusb2 driver for years. No dependency on other recent
commits.

### 8. Stable Kernel Criteria

| Criterion | Met? |
|-----------|------|
| Obviously correct and tested | Yes — syzbot-reported, maintainer-acked
|
| Fixes a real bug | Yes — URB leak, 'URB submitted while active' |
| Important issue | Yes — can cause USB subsystem issues and warnings |
| Small and contained | Yes — 5 lines, 1 file |
| No new features | Correct — pure bug fix |
| Applies cleanly | Likely — the pvrusb2 code is stable and rarely
changed |

### Conclusion

This is a textbook stable backport candidate: a small, surgical fix for
a syzbot-reported URB lifecycle bug in a USB driver. It's maintainer-
acked, uses established patterns, has minimal regression risk, and fixes
a real bug that can cause kernel warnings and potential instability. The
fix is self-contained with no dependencies.

**YES**

 drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index b32bb906a9de2..5807734ae26c6 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -3709,6 +3709,11 @@ status);
 				   "Failed to submit read-control URB status=%d",
 status);
 			hdw->ctl_read_pend_flag = 0;
+			if (hdw->ctl_write_pend_flag) {
+				usb_unlink_urb(hdw->ctl_write_urb);
+				while (hdw->ctl_write_pend_flag)
+					wait_for_completion(&hdw->ctl_done);
+			}
 			goto done;
 		}
 	}
-- 
2.51.0


  parent reply	other threads:[~2026-02-14  1:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-14  0:58 [PATCH AUTOSEL 6.19-6.12] media: ipu6: Close firmware streams on streaming enable failure Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: chips-media: wave5: Fix conditional in start_streaming Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: mt9m114: Avoid a reset low spike during probe() Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.1] media: amphion: Clear last_buffer_dequeued flag for DEC_CMD_START Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-5.10] media: adv7180: fix frame interval in progressive mode Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.6] media: v4l2-async: Fix error handling on steps after finding a match Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.1] media: rkisp1: Fix filter mode register configuration Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: ipu6: Ensure stream_mutex is acquired when dealing with node list Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] media: uvcvideo: Create an ID namespace for streaming output terminals Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.12] media: ipu6: Always close firmware stream Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] media: qcom: camss: Do not enable cpas fast ahb clock for SM8550 VFE lite Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-5.10] media: solo6x10: Check for out of bounds chip_id Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] drm/amdgpu: Refactor amdgpu_gem_va_ioctl for Handling Last Fence Update and Timeline Management v4 Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.12] media: chips-media: wave5: Process ready frames when CMD_STOP sent to Encoder Sasha Levin
2026-02-14  0:59 ` Sasha Levin [this message]
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-5.10] media: dvb-core: dmxdevfilter must always flush bufs 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=20260214010245.3671907-107-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=hverkuil+cisco@kernel.org \
    --cc=isely@pobox.com \
    --cc=linux-media@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+405dcd13121ff75a9e16@syzkaller.appspotmail.com \
    --cc=szymonwilczek@gmx.com \
    /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