Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A0FF17F36A for ; Wed, 10 Apr 2024 18:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712775463; cv=none; b=K3Gdak2MjGXgEvAfQpPb395rFsGxdwgXpFINryPAf4w0YvQK94QEJXtZhbwryoJf1URDER8v/1wLvcOqASjH3mFUpDj+vHZlT6kiL1tl+dV0CGIfP1M0Z41NojVz97ruqC1ADkOn7JPJZ8J5QcuZRF3+SDIvBNal42KKuiSL6qI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712775463; c=relaxed/simple; bh=gSu/8q55ioBM4G7a2YOvWM8dwIe3lTT8sOvtF46A1Xc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=f+HkisKkVH44SpyRSNqnK8cahM2peSQXuddHEO7/Ua0aezznzPsi2FGTpZsu099WzA8BYHjd7vZuSSmBYtQHxWyOIyJ0NJIs3yBUpKw5NRm+yQok62vJU2N1LDX892nDTuAlBMXOecM1s3hCaFhJ3hKSkTWBguk/ESyFvwskgKg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dU6dWCBE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dU6dWCBE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 714A0C433F1; Wed, 10 Apr 2024 18:57:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712775462; bh=gSu/8q55ioBM4G7a2YOvWM8dwIe3lTT8sOvtF46A1Xc=; h=From:To:Cc:Subject:Date:Reply-to:From; b=dU6dWCBExgT3H7dqDc/T9sE4oYpSCgaF38KJgvcMzYq51N9ygohtnQUYExix0KzLE sNmOc+FdnfSEd0qoIzQlbVGCkkGyMjdYIzETkSw1oRM9Ef22PCAt0Bn2zk/aMoWqNj HPUR+P3nG2UruyIyGVoynGSIM6asepOLg2u4YPB8= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2021-47182: scsi: core: Fix scsi_mode_sense() buffer length handling Date: Wed, 10 Apr 2024 20:57:31 +0200 Message-ID: <2024041032-CVE-2021-47182-377e@gregkh> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3186; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=gSu/8q55ioBM4G7a2YOvWM8dwIe3lTT8sOvtF46A1Xc=; b=owGbwMvMwCRo6H6F97bub03G02pJDGliD2XmiL2+kC/G1m/N+od145dbTKc49f+JcWt4KH5W9 L3st29iRwwLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzkQifD9OIQTulb7DkZd98r L30stc3VtT+VYcGVK5ds77a/PFW39Zq2WmnoL+nYKHMA X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: scsi: core: Fix scsi_mode_sense() buffer length handling Several problems exist with scsi_mode_sense() buffer length handling: 1) The allocation length field of the MODE SENSE(10) command is 16-bits, occupying bytes 7 and 8 of the CDB. With this command, access to mode pages larger than 255 bytes is thus possible. However, the CDB allocation length field is set by assigning len to byte 8 only, thus truncating buffer length larger than 255. 2) If scsi_mode_sense() is called with len smaller than 8 with sdev->use_10_for_ms set, or smaller than 4 otherwise, the buffer length is increased to 8 and 4 respectively, and the buffer is zero filled with these increased values, thus corrupting the memory following the buffer. Fix these 2 problems by using put_unaligned_be16() to set the allocation length field of MODE SENSE(10) CDB and by returning an error when len is too small. Furthermore, if len is larger than 255B, always try MODE SENSE(10) first, even if the device driver did not set sdev->use_10_for_ms. In case of invalid opcode error for MODE SENSE(10), access to mode pages larger than 255 bytes are not retried using MODE SENSE(6). To avoid buffer length overflows for the MODE_SENSE(10) case, check that len is smaller than 65535 bytes. While at it, also fix the folowing: * Use get_unaligned_be16() to retrieve the mode data length and block descriptor length fields of the mode sense reply header instead of using an open coded calculation. * Fix the kdoc dbd argument explanation: the DBD bit stands for Disable Block Descriptor, which is the opposite of what the dbd argument description was. The Linux kernel CVE team has assigned CVE-2021-47182 to this issue. Affected and fixed versions =========================== Fixed in 5.15.5 with commit e15de347faf4 Fixed in 5.16 with commit 17b49bcbf835 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2021-47182 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: drivers/scsi/scsi_lib.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/e15de347faf4a9f494cbd4e9a623d343dc1b5851 https://git.kernel.org/stable/c/17b49bcbf8351d3dbe57204468ac34f033ed60bc