Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1129960pxx; Tue, 27 Oct 2020 08:57:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY8unoOxtcPpsSr+eRD1GC3tXeaJL/+I5GD22XrYOgOHikGOyygXX22gnraK61hXgAPiIa X-Received: by 2002:a17:906:5488:: with SMTP id r8mr2952454ejo.483.1603814237697; Tue, 27 Oct 2020 08:57:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603814237; cv=none; d=google.com; s=arc-20160816; b=Ay7/mRn8vIiYQLSwGXy/toWq016mscI2VVkHXzlmnUsUNUx67WiMwM2kIshyozxYRK E8KeJywBBO566Oa3x5QV8o4cjL++O3n1HtpXue1ZKPcY1m70SOc7F4E8OMr7YzjysAfJ 5OqO63BMzbG3fIOj0rwKY20nwGoKOEm3856jsl4fQ9ipfcng8WAHToAkpnBJnJZsOROr l008N5jmdXOYX+hjDiAx98dUyzAcpnmJOG/geRlwcQf9ehpJzNdGDxwLkdWtoroLVLpm CPChm7nt5q73LRhFbxvYq/xljASYV8/U61NSGnJMQD6mnDMbVVQ6P/2dNBdsbdu7eped y0vg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MdYpqr2TPu5XfT+YCg4kvE0wZrzHlQCykOnpBmAMwhw=; b=sOgPK3zfatV1s5aN+8ChrLhMHU6H2zkY0eYGEIUcdVg9qr2/KzEgzdMI9i8CAGcRLR 6Nc4292FuGGbWf415lxz3DvfEmm7sm7JNDbD/de5ZA3XRiBLYF5B0T+VCVOqxfCih84c ka3Z+Ox+pL7DRblGpwbPsVfZmae0pNE6fGC1lTbFEWcLjqUDPrK8FNnij7+IaoRgX8Gd pH21Os+9A3K+FJ6U8Qn+WhnfqJWiqAlgh+HbVQ4ckC1cedCR3VDtmzvZ81JSqFmLAFH6 xKJBWzNqs/ewG+6Nlu9rDmwT4xXAHOSEN3IwDE37746FCFd7XTdhiq1o8SuQKVZBBaYc f/UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HTlSWSoH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r10si1300899ejr.168.2020.10.27.08.56.55; Tue, 27 Oct 2020 08:57:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HTlSWSoH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1783110AbgJ0O5x (ORCPT + 99 others); Tue, 27 Oct 2020 10:57:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:45244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763868AbgJ0OpT (ORCPT ); Tue, 27 Oct 2020 10:45:19 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D37D8206B2; Tue, 27 Oct 2020 14:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809918; bh=v1Z+kyM00XJqxJX/GQ2PGnu5D3WwgfqCSvSBlCHzPZw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HTlSWSoH1XAqg2maPlqVMkZVkcT7jd/NRb78xNVeZeQncQN632y7T2LtD+BgG3qLe 76bz3e28ahJ5iVJ2QT7IFMAMVms2sh7dnUqqxqW2GAVYFgJRLBKdQFMIXiGoCCRdeS dm8jCxm5/3w/PF/JIdMg4rW+AQuzgTEnfSoDBOK8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+aed06913f36eff9b544e@syzkaller.appspotmail.com, Rustam Kovhaev , Andrew Morton , Anton Altaparmakov , Linus Torvalds , Sasha Levin Subject: [PATCH 5.4 348/408] ntfs: add check for mft record size in superblock Date: Tue, 27 Oct 2020 14:54:46 +0100 Message-Id: <20201027135511.159364177@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 d4359a1df3d5e..84933a0af49b6 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -1809,6 +1809,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