Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2422090rdh; Sun, 29 Oct 2023 15:55:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLwnlRgoijUR7aXPMgxFXcnikQLVe3k/yr/oNT3Mu2vT+UNjruaw6qsQ1J0jTSHVNgmBpI X-Received: by 2002:a17:902:c412:b0:1c9:e77d:62d3 with SMTP id k18-20020a170902c41200b001c9e77d62d3mr12485827plk.10.1698620110575; Sun, 29 Oct 2023 15:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698620110; cv=none; d=google.com; s=arc-20160816; b=iHLkc/AGz/WPPB0cFDWIZM8CONpz88WKmKKWN8BR1lnbFxrTHdgB407RpBakZnMKJA tIF1X3+v7lRb2vIP9W+0PZJIJyWyi2Uf6/UhbtoQwB6NY87vK2vMrErEWxOI5tEeanxc MAmPCJtFCwxf6iAuQIfXlU2yEFoghFYyHt+LWxFaxhezZRIjRuKh2rwWrlH7cBd93F9M H1D8zpFOnwM2EsMrZMB0LOh+s1BQA4ob2te4mh6Cz1MTqQrxWef+6nOkT/Qcu44myGaS nmeVM9lHkeB7pu6VVQzAXPUTo3RLI8g0HXE98WlvwZptXaQQZBkOG6k3LjuK9L7OPosb tyog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YcpDc864XIaKTbb4pZ6HrQlms8S+anV9ZX1zVgYxSz8=; fh=NVj5khkaa4wJVWbYO1F9lxVBoc0LL85Zex+GtUcizcw=; b=GxhO4g4aCtH1NM+wMAzv4Zfc+sT/t+V4e5kpJ5Ud1R6p+82zymlUIfZw1A4iqbK9N2 Qs11HXgQsiR93Xo+8NgbAP6AdiuOYXSlvbobXlmLN635nrMBfaXsZ31kxIrmjSU6ZfJ6 h2uenNj6hYuCF91Szi1LVACZXqz/iGii9h8UNcqpuBhuIiBqbgTIqE2TxFMsaQ8GyCPa 8+xn1Dt6FQ2hH3G/w3dtbL5CMaw3+sGGJJYS78T/D3FK2xPpPahzhFvuW8ub6FfRl0+y j/a0/gJhzn6GXhW/1d19NDjQq93AOJ9EL6GVqdZZl9hRFlv6Uw3shxNVqM63GWtEL6T0 GfZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrdRMUn0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f3-20020a170902f38300b001c8944c933dsi4060861ple.380.2023.10.29.15.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 15:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrdRMUn0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A006780A7E5F; Sun, 29 Oct 2023 15:55:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231163AbjJ2WzE (ORCPT + 99 others); Sun, 29 Oct 2023 18:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbjJ2Wy6 (ORCPT ); Sun, 29 Oct 2023 18:54:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D49F4DB; Sun, 29 Oct 2023 15:54:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94C36C433CB; Sun, 29 Oct 2023 22:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698620095; bh=XpEB7QllHM+SGHwR2XRaJkTltVnlwDvLC5E/fzWUslg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KrdRMUn0NeTfdvoTXO0y0T5V5mVDNy46JXiTJcN9/U4Fqzgbf+IutxujJCulcydFq C+ifKmx0lIFbgPpk7BBp88BUkuRFlv6+BUi/bnRvcO6dQFw2PQ5548a3Vata/ShCVX vgt0lzLGSi4atizGlC5G1H6FcXEk0Hb5cn2VKWHcsS8e4gXncBWE+MmA3hVqdwPudU uUrcuUVEZ2sx4CNV89GeMJinAX/XHDeSFDM4+a51ySQxKXEuFPUgjMiCyVyzqLWInH rFJmjgKMEG+w64nA+A7oUFmkIMvHXV3PA6miVd30m69jlmCCda2ul/BaFCtmwiGoxl KoSllFruRo3KQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konstantin Komarov , syzbot+478c1bf0e6bf4a8f3a04@syzkaller.appspotmail.com, Sasha Levin , ntfs3@lists.linux.dev Subject: [PATCH AUTOSEL 6.5 07/52] fs/ntfs3: Fix shift-out-of-bounds in ntfs_fill_super Date: Sun, 29 Oct 2023 18:52:54 -0400 Message-ID: <20231029225441.789781-7-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231029225441.789781-1-sashal@kernel.org> References: <20231029225441.789781-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.9 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 29 Oct 2023 15:55:09 -0700 (PDT) From: Konstantin Komarov [ Upstream commit 91a4b1ee78cb100b19b70f077c247f211110348f ] Reported-by: syzbot+478c1bf0e6bf4a8f3a04@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov Signed-off-by: Sasha Levin --- fs/ntfs3/ntfs_fs.h | 2 ++ fs/ntfs3/super.c | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 629403ede6e5f..788567d71d939 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -42,9 +42,11 @@ enum utf16_endian; #define MINUS_ONE_T ((size_t)(-1)) /* Biggest MFT / smallest cluster */ #define MAXIMUM_BYTES_PER_MFT 4096 +#define MAXIMUM_SHIFT_BYTES_PER_MFT 12 #define NTFS_BLOCKS_PER_MFT_RECORD (MAXIMUM_BYTES_PER_MFT / 512) #define MAXIMUM_BYTES_PER_INDEX 4096 +#define MAXIMUM_SHIFT_BYTES_PER_INDEX 12 #define NTFS_BLOCKS_PER_INODE (MAXIMUM_BYTES_PER_INDEX / 512) /* NTFS specific error code when fixup failed. */ diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index d3c78e2a49cbe..18a8bc73b8e2d 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -901,9 +901,17 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, goto out; } - sbi->record_size = record_size = - boot->record_size < 0 ? 1 << (-boot->record_size) : - (u32)boot->record_size << cluster_bits; + if (boot->record_size >= 0) { + record_size = (u32)boot->record_size << cluster_bits; + } else if (-boot->record_size <= MAXIMUM_SHIFT_BYTES_PER_MFT) { + record_size = 1u << (-boot->record_size); + } else { + ntfs_err(sb, "%s: invalid record size %d.", hint, + boot->record_size); + goto out; + } + + sbi->record_size = record_size; sbi->record_bits = blksize_bits(record_size); sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes @@ -920,9 +928,15 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, goto out; } - sbi->index_size = boot->index_size < 0 ? - 1u << (-boot->index_size) : - (u32)boot->index_size << cluster_bits; + if (boot->index_size >= 0) { + sbi->index_size = (u32)boot->index_size << cluster_bits; + } else if (-boot->index_size <= MAXIMUM_SHIFT_BYTES_PER_INDEX) { + sbi->index_size = 1u << (-boot->index_size); + } else { + ntfs_err(sb, "%s: invalid index size %d.", hint, + boot->index_size); + goto out; + } /* Check index record size. */ if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { -- 2.42.0