From nobody Mon Jun 8 08:28:18 2026 Received: from mail-qv1-f41.google.com (mail-qv1-f41.google.com [209.85.219.41]) (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 CFF8844D021 for ; Wed, 3 Jun 2026 17:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780506672; cv=none; b=S8mqqzrn7zsqgyZVUGlaiYE07rkL/1+QzLMqeyMTcxbqM5pej88rUQ+MXpo+LhFynkGKEBp/mRxNavKKZeJeoTowgb0OqX5uqLci2i7uVLidXaWh6HPXgj1kWfkw88tRrlIScNLke/hbrtVb8I2o3Bskzff+4DNpwraietsYfWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780506672; c=relaxed/simple; bh=gggVixvNIe8eojfgqAyRfMfpRR02zkhLBeCRqDiKDcs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jdDhKhpMPf9Y22SpawGVSKSzVrVdsBDdM7Xy4g2DMGv950lKjc2mDisiRIZATG915NZ46REZHKbrCMhrSrDWxvNOOdpAC9hHVu+W+HI3RGBmW7e1Nn99SLfEWk0MJz57eiTDn9VjtLjNcZY4p5h9n83N+4G+fY+/WGyFtCvrQZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=YPjnIqLG; arc=none smtp.client-ip=209.85.219.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="YPjnIqLG" Received: by mail-qv1-f41.google.com with SMTP id 6a1803df08f44-8ccea53f35cso64174696d6.1 for ; Wed, 03 Jun 2026 10:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1780506670; x=1781111470; 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; bh=Tt2E3V9JRbSP5TlXePw68cT+MzmoIbGHI39TQOv7QTs=; b=YPjnIqLGm1a1+7+5YruqmqcmrM/Akq0iVFMWmGpRxMy2edj6UQ9sVF2AYTEM8oHO54 osilFLdDSNVYSLBgSpxLQ9nuVtgGIMlGLdcXB2u81yMFUvljwVU/mfg73x3aVsXllTrZ FfPg5FdIpbb6aMiSnR12Y/XDE1X972DmsMgoqRZELbRqyocbdWpEyWYQMLtawXuBZL40 NRxYSI4ezZnm8mZWxfAymmN4BVpxe3+Nxo8sX2c0RGxYfuhibHuzDVTtq5ytbgK+bf21 QIF+ciPAskzEaSA2YJ4HpD8tUp+zjlFwLGPk/j4TEZmTCOBcA2qFS8LlfsEnSCPxy5yq ZrfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780506670; x=1781111470; 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; bh=Tt2E3V9JRbSP5TlXePw68cT+MzmoIbGHI39TQOv7QTs=; b=nMhmJQupv4uRCtw4KAkIlnLLr4sF3YYWMiXgL3rnKcsfWr9QXUUGNiJMeyLxKt4EVY RVszu0JNgnVzrBFduryJk6gFlxC3dFZu43VrEFWxj4l/KdT8eYIP8J5n+Pva/eRTIr/X AIsET3jvfJcB4TPi9jO3g7w2GfSHMtlouahFT4BQnf4NnGZAA+FdcnuKIncLyWPfnKPR YVAhQl7aD7uNx5fszEDQ/t77D6xYpte7sn7JHVBU4DG5BXiX8kvpuxdGq5/fz3HwS5OR avMVU41ZSS3DY+vrKaFF/5isH6bES/mT2V7K2YpKOCfFZAof1+kqvaw1gZaZOcdkYeTF bveA== X-Forwarded-Encrypted: i=1; AFNElJ8o3HEL6ocKKfs2Jj2xgVKz6xY3aW0EWT9F+KIRrnQIDPDhnC4CV8sNcipKDX+tO5OB5q5LVoOLo9pvS+w=@vger.kernel.org X-Gm-Message-State: AOJu0YzzjmL5OWgZhwREIWD+y5ZuzdXT4uEuLkxE5hUlBdyhkQQEK3zq gukzGTN128v7L394tYAD20UXLMnkvNZuW//Dcn1bygWrpOlOhwxK0HTWEghPtWchLCQ= X-Gm-Gg: Acq92OFyCOwGOB2e0IQAyzTsWJ2SXt5gHa6SefOREytqEyYiSc8CtHQzSF3En7HxxBB DF+aBHM2wLtD8NCBRnWeIXWxd9fvn/gQoPxbJrn+08Q1s5xBc+NOsUXPh0tkWYrB1MckeL2wtKC 7gJNZr7jaqrFBr1tOcjlxOa1gtIT+W2ntpLRqD80hz2bc/tz3uG2jlNT/HaZ52nPXXVszEkwF2R ehNv+qQbxBUPEc/Z5TtEPBz905qzgWZ8JaEOxZlxGl1fQhn3diahuEFWeF5q3iyasLjRpPLUhtL 1YTFLl7OR5maZymIfYMBdtv4MIanSOaw6/ri5DvbYswzC9BdnuZrlidXS0rXrZc2RYOJArEljMT 9kqjRnvPGqPyi07vkN9Kj5K9p6hs7vgb1JM/KnQaHllUk3Fc26AtkeNiqELloQflWLrnifWQpwh FaMsljx4VYt7qS50RwdTBrTJwVTNWFgVCeujLlGw== X-Received: by 2002:ad4:5ae7:0:b0:8ce:a9be:bc65 with SMTP id 6a1803df08f44-8cecdd20168mr62523276d6.41.1780506669831; Wed, 03 Jun 2026 10:11:09 -0700 (PDT) Received: from localhost ([161.35.96.86]) by smtp.gmail.com with UTF8SMTPSA id 6a1803df08f44-8ceccdb93d8sm26240696d6.16.2026.06.03.10.11.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jun 2026 10:11:09 -0700 (PDT) From: Samuel Moelius To: "James E.J. Bottomley" Cc: Samuel Moelius , "Martin K. Petersen" , linux-scsi@vger.kernel.org (open list:SCSI SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] scsi: scsi_debug: reject too-small REPORT ZONES buffers Date: Wed, 3 Jun 2026 17:11:04 +0000 Message-ID: <20260603171104.18464-1-sam.moelius@trailofbits.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" REPORT ZONES subtracts the response header size from the allocation length before ensuring that the allocation is large enough. A short allocation can underflow and make the remaining length look huge. The handler can then write zone descriptors past the caller-provided response buffer. Validate the allocation length before subtracting the header size. Assisted-by: Codex:gpt-5.5-cyber-preview Signed-off-by: Samuel Moelius --- drivers/scsi/scsi_debug.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 1515495fd9ea..f17e59482cfc 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -5911,6 +5911,10 @@ static int resp_report_zones(struct scsi_cmnd *scp, alloc_len =3D get_unaligned_be32(cmd + 10); if (alloc_len =3D=3D 0) return 0; /* not an error */ + if (alloc_len < RZONES_DESC_HD) { + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); + return check_condition_result; + } rep_opts =3D cmd[14] & 0x3f; partial =3D cmd[14] & 0x80; =20 --=20 2.43.0