From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F3DBC43457 for ; Sun, 18 Oct 2020 19:35:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27BD2207DE for ; Sun, 18 Oct 2020 19:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603049737; bh=wwcSHnEGzPMRuAF0NbOb9fwXJ3eDhP46kueuiqZkXOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=lcFhp2Ho4hgcTCxQw/lHNunsdPyzVcITvrRKHybB8Qy3fCk/WS3Rqkyl6OBAmXJqq K9Fadv/kFqt/LVvj4gVW/IDkL0Hv6PaiIQKUo9GXu4Uflu8A/5kqe5ZwWAj4baaUj8 GNNeGUBWzMMp5DRs71kHsbT+7huq9UK8KZpI2vmo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733033AbgJRTfg (ORCPT ); Sun, 18 Oct 2020 15:35:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:40880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731463AbgJRTZ5 (ORCPT ); Sun, 18 Oct 2020 15:25:57 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8161620791; Sun, 18 Oct 2020 19:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603049156; bh=wwcSHnEGzPMRuAF0NbOb9fwXJ3eDhP46kueuiqZkXOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1yxk3hhTwSAf2wxiZKns22Yuu0N06msaV1NbR4TfXfsH6RuZB68Gn97qzpEOT/woS G4un1Wq2Th2uBKgOeksX0fcqgWSjCTAztNg2Z1S0PTUz23diioViBQm+Ql6sHNvVGd QsWIpS84k66RK+DHL66J8UfSgEgdBkgZ/f8lTYZ0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rustam Kovhaev , syzbot+aed06913f36eff9b544e@syzkaller.appspotmail.com, Andrew Morton , Anton Altaparmakov , Linus Torvalds , Sasha Levin , linux-ntfs-dev@lists.sourceforge.net Subject: [PATCH AUTOSEL 4.14 21/52] ntfs: add check for mft record size in superblock Date: Sun, 18 Oct 2020 15:24:58 -0400 Message-Id: <20201018192530.4055730-21-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201018192530.4055730-1-sashal@kernel.org> References: <20201018192530.4055730-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rustam Kovhaev [ Upstream commit 4f8c94022f0bc3babd0a124c0a7dcdd7547bd94e ] Number of bytes allocated for mft record should be equal to the mft record size stored in ntfs superblock as reported by syzbot, userspace might trigger out-of-bounds read by dereferencing ctx->attr in ntfs_attr_find() Reported-by: syzbot+aed06913f36eff9b544e@syzkaller.appspotmail.com Signed-off-by: Rustam Kovhaev Signed-off-by: Andrew Morton Tested-by: syzbot+aed06913f36eff9b544e@syzkaller.appspotmail.com Acked-by: Anton Altaparmakov Link: https://syzkaller.appspot.com/bug?extid=aed06913f36eff9b544e Link: https://lkml.kernel.org/r/20200824022804.226242-1-rkovhaev@gmail.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/ntfs/inode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 7c410f8794124..2aa073b82d30f 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -1844,6 +1844,12 @@ int ntfs_read_inode_mount(struct inode *vi) brelse(bh); } + if (le32_to_cpu(m->bytes_allocated) != vol->mft_record_size) { + ntfs_error(sb, "Incorrect mft record size %u in superblock, should be %u.", + le32_to_cpu(m->bytes_allocated), vol->mft_record_size); + goto err_out; + } + /* Apply the mst fixups. */ if (post_read_mst_fixup((NTFS_RECORD*)m, vol->mft_record_size)) { /* FIXME: Try to use the $MFTMirr now. */ -- 2.25.1