From nobody Sat Jul 25 04:54:17 2026 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 C1E97422532 for ; Fri, 17 Jul 2026 14:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784299449; cv=none; b=KU5VVSyjomyho98LcMpk10sRobz8GEOAvVMDXKhSuCckr95Zpt/rugMAhGXleXMqvg5Jr8OOKjQSYbpNYmSLdXbcPBvMvOpX8dNWLc429B7Wgb3CaydV8DjchcgV2XztjCzA4XFfPIWUjxXENIeiHOr83B0yoy8V5tOJ/DZbxKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784299449; c=relaxed/simple; bh=Iw0b/Nwh/H9LGk9o/5pyDDEhZjwGXhyHgsUJaHjUFPM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=O/fdGjn/IUDZRJFmrpYDbYLaKLzPRZCsXjjuKaX36IlB4b4EhQWhKq+zh1n/uvzo8cs5/T+Oah+2xoW6KkqT22lTH8N8DeA7AJtlfqk8P6xaJH62qbkSZ3xERRTrvVPFdsbiYQmkfgqqkdmyu9tn34ifKvgUWtVrPqhdOV+bZNM= 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=Fu8RkWxT; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fu8RkWxT" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-69e7a5b61e4so497123a12.2 for ; Fri, 17 Jul 2026 07:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784299446; x=1784904246; 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=xCkYbjx2cQyuHcwYogCXd80/iygZG2u+MVDPY/mY78g=; b=Fu8RkWxT9B+yqKznTWF8zwIzRifj5tPaCZG75EqrBOVDyXB7fv74/ZqDAc1RQ92DOi K/YH1z2VnE9mMfDBaGIpE1Y//qkF2zF2jQ0HVa3F4kTtYOWPzLRHC0ds+fk3ESc8tQqS pZy8F83Ks9JjbzMp9VLcdrf4vPYtduATK0sRw0l7RVi+FSt4tBPy4mCt5euYV18ZZHbs QmA+Huw+Grz2b1uKTDMa2gB9l/hhtsFB7XAHgvtH8uwWz+CZlM8gfbOCDJpvoChiBVqV aHfGlNUkYWuiSFRdk4+dOxIxJDc5k5ohdauJkaJea0obrSAHEQtXRgjsSXMZQNUAJH0y nYtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784299446; x=1784904246; 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=xCkYbjx2cQyuHcwYogCXd80/iygZG2u+MVDPY/mY78g=; b=I7jikrMY4ClY4bbcBxa/sRBPq+HaIwWB269QotEOYnYnwSZ0jI8rLLZvy8SE7swxc2 CVDlHiWr3sEnfW/pNR3ouBE3G520mPO+N7af2iSCsqG9STLO++Ke8OQu/mifQWH3LRro FhUrSvfeVZuifgIGNzRbfBO06+FHkBWg6OZKN2ncjazckmq27VnBHE5kFvdm9Ud4svvZ GZfO+ILMLdZ9BgPHmg4gx+QPfHBia87fRXb4aTw4e0TkCHYrmSJ2pxVDD2niv5iKP18c ew3zdhc5j5IJ8nSGayniLB8mqwJEIovd3nwuHWf92UiomLFXoG3E5kmhZQwhkt9dTac2 f9uw== X-Forwarded-Encrypted: i=1; AHgh+RpiOD+rjfTn2V/pKCQNtIrRd3cnUlvUZx3aRFDBsHTd17Wx+3d+e2KXgiK9EoDs4hjETsd00Zyi1uTml7Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yxtvch///rsGIVuFjfjxA5Js25h5omgrQoG61IaHRq6gKsbldJv HX3JTUjze7HYxch56ItEweoMwDiErCP8esslBDsNrgGqbuTKjo1MN5qd X-Gm-Gg: AfdE7cl8F4HjndQmFU6y9Gc0pLkGevu8hKUCHa+vtp5JXYJLUHnhmoFtRYdoHIuDYzg Wx0JQwdChzW/H/1ZfcpqiCXmBUdRGnkpL89Mr+mdF3USmzN09/aoWraFNI7uzu5oYI1UQ+o/eXm j+NmFrtadSYeAwZnFajgz/fP/yA3pGRcWJ8UA8Riu3iQwJfpW1wwJKIBo853hbw2UvCZuSdyF0s +r/G88f1ER6KeUWK85MLGyiicdcds6abVpIH1R6YgMJTIAOxoa+Hzuh8yOhi09QAJeMh/rQ0imx pBItLfgCcoAfCK80rUzjUElK1PvwKZSdIe5IeTLqtkRjsDRXd8mZtDYbv6SRfi2ROp/BCgNLKOM 7eWHte2NiUBetSthismC3U8qKnqEPZZgcVhN/Bb6Qno5+XE7eYZzOsIdKlvmfJyrKsH2ltWcCi/ H+hEMZPSKGnvrcHmeQ6sVoR7qqbC8Fenr3PPL3kJoC91ycPhmyIV/tF5BcmdjThcFVhiYVoQi3z 7MD X-Received: by 2002:a05:6402:241f:b0:697:d4ee:ab97 with SMTP id 4fb4d7f45d1cf-69e652726d6mr1158331a12.12.1784299445870; Fri, 17 Jul 2026 07:44:05 -0700 (PDT) Received: from misharu.home (2a02-a463-a071-0-5347-776a-5ef9-a909.fixed6.kpn.net. [2a02:a463:a071:0:5347:776a:5ef9:a909]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-69e6fef2477sm829324a12.7.2026.07.17.07.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 07:44:05 -0700 (PDT) From: Hari Mishal To: Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Hari Mishal Subject: [PATCH] nvmet: passthru: fix OOB reads when parsing ns id descriptor list Date: Fri, 17 Jul 2026 16:43:53 +0200 Message-ID: <20260717144353.19436-1-harimishal1@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" nvmet_passthru_override_id_descs() walks a namespace identification descriptor list populated from the underlying passthru controller's Identify response, which is device reported. The loop advanced pos by device controlled amounts (sizeof(*cur) + nidl) without checking that the next descriptor header actually fits inside the buffer, so a malicious device could push pos to within a few bytes of the buffer end and cause cur->nidl, cur->nidt or the reserved field to be read past the allocation. Additionally, when a CSI descriptor lands exactly at the last valid header offset, cur + 1 points one byte past the end of the buffer. The unconditional memcpy(&csi, cur + 1, NVME_NIDT_CSI_LEN) could read that out-of-bounds byte and copy it back to the initiator via nvmet_copy_to_sgl(), leaking adjacent heap memory. Bounds check both the descriptor header and the CSI value before dereferencing them. Signed-off-by: Hari Mishal --- drivers/nvme/target/passthru.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index e27f84e3cf2b..7ef02958078b 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -53,13 +53,21 @@ static u16 nvmet_passthru_override_id_descs(struct nvme= t_req *req) for (pos =3D 0; pos < NVME_IDENTIFY_DATA_SIZE; pos +=3D len) { struct nvme_ns_id_desc *cur =3D data + pos; =20 + if (pos + sizeof(*cur) > NVME_IDENTIFY_DATA_SIZE) + break; + if (cur->nidl =3D=3D 0) break; + if (cur->nidt =3D=3D NVME_NIDT_CSI) { + if (pos + sizeof(*cur) + NVME_NIDT_CSI_LEN > NVME_IDENTIFY_DATA_SIZE) + break; + memcpy(&csi, cur + 1, NVME_NIDT_CSI_LEN); csi_seen =3D true; break; } + len =3D sizeof(struct nvme_ns_id_desc) + cur->nidl; } =20 --=20 2.43.0