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 B0721180A76 for ; Wed, 10 Apr 2024 18:58:45 +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=1712775525; cv=none; b=mQO5mJhWEJKZSu9NbgS6f9A681iSu9DL/1W+vG39fp27mVMwT31sYp2FL4TT+xg3n5DukraEcWW1AK0TrJ8LS3rXdybpLQU3lEaEHMUBepQn9WkrUZnkGrMLOqjxFnKXp+zR2sktMGG8Tyv6nbt+DqF2D20D4GcaFimMWauBSrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712775525; c=relaxed/simple; bh=7kRttD7ugJrANpnK6wh2jnQdsU82vHerSeh9O5fGidQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fk4Y1cyIjkPqG9MKO4nss4ed8ba9ZYdiF1maUedwYOeu0W4uvfkbW613EpKwbLENRLolRMUyZ5jsEsxeliDJPOpXJf8QO5xGXZQ1PBadEEDf9o9RElaqXDpAIhI+JZc0r1RGugEN9h7tv3BND4TECu7vtorzkSsV4Rz+fxK+59U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Qjjp2X4o; 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="Qjjp2X4o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A961C433C7; Wed, 10 Apr 2024 18:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712775525; bh=7kRttD7ugJrANpnK6wh2jnQdsU82vHerSeh9O5fGidQ=; h=From:To:Cc:Subject:Date:Reply-to:From; b=Qjjp2X4o7g9JPqfXqrOPxmu2w/BWM/tNE3vNGLMX7s25kQ428ghtZnPXyEwAKvJQF /ohN5LMA5Z6UuzWWAv4DlJtAn0bKq7/rstQmNb/zgOLp8nw3cyv5cytPoH+XI8cVyB cyUaNRNWwIxbxiQ1dCbccpVZX1KuybcJdvYYs0Bk= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2021-47191: scsi: scsi_debug: Fix out-of-bound read in resp_readcap16() Date: Wed, 10 Apr 2024 20:57:40 +0200 Message-ID: <2024041034-CVE-2021-47191-ec4f@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=4059; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=7kRttD7ugJrANpnK6wh2jnQdsU82vHerSeh9O5fGidQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDGliD+UPTm7kF1rieWZn6dcrHbN3L/VKLG58+S3RPc71H 2PepcN7O2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAix68xzDPbvjCOgeHR4Vfs 74xVtDSZBcOffmGYn/HPZNbdCp28SwLf1Nf6bVtZxZMwEQA= 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: scsi_debug: Fix out-of-bound read in resp_readcap16() The following warning was observed running syzkaller: [ 3813.830724] sg_write: data in/out 65466/242 bytes for SCSI command 0x9e-- guessing data in; [ 3813.830724] program syz-executor not setting count and/or reply_len properly [ 3813.836956] ================================================================== [ 3813.839465] BUG: KASAN: stack-out-of-bounds in sg_copy_buffer+0x157/0x1e0 [ 3813.841773] Read of size 4096 at addr ffff8883cf80f540 by task syz-executor/1549 [ 3813.846612] Call Trace: [ 3813.846995] dump_stack+0x108/0x15f [ 3813.847524] print_address_description+0xa5/0x372 [ 3813.848243] kasan_report.cold+0x236/0x2a8 [ 3813.849439] check_memory_region+0x240/0x270 [ 3813.850094] memcpy+0x30/0x80 [ 3813.850553] sg_copy_buffer+0x157/0x1e0 [ 3813.853032] sg_copy_from_buffer+0x13/0x20 [ 3813.853660] fill_from_dev_buffer+0x135/0x370 [ 3813.854329] resp_readcap16+0x1ac/0x280 [ 3813.856917] schedule_resp+0x41f/0x1630 [ 3813.858203] scsi_debug_queuecommand+0xb32/0x17e0 [ 3813.862699] scsi_dispatch_cmd+0x330/0x950 [ 3813.863329] scsi_request_fn+0xd8e/0x1710 [ 3813.863946] __blk_run_queue+0x10b/0x230 [ 3813.864544] blk_execute_rq_nowait+0x1d8/0x400 [ 3813.865220] sg_common_write.isra.0+0xe61/0x2420 [ 3813.871637] sg_write+0x6c8/0xef0 [ 3813.878853] __vfs_write+0xe4/0x800 [ 3813.883487] vfs_write+0x17b/0x530 [ 3813.884008] ksys_write+0x103/0x270 [ 3813.886268] __x64_sys_write+0x77/0xc0 [ 3813.886841] do_syscall_64+0x106/0x360 [ 3813.887415] entry_SYSCALL_64_after_hwframe+0x44/0xa9 This issue can be reproduced with the following syzkaller log: r0 = openat(0xffffffffffffff9c, &(0x7f0000000040)='./file0\x00', 0x26e1, 0x0) r1 = syz_open_procfs(0xffffffffffffffff, &(0x7f0000000000)='fd/3\x00') open_by_handle_at(r1, &(0x7f00000003c0)=ANY=[@ANYRESHEX], 0x602000) r2 = syz_open_dev$sg(&(0x7f0000000000), 0x0, 0x40782) write$binfmt_aout(r2, &(0x7f0000000340)=ANY=[@ANYBLOB="00000000deff000000000000000000000000000000000000000000000000000047f007af9e107a41ec395f1bded7be24277a1501ff6196a83366f4e6362bc0ff2b247f68a972989b094b2da4fb3607fcf611a22dd04310d28c75039d"], 0x126) In resp_readcap16() we get "int alloc_len" value -1104926854, and then pass the huge arr_len to fill_from_dev_buffer(), but arr is only 32 bytes. This leads to OOB in sg_copy_buffer(). To solve this issue, define alloc_len as u32. The Linux kernel CVE team has assigned CVE-2021-47191 to this issue. Affected and fixed versions =========================== Fixed in 5.10.82 with commit 3e20cb072679 Fixed in 5.15.5 with commit 5b8bed6464ad Fixed in 5.16 with commit 4e3ace0051e7 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-47191 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_debug.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/3e20cb072679bdb47747ccc8bee3233a4cf0765a https://git.kernel.org/stable/c/5b8bed6464ad6653586e30df046185fd816ad999 https://git.kernel.org/stable/c/4e3ace0051e7e504b55d239daab8789dd89b863c