public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Maurizio Lombardi <mlombard@redhat.com>,
	Zhaojuan Guo <zguo@redhat.com>,
	Mike Christie <michael.christie@oracle.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	tglx@kernel.org, mingo@kernel.org
Subject: [PATCH AUTOSEL 6.18-5.10] scsi: target: iscsi: Fix use-after-free in iscsit_dec_session_usage_count()
Date: Mon,  2 Feb 2026 16:46:08 -0500	[thread overview]
Message-ID: <20260202214643.212290-13-sashal@kernel.org> (raw)
In-Reply-To: <20260202214643.212290-1-sashal@kernel.org>

From: Maurizio Lombardi <mlombard@redhat.com>

[ Upstream commit 84dc6037390b8607c5551047d3970336cb51ba9a ]

In iscsit_dec_session_usage_count(), the function calls complete() while
holding the sess->session_usage_lock. Similar to the connection usage count
logic, the waiter signaled by complete() (e.g., in the session release
path) may wake up and free the iscsit_session structure immediately.

This creates a race condition where the current thread may attempt to
execute spin_unlock_bh() on a session structure that has already been
deallocated, resulting in a KASAN slab-use-after-free.

To resolve this, release the session_usage_lock before calling complete()
to ensure all dereferences of the sess pointer are finished before the
waiter is allowed to proceed with deallocation.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
Reported-by: Zhaojuan Guo <zguo@redhat.com>
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Link: https://patch.msgid.link/20260112165352.138606-3-mlombard@redhat.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

Excellent! Now I have a complete understanding. Let me summarize my
analysis:

## ANALYSIS

### 1. COMMIT MESSAGE ANALYSIS

The commit message clearly describes:
- **Bug type:** Use-after-free (UAF)
- **Root cause:** `complete()` is called while holding
  `sess->session_usage_lock`, but the waiter (in session release path)
  may wake up and call `kfree(sess)` before the lock is released
- **Detection:** KASAN slab-use-after-free
- **Fix:** Release the lock before calling `complete()`
- **Tags:**
  - `Reported-by:` - indicates a real bug report
  - `Reviewed-by: Mike Christie` - credible reviewer for SCSI/iSCSI
    target code

### 2. CODE CHANGE ANALYSIS

**The bug mechanism:**
1. Thread A calls `iscsit_dec_session_usage_count()`, decrements count
   to 0
2. Thread A calls `complete()` while still holding
   `sess->session_usage_lock`
3. Thread B (waiting in `iscsit_check_session_usage_count()`) wakes up
   from `wait_for_completion()`
4. Thread B continues to `iscsit_close_session()` → `kfree(sess)` at
   line 4519
5. Thread A tries to call `spin_unlock_bh(&sess->session_usage_lock)` on
   freed memory → **UAF**

**The fix:**
- Releases the spinlock *before* calling `complete()`
- Uses early return to avoid double-unlock
- This is a standard pattern for avoiding UAF when completion wakes up a
  free-er

**Size:** +4 lines changed, -1 line changed = 3 net lines. Very small
and surgical.

### 3. CLASSIFICATION

- **Bug fix:** Yes, fixes a clear use-after-free
- **Security:** Use-after-free bugs can potentially be exploited for
  privilege escalation or code execution, though this one is in iSCSI
  target code which requires privileged access to configure
- **Severity:** HIGH - UAF can cause kernel crashes (KASAN detected) and
  potential security issues

### 4. SCOPE AND RISK ASSESSMENT

- **Lines changed:** ~5 lines (minimal)
- **Files touched:** 1 file (`drivers/target/iscsi/iscsi_target_util.c`)
- **Complexity:** Very low - simply reorders lock release and complete()
  call
- **Subsystem:** iSCSI target - mature, widely used for storage
- **Risk:** Very LOW - the fix is semantically identical (unlock happens
  either way), just changes order

### 5. USER IMPACT

- **Affected users:** Anyone using Linux iSCSI target (LIO) with active
  session teardown
- **Severity if hit:** Kernel crash/panic, or potentially worse
  (security issue)
- **Likelihood:** Race condition, so timing-dependent, but clearly can
  be triggered (reported by Red Hat engineer with KASAN)

### 6. STABILITY INDICATORS

- `Reviewed-by: Mike Christie <michael.christie@oracle.com>` - Mike
  Christie is a well-known SCSI subsystem maintainer/contributor
- `Reported-by:` tag indicates this is a real-world bug
- Accepted by Martin K. Petersen (SCSI maintainer)

### 7. DEPENDENCY CHECK

- No dependencies on other commits
- The `session_usage_lock`, `session_waiting_on_uc`, and completion
  structure exist in all stable trees (they're fundamental to iSCSI
  target operation)
- Clean, standalone fix

### CONCLUSION

This commit is an **ideal candidate for stable backport**:

1. **Fixes a real, serious bug:** Use-after-free detected by KASAN,
   reported by Red Hat
2. **Obviously correct:** Standard pattern of "unlock before complete
   when waiter frees the object"
3. **Small and contained:** Only 5 lines changed in one function
4. **No new features:** Pure bug fix
5. **Low risk:** The change is semantically equivalent (lock must be
   released anyway), just changes order
6. **Wide impact:** iSCSI target is widely deployed in enterprise
   storage environments
7. **Reviewed by expert:** Mike Christie is a recognized SCSI expert

The fix follows the well-established pattern seen in many similar fixes
throughout the kernel where a completion must not be signaled while
holding a lock that protects the structure being freed by the waiter.

**YES**

 drivers/target/iscsi/iscsi_target_util.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c
index 5e6cf34929b55..262a3e76b4b1c 100644
--- a/drivers/target/iscsi/iscsi_target_util.c
+++ b/drivers/target/iscsi/iscsi_target_util.c
@@ -741,8 +741,11 @@ void iscsit_dec_session_usage_count(struct iscsit_session *sess)
 	spin_lock_bh(&sess->session_usage_lock);
 	sess->session_usage_count--;
 
-	if (!sess->session_usage_count && sess->session_waiting_on_uc)
+	if (!sess->session_usage_count && sess->session_waiting_on_uc) {
+		spin_unlock_bh(&sess->session_usage_lock);
 		complete(&sess->session_waiting_on_uc_comp);
+		return;
+	}
 
 	spin_unlock_bh(&sess->session_usage_lock);
 }
-- 
2.51.0


  parent reply	other threads:[~2026-02-02 21:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 21:45 [PATCH AUTOSEL 6.18-6.12] ALSA: hda/realtek - fixed speaker no sound Sasha Levin
2026-02-02 21:45 ` [PATCH AUTOSEL 6.18-5.10] ALSA: hda/realtek: Fix headset mic for TongFang X6AR55xU Sasha Levin
2026-02-02 21:45 ` [PATCH AUTOSEL 6.18] io_uring/rw: free potentially allocated iovec on cache put failure Sasha Levin
2026-02-02 21:45 ` [PATCH AUTOSEL 6.18-6.12] ALSA: hda/realtek: ALC269 fixup for Lenovo Yoga Book 9i 13IRU8 audio Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] ALSA: usb-audio: Add delay quirk for MOONDROP Moonriver2 Ti Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.1] ASoC: amd: yc: Add ASUS ExpertBook PM1503CDA to quirks list Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-5.10] gpio: sprd: Change sprd_gpio lock to raw_spin_lock Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.6] spi: hisi-kunpeng: Fixed the wrong debugfs node name in hisi_spi debugfs initialization Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.1] ASoC: cs35l45: Corrects ASP_TX5 DAPM widget channel Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-5.10] scsi: target: iscsi: Fix use-after-free in iscsit_dec_conn_usage_count() Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.1] ALSA: hda/realtek: Add quirk for Inspur S14-G1 Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] btrfs: fix Wmaybe-uninitialized warning in replay_one_buffer() Sasha Levin
2026-02-02 21:46 ` Sasha Levin [this message]
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] Revert "drm/amd/display: pause the workload setting in dm" Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] btrfs: sync read disk super and set block size Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-5.10] wifi: mac80211: don't increment crypto_tx_tailroom_needed_cnt twice Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] spi: intel-pci: Add support for Nova Lake SPI serial flash Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.12] btrfs: reject new transactions if the fs is fully read-only Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] riscv: Use 64-bit variable for output in __get_user_asm Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.6] regmap: maple: free entry on mas_store_gfp() failure Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-6.6] wifi: mac80211: correctly check if CSA is active Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-5.10] romfs: check sb_set_blocksize() return value Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18-5.10] wifi: cfg80211: Fix bitrate calculation overflow for HE rates Sasha Levin
2026-02-02 21:46 ` [PATCH AUTOSEL 6.18] tracing: Avoid possible signed 64-bit truncation Sasha Levin
  -- strict thread matches above, loose matches on Subject: below --
2026-01-28 22:32 [PATCH AUTOSEL 6.18-5.10] ALSA: hda/realtek: Fix headset mic for TongFang X6AR55xU Sasha Levin
2026-01-28 22:33 ` [PATCH AUTOSEL 6.18-5.10] scsi: target: iscsi: Fix use-after-free in iscsit_dec_session_usage_count() 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=20260202214643.212290-13-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=mingo@kernel.org \
    --cc=mlombard@redhat.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=zguo@redhat.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