Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2777710rdb; Mon, 12 Feb 2024 17:03:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVGkpd65BHQocD0JJw8UMg4Y5EZeOQYUjGYtSw+Dc3vZxrykppPwFfZmZF8uDm3VdnLB2eNXfOpFgfSYQM0gUkXoGkZYdBewyr5aoH1g== X-Google-Smtp-Source: AGHT+IGJkBvhTB1EAgAfVDoZJSJQh/1U/SDvlLLPp/M6NrtWS6aKvL1rAaMciCYYTEUBIkikteDt X-Received: by 2002:a05:6358:70c:b0:17a:df3a:c2af with SMTP id e12-20020a056358070c00b0017adf3ac2afmr6028073rwj.26.1707786204215; Mon, 12 Feb 2024 17:03:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707786204; cv=pass; d=google.com; s=arc-20160816; b=uJ40XPST5g+NfiiTPVjRV4s4NLlwrI0uQ47y3hq7tZZ3TJAGaQPT/k9MhpZQ7gw4Vl VPik39xF/SAct+R6wdK1PqYsnLoG+oXiavrfDqxvj4bFXI6Jah4n30Mi2J5gIRtNNUQq WqMCywVmIeiBUBFhS8e1KmWxcRAgCLtnWSuHWXrRexndz/qHehPu6tILVZkFzNWi+5wG m3/dx1zw1vCmNC2u2jUi5jllPshjptjFwVzhwwGUSknAL7gOqyN0gUPH1ZCrcaJslZoC zuLW/c1Hu9HVTLbXKqKsZx4rl0KYslxDuWwBKmgGXQodCztKSanrfxX9XvtsMsgmQkIR JDjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bfwPlj/hzplYQ5cDi3iKcol/5RpcuOEZ9vrWp6GYOOQ=; fh=DD12jPjpKv2Hma7Rf/a6/JUwxx3m4HiFdw8nJbeU7X0=; b=EUlZii4z2LjrDGjyfiBs+dcdWWYY/F4YBdZYhwYZR/gke8AuH9Y/cQFnqypAgmcX6f QeiQpdMlGfWIG6JbiekdzAdc69Ztth7cxoLz6z7ih2dHAAJlTfNGFsVazgddKM49s0sH ZclKN1eMhxcsQRBi0TnL+BEpgVZWYuYEV83xAcwNKqmcKP2XEJ5jN1ztPTSxfWAxkQ2Z SYtt65xOzTJhV0aozKCBaVjK/oY0y9j4iUFRe+S8ns5g3d6KqTCB0tpFTO/leEvDgOOy w7kW9StaPq/LgX0Y4nv+nq+1+F6KtaazXqb/l91Ea25+5MVuB0PZMkiFHKO96ciNf12T gJWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qQqS1Y0m; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62694-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXAfD8vWTKVIhfT1WT/q1BkeAlhqlI5C+LiwfvcQ7i2q6XpL3OTC2Bqn7ciZLpjbuUGyCqtPS2WdVk1AYESvIyjpNym5CQ+fpHxtrVePg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e38-20020a635026000000b005dc867e6895si34622pgb.158.2024.02.12.17.03.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:03:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qQqS1Y0m; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62694-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C8E28B25AD6 for ; Tue, 13 Feb 2024 00:52:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A89179DA0; Tue, 13 Feb 2024 00:22:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qQqS1Y0m" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6180A79924; Tue, 13 Feb 2024 00:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783768; cv=none; b=lKMoNWSPsse5gsJ/Oc6nk6FNpSAuXnwZb9BILQgkYaDVdp/Xlg7XHkVLR7X9CeeFw8qoOin49gvNSJ+STqNalw/1f/3ljxx1kIzx8Mp62l9cyqXZBjozwQao0nVKPlG0+9Hq6g80T5CZgDt7wllk1YYv+pdez2TfMVZE+hrmF44= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783768; c=relaxed/simple; bh=DM/oJ02iFG+93phrWttB18O9CbwS834Lr4C862I6x90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eAFKAXMDm7J23EZlwMyDcCPvNoJdGK4gnb8PwcM7tinEThO/ueSH6m65TzHgZF9zjd+yOmMHaM5HQHGhdeyvkBmFcu0pyYZJ8+TTF3zWZx5ymOKwxkoXLAxv1oAN/8C0NG3cGUFjmOWBOjxCOuALh/8qYqGJX7T2oZIAjibjQvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qQqS1Y0m; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FEE7C433F1; Tue, 13 Feb 2024 00:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707783768; bh=DM/oJ02iFG+93phrWttB18O9CbwS834Lr4C862I6x90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQqS1Y0mnC7zvIGFW+yfYEe6xkYeDqlBrjt+dvl/aPefbAXBhtFJt9fAnjiNR9Sg4 HG89o7SqJ0YD8BfhaM7YKJR0EvHb3KcyewLGh2r/AehynEE2lm9YFb7G/+91vOazGr R6Q1XtM9MwzAqbTUFm1g7XJaeHb/vykdm9VV5LsdLFd/pjeD6Q5oq3X25QN+CZIW75 f9dZKmQk31F/AvoBkkr1wcCIy4ALcvFrAT8MunU9ENY79FX7xTH5WYVAMss5HL2WSo yrVM0IKrkNoUFALKzy1UkW9G2Ms00WcErQ2BlZzKmfbFR5vNI/riGTj2NENE8aHbLz POIQqRBcRhUGA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konstantin Komarov , Robert Morris , Sasha Levin , ntfs3@lists.linux.dev Subject: [PATCH AUTOSEL 6.1 10/28] fs/ntfs3: Correct function is_rst_area_valid Date: Mon, 12 Feb 2024 19:22:08 -0500 Message-ID: <20240213002235.671934-10-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213002235.671934-1-sashal@kernel.org> References: <20240213002235.671934-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.77 Content-Transfer-Encoding: 8bit From: Konstantin Komarov [ Upstream commit 1b7dd28e14c4728ae1a815605ca33ffb4ce1b309 ] Reported-by: Robert Morris Signed-off-by: Konstantin Komarov Signed-off-by: Sasha Levin --- 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 710cb5aa5a65..d53ef128fa73 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.43.0