Article View: linux.kernel.netdev
Article #2261[PATCH v3] vhost-scsi: do not count PI bytes in the data length
From: Jia Jia
Date: Mon, 12 Oct 2026 10:39
Date: Mon, 12 Oct 2026 10:39
84 lines
11141 bytes
11141 bytes
vhost_scsi_handle_vq() moves pi_bytesout or pi_bytesin into the
protection sgl and subtracts those bytes from exp_data_len. The length
passed to TCM is still exp_data_len + prot_bytes.
prot_bytes comes from virtio_scsi_cmd_req_pi. With
VIRTIO_SCSI_F_T10_PI negotiated, vhost reads that header and does not
check that the CDB is a READ or WRITE. sbc_check_prot() replaces
data_length from the CDB only when the protect field is non-zero.
target_cmd_size_check() leaves a write's data_length unchanged when the
CDB size is smaller, so a command that does not get that replacement
keeps a data_length larger than the data sgl.
The KASAN report is a MODE SELECT whose header had pi_bytesout set.
The data sgl held only the parameter list. spc_emulate_modeselect()
walked data_length and read the next physical page.
Pass the data sgl length. Protected READ and WRITE still take their
length from the CDB in sbc_check_prot().
KASAN reports:
BUG: KASAN: use-after-free in spc_emulate_modeselect+0x145/0x380 [target_core_mod]
Read of size 1
spc_emulate_modeselect
__target_execute_cmd
target_execute_cmd
vhost_scsi_write_pending
transport_generic_new_cmd
__target_submit
target_queued_submit_work
process_one_work
worker_thread
kthread
ret_from_fork
ret_from_fork_asm
Fixes: 9f977ef7b671 ("vhost-scsi: Include prot_bytes into expected data transfer length")
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
---
v3:
- Rewrite the inline comment to distinguish the data and protection
SGLs and explain why TCM receives only the data SGL length.
- Note the related target-core patches for PI tuple accesses at
protection-SGL boundaries:
https://lore.kernel.org/all/20261006093338.27342-5-physicalmtea@gmail.com/
https://lore.kernel.org/all/20261006093338.27342-6-physicalmtea@gmail.com/
https://lore.kernel.org/all/20261006093338.27342-7-physicalmtea@gmail.com/
v2:
- Drop the claim that target used to subtract prot_length.
9f977ef7b671 cites 14ef9200, which is not in the tree
- prot_bytes comes from virtio_scsi_cmd_req_pi
drivers/vhost/scsi.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 4f8c0260bc9e..4bd29c2ceed9 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1534,9 +1534,17 @@ vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq)
* vhost_scsi_queue_data_in() and vhost_scsi_queue_status()
*/
cmd->tvc_vq_desc = vc.head;
+ /*
+ * vhost_scsi_mapal() maps the PI bytes into cmd->prot_table.
+ * It maps the remaining exp_data_len bytes into cmd->table,
+ * which is the data SGL passed to the target core. Its
+ * expected length must therefore exclude prot_bytes.
+ *
+ * sbc_check_prot() derives the data length for protected READ
+ * and WRITE commands from the CDB.
+ */
vhost_scsi_target_queue_cmd(nexus, cmd, cdb, lun, task_attr,
- data_direction,
- exp_data_len + prot_bytes);
+ data_direction, exp_data_len);
ret = 0;
err:
/*
--
2.53.0
Technical Details
Message-ID:
<20261012103954.136698-1-physicalmtea@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344898-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344898-linux-kernel-netdev=dewy.ru
From: physicalmtea@gmail.com (Jia Jia)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v3] vhost-scsi: do not count PI bytes in the data length
Date: Mon, 12 Oct 2026 18:39:54 +0800
Organization: Usenet Network
Message-ID: <20261012103954.136698-1-physicalmtea@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1749013"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:K7fUW0fFZRqafLC3+mKfIpy3FDQ= sha256:tKJOVluKQ5xe3chhDcXz+/S45xKVNns7+kfgkc6uz8Y=
sha1:rFpR+y1njH5lJwRiHrQlaBqkK3E= sha256:XwZkm7KqwT6ccXblPtPWpMGEWRJPnle/wzjLfseCLrY=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 067E410FB93; Mon, 12 Oct 2026 13:41:17 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.749
X-Spam-Status: No, score=-0.749 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id rkuCXyifYunE;
Mon, 12 Oct 2026 13:41:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-344898-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id E7E3F10F81D; Mon, 12 Oct 2026 13:41:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by tor.lore.kernel.org (Postfix) with ESMTP id 1E2572DC5F; Mon, 12 Oct 2026 10:40:34 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id EBDE53ACA5C;
Mon, 12 Oct 2026 10:40:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hufXMIw0"
X-Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0CF13AAF5F
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 10:40:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791801627; cv=none; b=OwU0KSVWki5YMu75Nm511JyDK/SdC5QGiDv9C7GJtiAxvU5pcHStd80TutlNpNONdHJKjGfUoKMnr9oLgRxHCBjiwQeeLxedpA+2V2WWq4NmPv7nFLqHIVjCflhwv3ytbn1q0wDOGPhRv2cDpBw7ETy/hwrZo+RRFU7nhpDwbTU=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791801627; c=relaxed/simple;
bh=vFkCRtgxGCnpOhlZA7FYzY49jEv/8nkM8zfXlvjQOfQ=;
h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=faYLlsXM377KMsNh9vMig81jPXG+fX0fsSJuCGUWObUqDdU0yd48qXTP5yVfOBRj+zhiCkdz13h0OyDauqVNpFZH49FT6gJ8xpW80FEhCZYb8LhDuf6eCpK+Wlcqt+v3ciF864onj6eJLOs9+IoPRMtKTy1aqeFTLecb39WMIkM=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hufXMIw0; arc=none smtp.client-ip=74.125.82.171
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-33e6279a1d7so459987eec.1
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 03:40:26 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791801626; x=1792406426; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=3l61iXys9UAgeiq6Qoow/JEP0G8Esaw8ppQEGcd0fNQ=;
b=hufXMIw0EVpInfTHhpYb/QUt24+17FSeX5h06Wfnpgb8Jkqyyg8piXuqxx0i625Ai/
d1vDYYMkZ+rRr30gF8oMr/6BYgyg9nnWRXXjq7qrdsMkFBencCoYq0KKVxe4dFuKqDdA
duwdxgMF+BUMMevDDeIs/s9YhAgGSLzDgmafK5TY7GcB1laaUuybDctQojzxBOeaoBdN
V7kDovVSMCCZs+TYIVIFuBUB7ZLi5fnvzeA/FT0HhRFFbgD6IbZS/j77mtX+TwzxYbJ4
RPfwXqe2M2dA8zSmwVeABniRXbFeYUNUG1Pqnk2e2EU+NrxUOc5FgDbkatK5yVGjHi09
80mA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791801626; x=1792406426;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=3l61iXys9UAgeiq6Qoow/JEP0G8Esaw8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MBBT63qZHC+yfod+YlfEAnF4nr2F0Kb9k5IpycLidGaKvOYX4QQ==
X-Received: by 2002:a05:701b:2058:20b0:15c:20b8:7964 with SMTP id a92af1059eb24-16a63386d86mr13548313c88.27.1791801625139;
Mon, 12 Oct 2026 03:40:25 -0700 (PDT)
X-Received: from gmail.com ([188.253.12.32])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3537cb2fd33sm31434866eec.28.2026.10.12.03.40.21
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 12 Oct 2026 03:40:24 -0700 (PDT)
X-Cc: "Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowangio@gmail.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Eugenio PΓ©rez <eperezma@redhat.com>,
Nicholas Bellinger <nab@linux-iscsi.org>,
virtualization@lists.linux.dev,
kvm@vger.kernel.org,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jia Jia <physicalmtea@gmail.com>
X-Mailer: git-send-email 2.34.1
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>