From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E110F30C60D for ; Wed, 24 Jun 2026 03:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782272503; cv=none; b=IQ7Hw9V9WOo0i6FUZ5Bku6jEahjBfZKnDp3BXcFnKcwcFhiOcJ5y7/iDK5j3qWjiFqqCPWZD0qlNrMpczAWEYkislSDi2Tz5bBEeEOwabmIEw0VxqpOSZBlQvN4rVtA8958f8+xxA9M/vCS5twQJ4xaBqLUFrW8ZhUKE19gBBrY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782272503; c=relaxed/simple; bh=CY+tNU7GMtSGXkZAry8HH0JrKZdkesTI/8rov5D0NHg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=b+oUg65draSO9ppRArNqscUsbxqdNsKCs6Tg8VD/8ZnGy4eJq5BJ+NmiDxLx11RX+dgz1GfQamZqCAZ1UcbIgbT5DDAaMGej6B+XmftubnSDMmOKQgLtrHDbrp6CoaBknfozSZTzHDCfL5ifoEbkyrUqjiog2mIZqJj8H1o2mUo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P0pJtrX0; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P0pJtrX0" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-36ba285e98bso568015a91.2 for ; Tue, 23 Jun 2026 20:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782272500; x=1782877300; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=beN+/tmi2yavCBr4937vYEbhqn8BZbwpQDA/8eL/t4Q=; b=P0pJtrX0KTC3fTgP2aOqK3WhqGU+BpphcRqjq13XtISERxJfNJ6udSoqHvFmoPH2cu fKHDeroyyBK0+NBBCkUV3N3fFczpVC51aeDhLgdj9J9Tg04ddUh/oZ61DEB+oVhYeQ6g ZTWOtnf4aM4riVENcrP1X0HeMq7/8lQxGVzVPqS+oW/Cd/TXiZmRul+Qx8g3BfDHFMOe 4aOmgxnJLWdyN8NDNJW/SvZx8UyDAE8nb++c3XdoJx8D6QRlwCt8um92IC37NVrBHChy ROmTZ6+XbWEnIwTYhC/efQy509WTV8d1apaXBRJL8//1AT4rYXfKaMVeC4Ko9E3bffm0 RgHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782272500; x=1782877300; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=beN+/tmi2yavCBr4937vYEbhqn8BZbwpQDA/8eL/t4Q=; b=pqaOYvnZLmRCjQ6uDL70l0Kw7wKVTaOXCxkFIMzASN4kszMzWTMQA1p7zeahV4gELZ rZPrzyKUnU0NOea+3AOH76aEdz8Ni8HbHXF2BpPTU5bm3hpAbN62gLvohaFDC0eR9BoK X+Iu2Ivd+01vSEQx//JTj+NauPmQg9pxGGVd+0kGpiU9ryPkXjc5HdSkmBkmWRW0ipZl IFetNt0O62wtEeCQg+bbTHEEj1saM6i+AYGY3UzP4VA1uUhsyxapAfbSTdhzYMXgPh70 t9hotbj/HAAqOUq44ofncTBp3eUKx/6JHONbnqbwlwS7F1fzB94FiP+/VWLeRSArPCJW T/Yg== X-Forwarded-Encrypted: i=1; AFNElJ+jkiQaPI4fq2AqdiY0XPyaGpvq1k7QhJ11gV/G9mhWza+WMWaVlESkzB9Uui8KTwp0gHakxG/uWcQUoGA=@vger.kernel.org X-Gm-Message-State: AOJu0YwdMgp5KYWzvjfFUpCj1DPIG3/XlLCM1K6dL9Mxirj6MKm3Ljps y3QF4/224fEd0x0qYqMGMyLbspi4+xmsaWFQRcM1yyaDvYvohQpE1M2Y X-Gm-Gg: AfdE7cmNm4SLOnqXlEhi5DZUWM1S95GFbb9r4HA2GzAWe6aVOYXj2JVhFzvZGf8h4zX JtRiQSHse+ukgN1ylvSH9AzN6uTaH4BrsuM3GWN2I/3ToUHuBlD93VBtFOTWFo3tKVXYNzeyhfN YECMUDeiYEaNZ/gOvcLbB0OXVV3v0A2Tihhg3rJZBlTobBR4nKMSijN/hQHI/RGyoqYXoKNYEi4 ZQMsBS5MGbCK6cRaBuT9K060YCmWIo9V543VsXeW5ECFxacgL4Q9PWjPRawiuQQ275uCBqLbE/S wuPPS7Nck5uJzDiuA5+x+5KXpxbugmkQ5JGObBwzMxQ1DML+NRU6wznCysabP6Rpmv2mZEuht4E AaBUlmIO18QYNDYkfXbYaWnzz60pc9Lmh9NmQJIc0mqw6yzUQPJDzU4X8MXZXceLB72L75xi1EU cZXuUpRAyiGZLTjR99jabCLlA= X-Received: by 2002:a05:6a20:e211:b0:3b4:8fb2:a34b with SMTP id adf61e73a8af0-3bd14f2e765mr7359013637.11.1782272499998; Tue, 23 Jun 2026 20:41:39 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-845a412e5e9sm658494b3a.54.2026.06.23.20.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 20:41:39 -0700 (PDT) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: Konstantin Komarov Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org, Zhan Xusheng Subject: [PATCH] fs/ntfs3: fix integer overflow in MFT cluster validation Date: Wed, 24 Jun 2026 11:41:33 +0800 Message-ID: <20260624034133.57049-1-zhanxusheng@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In ntfs_init_from_boot(), the boot sector's MFT cluster numbers are validated against the volume size with: if (mlcn * sct_per_clst >= sectors || mlcn2 * sct_per_clst >= sectors) goto out; mlcn and mlcn2 are u64 fields read directly from the boot sector. sct_per_clst is bounded above by 4096 (true_sectors_per_clst() plus the is_power_of_2() check below it), but the multiplication is done in u64 and wraps when mlcn (or mlcn2) is large enough -- e.g. mlcn near 2^62 with sct_per_clst == 4 wraps to 0, which compares below any non-zero 'sectors', so the check is bypassed and the malformed record is accepted. The accepted mlcn is then used unchanged in sbi->mft.lbo = mlcn << cluster_bits; In practice the resulting reads fail at the block layer (sb_bread() returns NULL via grow_buffers()'s check_mul_overflow() guard), so today this manifests as mount failing in odd places rather than as something more dangerous, but the validation step is still wrong and there is no reason for callers to rely on the block layer to catch a value that should never have been accepted in the first place. Use check_mul_overflow() to compute the two sector positions and fail the mount if either multiplication wraps; this preserves the existing semantics (mlcn * sct_per_clst >= sectors) instead of switching to division (mlcn >= sectors / sct_per_clst), which would tighten the check at edge cases where 'sectors' is not a multiple of sct_per_clst. The check_*_overflow() style is the one ntfs3 already uses for similar on-disk arithmetic in fs/ntfs3/run.c. Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Signed-off-by: Zhan Xusheng --- fs/ntfs3/super.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 3305fe406cb2..4205a212154b 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -957,7 +958,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, struct ntfs_sb_info *sbi = sb->s_fs_info; int err; u32 mb, gb, boot_sector_size, sct_per_clst, record_size; - u64 sectors, clusters, mlcn, mlcn2, dev_size0; + u64 sectors, clusters, mlcn, mlcn2, mft_pos, mft2_pos, dev_size0; struct NTFS_BOOT *boot; struct buffer_head *bh; struct MFT_REC *rec; @@ -1026,7 +1027,15 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size, mlcn2 = le64_to_cpu(boot->mft2_clst); sectors = le64_to_cpu(boot->sectors_per_volume); - if (mlcn * sct_per_clst >= sectors || mlcn2 * sct_per_clst >= sectors) { + /* + * Convert mlcn/mlcn2 to sector positions before comparing with + * 'sectors'. All three are u64 values that come from the boot + * sector, so use check_mul_overflow() to keep a wraparound from + * silently bypassing the comparison. + */ + if (check_mul_overflow(mlcn, (u64)sct_per_clst, &mft_pos) || + check_mul_overflow(mlcn2, (u64)sct_per_clst, &mft2_pos) || + mft_pos >= sectors || mft2_pos >= sectors) { ntfs_err( sb, "%s: start of MFT 0x%llx (0x%llx) is out of volume 0x%llx.", -- 2.43.0