Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp5116773pxb; Tue, 28 Sep 2021 10:51:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm4Q5H4kTFdAra8/w+cXFObW1jOdS2aoYZxFnGuuvUQ6tsnhsmu0/LgPuadmhx8b5RLA9F X-Received: by 2002:a17:90a:4801:: with SMTP id a1mr1339175pjh.156.1632851493918; Tue, 28 Sep 2021 10:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632851493; cv=none; d=google.com; s=arc-20160816; b=Q8AERQr/Q/ZHN8cTLC2q77p4pYu1R1iU/7udDVlwUwzG+h7+ZmLeUv3bYGs5d0UYzk A1imNH7uurZBlD/rsV+P9Pw1AA7aFrd+ygML51dXm+gwtET+PK9gsGNHaQCjGRmsmDAL 6zhNhd6PJvxKWNmfllmpAKvjjGQ20jpFoXIZIuu+a0GDwtQn3QN+5aixzAsN4H7ccd02 z8NQNbj0hunpdD2uAy2Q+SVhK/q0p+8/lAjE2BwH63B8OrpTBrZO2H52dtjMUsoWAgQi 5LklY3xKc41XpT+j47I9FkN9W8yrLWEx32lb0GVegcrcm0FJMfCn08ONeuBYyNV9Ca77 zYjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=I6dxCXn0jNZZaFv7JKVRXPY3OVFbnaASgRPEVdZRV64=; b=JNsZVzvVSGFdpNn26xhZ15Z6o4ya6puEkgRvqjQSQyR3Ehzs9a5zBXae2f8kc3LeRK B6En8E+cO3Lukz3sKzKq7SoHs1KFcU9maKoLPpe6a9x8AAdy5jbCTpojmSGqhioeZxWV lc6hSKC/YB9gCqhH17xeukdi6CLl+OnFlmkL1EwGChg0dxsDJHLjIrxGc3M7Hfe/sAgu TThOrTumX/yaNb1OpBSyjRUK+k9C8Xvr4hYyUblvJ6VbQoDhGiAS0fxWT13OTZi6kQAJ pKYkS5HloPDUmKBDdaJJwCQB8QAw70IrjmzcxbhP//RM/YadMXNfS1S328elypd1R5vM sjmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=tmgfn5XZ; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v13si23832936ple.422.2021.09.28.10.51.18; Tue, 28 Sep 2021 10:51:33 -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=@paragon-software.com header.s=mail header.b=tmgfn5XZ; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242009AbhI1RTv (ORCPT + 99 others); Tue, 28 Sep 2021 13:19:51 -0400 Received: from relayfre-01.paragon-software.com ([176.12.100.13]:35878 "EHLO relayfre-01.paragon-software.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242008AbhI1RTv (ORCPT ); Tue, 28 Sep 2021 13:19:51 -0400 Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id B5F99454; Tue, 28 Sep 2021 20:18:09 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1632849489; bh=I6dxCXn0jNZZaFv7JKVRXPY3OVFbnaASgRPEVdZRV64=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=tmgfn5XZBuktnx7r+Z2I5Aih9gscWadHYr+f4C7XeJK1kpZrdqTTPL36+R5VPFkZY 82dXSp3u4M7ELZCpP8E/E9Wc1aenVnm227WzX2iLlV0OZq69N6dI/qOjsjosheaAEY sNatroK63X7KjOshvde02fdUDVoeqF6Kd69LVl+Q= Received: from [192.168.211.85] (192.168.211.85) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 28 Sep 2021 20:18:08 +0300 Message-ID: <228cbe20-87d6-4020-55fb-111d22e2b487@paragon-software.com> Date: Tue, 28 Sep 2021 20:18:07 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.1 Subject: [PATCH v2 2/3] fs/ntfs3: Reject mount if boot's cluster size < media sector size Content-Language: en-US From: Konstantin Komarov To: CC: , , References: In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.211.85] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we continue to work in this case, then we can corrupt fs. Signed-off-by: Konstantin Komarov --- fs/ntfs3/super.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index aff90f70e7bf..890c5d9d6d60 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -763,9 +763,20 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, sbi->mft.lbo = mlcn << sbi->cluster_bits; sbi->mft.lbo2 = mlcn2 << sbi->cluster_bits; - if (sbi->cluster_size < sbi->sector_size) + /* Compare boot's cluster and sector. */ + if (sbi->cluster_size < boot_sector_size) goto out; + /* Compare boot's cluster and media sector. */ + if (sbi->cluster_size < sector_size) { + /* No way to use ntfs_get_block in this case. */ + ntfs_err( + sb, + "Failed to mount 'cause NTFS's cluster size (%u) is less than media sector size (%u)", + sbi->cluster_size, sector_size); + goto out; + } + sbi->cluster_mask = sbi->cluster_size - 1; sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask; sbi->record_size = record_size = boot->record_size < 0 -- 2.33.0