From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388345; b=zNbdZojNJk6nFYKSFPbsVDIlU31/VGnp4kWzkyU2WvPpviSyTyiUqOjGQ/jZthZAOCwu BZMMqGW/ozwQInFBxmRW8j8pf3ARc4L0s1+muUN4SbBGpNHDDg3eHVjceGEAM9DmYCdPr EknJHIqy4l8QJOTxHc2ZH2AT8KwmMJxxGhRWjcCxJEe/1CFkzvThiodX8SJtZmD8x8Kp4 OBbf9+Gv1rjGfKcvfyxrG2+IRanjaGIN1bQZe9TDO7VmHb5qbAow4BfeNbZEoxcwygSIO Y5FtZ76Z5SU5WMPiVMO0F+AQdwKRP8nAWaphODo7A1+Zt5+M1AiBWy9cqqry4fh22iQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388345; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=XMMMqVrs+b3jX8GLdiHjJlJeGXY6g66LrC85R+p1yyM=; b=UeIx56BUdv0BMjshmzDgDWG22R95Mg5gT2ABPwZm9HluBdv9D0pqveUptZp6QfYyyrlk uwdIbZa/jpxJ4AhoiXnW51kydf6+mZQkIDAggcyw1I6AvrPczW0wtf+CX5L6MaHtUojcq H9cgbfrtw9DeaD0Bzw7TNX5thLKkMEykCCGraPFr6KZm3qKg8L5j5awp8CSTGl2XZV6Ya at6C1VHDCPWST2DNfuxoB55Mz+O5qha8W9tN87hVSIKlu+ntFR1FcceW8nGWDYIcGMPFJ OLTyOTZKafZ94O+PG7Pk5tFhWNO/+ihj/LEkYAQKZPURccgkcD0XvmmKZG9v1Z6JhHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=su512QVj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6791B606A33A; Fri, 4 Dec 2026 12:45:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=su512QVj Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADF6D1F00939; Fri, 4 Dec 2026 12:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388345; bh=XMMMqVrs+b3jX8GLdiHjJlJeGXY6g66LrC85R+p1yyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=su512QVjr6VWKtooniIoT1KQCF9vLlD4aKTavecHYLi4JzQwelHvIGDplc3Au7ZfV uu8CHpum3h/vk1tTe0USQsL2i0QgeiuNJnNLaQnmIx9vylFScHCFZ9AuagB1Tc4be6 RfIa5x3C5iZqMevXdSIblIFBdvy5/GxY509+0NRs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jay Vadayath , Mikulas Patocka Subject: [PATCH 6.1 0576/1059] dm-raid: bound array_position before indexing failed_devices Date: Fri, 4 Dec 2026 19:01:47 +0900 Message-ID: <20261204100659.086117072@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jay Vadayath commit 11b5cd14c0eecae458cecbe53d21a3dbc10190f5 upstream. super_init_validation() reads role = le32_to_cpu(sb2->array_position) out of an on-disk dm_raid_superblock and then uses it as a bit index into the failed_devices bitmap via test_bit(role, (void *)failed_devices). failed_devices is a uint64_t[DISKS_ARRAY_ELEMS] (DISKS_ARRAY_ELEMS == 4, i.e. 256 bits) living on the stack. The only guard is role < 0, so any on-disk array_position >= 256 makes test_bit() read past the end of the stack array (array_position == 256 reads failed_devices[4], 8 bytes past the object). For a raid1 set the role != raid_disk reorder branch falls through to the same test_bit(). A crafted dm-raid superblock therefore causes a stack out-of-bounds read during table load. Reachable by anyone able to issue a dmsetup create with attacker-controlled metadata (CAP_SYS_ADMIN in the target namespace); the crash fires in the constructor / analyse_superblocks path, before any md_run or array sizing. BUG: KASAN: stack-out-of-bounds in super_validate+0x1cd0/0x3390 Read of size 8 at addr ffff888007b17828 by task poc/152 Call Trace: dump_stack_lvl+0x64/0x80 print_report+0xd0/0x630 kasan_report+0xe5/0x120 kasan_check_range+0x105/0x1b0 super_validate+0x1cd0/0x3390 (super_init_validation, inlined) raid_ctr+0x2c4b/0xa0f0 dm_table_add_target+0x66f/0xf80 table_load+0x2ee/0x780 ctl_ioctl+0x362/0x9f0 dm_ctl_ioctl+0x9/0x10 __x64_sys_ioctl+0x134/0x1c0 do_syscall_64+0xe2/0x4b0 entry_SYSCALL_64_after_hwframe+0x77/0x7f role is a device position that must refer to an actual member of the array, so reject anything outside [0, rs->raid_disks) instead of only the negative case. rs->raid_disks is always <= the 256-bit capacity of failed_devices, so this both closes the out-of-bounds access and matches the intended semantics. This bug was discovered by Artiphishell's vTriage pipeline, which generated a crafted raid1 superblock (magic "DmRd", compat_features=1, num_devices=2, array_position=256, level=1) and a dmsetup-create reproducer that reliably triggers the KASAN report on an unpatched kernel (the precursor DMINFO "raid device #256 now at position #0" is visible in the serial log just before the splat). The fix below was drafted with the Claude coding assistant; a userspace reproducer is available on request. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Jay Vadayath Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-raid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/md/dm-raid.c +++ b/drivers/md/dm-raid.c @@ -2395,7 +2395,8 @@ static int super_init_validation(struct */ if (!test_bit(FirstUse, &r->flags) && (r->raid_disk >= 0)) { role = le32_to_cpu(sb2->array_position); - if (role < 0) + /* Bound @role before it indexes the failed_devices stack bitmap. */ + if (role < 0 || role >= rs->raid_disks) continue; if (role != r->raid_disk) {