Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp242635rdb; Mon, 29 Jan 2024 00:08:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpVgpVM2rdKSvHH+uRQ3Yd7oUoT/BpGsYLDKc4T4RoqRmJsQZ5Vf8t7vMwpOM+3VG6hfd5 X-Received: by 2002:ad4:5aad:0:b0:686:49df:8e3c with SMTP id u13-20020ad45aad000000b0068649df8e3cmr6799632qvg.43.1706515734642; Mon, 29 Jan 2024 00:08:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706515734; cv=pass; d=google.com; s=arc-20160816; b=oBe6mVaDq0m9U56t5cMOkMCqiAdbrUEowWtH6Mpw49lPqJQSeiMTPwfEtWQkHloG7O kuAEbXS64updjulLXJz9BRGPN1X3P6yUw+9FkUUcc7VLhZXKRGDkTOQD2DDIPoiFnzAr oNUvPFzIJ+2yCWj7lULjJ/gtiP3ZDgXUgG5acq9aFhpdSI0kEOf8HJfmbho7K3SKQlCK /eoOQD8R9NqHqUA/JXkTw05Ah0RFU+rLno1oGFyKFFvygV4oN9VlnPIHvz85M3c4KjMd /r9B4lCfAU7OhmfGRUJJMJv9KDaiSxBsXRRQxNAMzhAsOUBKWJ0OUgflaltClaThq4Qz R92Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=xeznt+Dol1rUDewd0bVWo6D8uEqRIEtOxRwa5jeQ4+4=; fh=P7I85FIabZcM8ojWdeG8ABpTZepe/Xtte9jKWDfUHBM=; b=tjryMinTadVCXyMVQr6eve5Hyxwolkmn+9IJZ8LeZJyuoPRc08yO8WT1P/wAr3JVuz vOoqMn3pWObzX0xzZc8xqyCdxNlKNjDboA8aVVmixMvae48RPcaKhs4iGmHmQ79ETASe eD6O6OVk/BehOng59A5r1dE+sE06YFgxwuScounFDE5VII9c5FjWYb9/OFUbkhYYzy3o z/2K61wDA3fEG/bJSRpj4EBXRJVL87ahZfKRxlZLsD9KPGWNy4IX7Vgc4/lSZdyvBjJA Muvs/bB7t6EtK26AUr2MeqFdFCHvF4hKr8L4OEhvLawbHxpncWtJKcMy81Gon6NUrk73 W27g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=S74i0XWS; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-42330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d8-20020a05621421c800b0068c3d2afb85si4716901qvh.609.2024.01.29.00.08.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 00:08:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=S74i0XWS; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-42330-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 65BE21C21AE1 for ; Mon, 29 Jan 2024 08:08:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 593A252F8C; Mon, 29 Jan 2024 08:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="S74i0XWS" Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7CC452F68; Mon, 29 Jan 2024 08:08:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706515726; cv=none; b=gdPIwPe3alltsMWueEij+nyqBmg86gzpfAcgNrrnYEKaALmWIy0FESGrdzv99b9bl9b1OmbnLrBISehfVfkauLIH2DuAiVzU3XcYUtfX//I+y8rE0HQkAOahnQwWryrOzeSGyVB+0u+pvXk3rKueSrVubVBSITV/qY95z2E1OG0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706515726; c=relaxed/simple; bh=eLCjjqfccU7QtD9Z/zPxtm6zfiWJea3+n+pEq5WYGg8=; h=Message-ID:Date:MIME-Version:Subject:From:To:CC:References: In-Reply-To:Content-Type; b=f0ypxJX1eSNWf6drQxwrc2DM7LJvGe8hMpqRgr3lakiyezuPxcSeYsZV6XP6MtjlN8T9rZ+1a/DNXjHNs4dITaMITWz+U1xAzUrputk6OwyGAcM0EkSRw0X7m47gUGTi2+w1bfx+8s94O3DWBFjxXmgEn74rmBVWSXdr1HwIoB8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=S74i0XWS; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 91AA2211A; Mon, 29 Jan 2024 08:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1706515311; bh=xeznt+Dol1rUDewd0bVWo6D8uEqRIEtOxRwa5jeQ4+4=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=S74i0XWSIfRF+JVBnt337iayJpkT1ksrZPWaVFe8U6idhyTol/XtAFED7eKiihHXx 3bnLehRD7HFMSud7BGLytgQenaWmN2Y9n9bDKednKjAyM5gX0pt5omodk9cUoNasEt qNxW3Y+4Lu/jmzh69HgjeYCgWx04Bp7HsulTZ7aU= Received: from [192.168.211.199] (192.168.211.199) 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.2375.7; Mon, 29 Jan 2024 11:08:41 +0300 Message-ID: <1b1c7be1-0af8-4a2b-a37f-9eedf45cbf1a@paragon-software.com> Date: Mon, 29 Jan 2024 11:08:41 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 3/5] fs/ntfs3: Correct function is_rst_area_valid Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Reported-by: Robert Morris Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fslog.c | 14 ++++++++------  1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index 7dbb000fc691..855519713bf7 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -465,7 +465,7 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)  {      const struct RESTART_AREA *ra;      u16 cl, fl, ul; -    u32 off, l_size, file_dat_bits, file_size_round; +    u32 off, l_size, seq_bits;      u16 ro = le16_to_cpu(rhdr->ra_off);      u32 sys_page = le32_to_cpu(rhdr->sys_page_size); @@ -511,13 +511,15 @@ static inline bool is_rst_area_valid(const struct RESTART_HDR *rhdr)      /* Make sure the sequence number bits match the log file size. */      l_size = le64_to_cpu(ra->l_size); -    file_dat_bits = sizeof(u64) * 8 - le32_to_cpu(ra->seq_num_bits); -    file_size_round = 1u << (file_dat_bits + 3); -    if (file_size_round != l_size && -        (file_size_round < l_size || (file_size_round / 2) > l_size)) { -        return false; +    seq_bits = sizeof(u64) * 8 + 3; +    while (l_size) { +        l_size >>= 1; +        seq_bits -= 1;      } +    if (seq_bits != ra->seq_num_bits) +        return false; +      /* The log page data offset and record header length must be quad-aligned. */      if (!IS_ALIGNED(le16_to_cpu(ra->data_off), 8) ||          !IS_ALIGNED(le16_to_cpu(ra->rec_hdr_len), 8)) -- 2.34.1