From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 DC63A3B1008 for ; Thu, 20 Aug 2026 06:48:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787208512; cv=none; b=G9gcUA7lWJT1jvH729MiNBhq6hGnJ7c+X9jewNYMyj0aOKFHqkYiZGLea88MKmmezzbsxTSqOizT6kDpSn3AIu06jb66x0lVQqsvnxYRyQdOtjcDj16gHCgt7TLSsg/jrYVnQ1GSwJgOr0dy7HZ1ydwzAlX78lQpyYy8h/seECw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787208512; c=relaxed/simple; bh=/UCVxZk2QssJLuKMX9Jg2Mh+HN80WKve1xMiWQfJ4AM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T6ikATyiem6/B1p4fm+gBtas7iSIZnqf3Zcas9nbUTSMnH6CFqBYusojAsZ9B504x+jkvj6V3KHtKV1nstuyOmI7tg7yOVrGaqVu5109e6Vvrnpt3k1GVi+g2pXsma4L1W0/Kmw7MoE94wUAVhUXETYfp9zugpdsjf9/Q1Bm0Q4= 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=dYH0kmcK; arc=none smtp.client-ip=209.85.215.180 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="dYH0kmcK" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c9aea40d799so940469a12.0 for ; Wed, 19 Aug 2026 23:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787208510; x=1787813310; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:subject:cc:to:from:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=pgkmn85tVZpcP5UWnOcsGVdM3fDAb124VxlJmt14G5U=; b=dYH0kmcKaG0AhtSeQWYenkZTjEzXEOVhMQX5BW/4t4SrKV3cDu1ShV3dH34UNtu1iG znAmLKf5YRYbCB8ERTJIVIQXaM0kSSZ/68aPZQ/F9GHG+RBQfLPd9YWpWVIfjcfditsp DKUh+f4e/rDCy8t0+7vadRtvuz091etuY+CJxwXOUS2sjXLYJSf+VPEoCvFw3CgL7M00 NoWhDPegzHesgMEQdeTzB/GU7ITgGdlKQUxCeyyo8t6vRkZngh/OgsrKS2tEF1vvCwoB f/lyRfYJy4leJHB9YeJ/4K/1n1DRhDqPwoLsuRP2WG2cUE+2kxQKku8rSrEGLy9pWSm2 IzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787208510; x=1787813310; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:subject:cc:to:from:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pgkmn85tVZpcP5UWnOcsGVdM3fDAb124VxlJmt14G5U=; b=cwO4nKvnGLrhLm74TY38k8moL+3OPbqYWPuwA1BFmUX7KYIrp1UN8Ll6+AtZh2Wc6I 7cxV58gToqyUnleT32kiqtkHB4gfU2G1heRASSlNTT3eXdG7Am6rQAJbsfzF/2MT5e7d bwqqtZColZ+YRuOS3GuRUvHPtYW5P9zsnWSvJRED+205nEMn9gbIIgqg/c80XC26bylW yHjM/yHaqZ/0HRMJl9x3XVLsAmSYMzwIloztOZDTpkcLpUBH1RzxB5QLfE/aeo539mBL tuWW7tsxuvFl98CY5Y/f7eYSk19WNQ1pTjWcAbS5VPr/E4JG0gqvH+Rf0EXOIuQQOJIg 1p/w== X-Forwarded-Encrypted: i=1; AHgh+RqQpjtJYhFvd8T73bTKA41tAKfP4ftCap5jsZHJmvNgJKZ6fgwteRoGqTUtnKUhfP2w/VQumynRYbBHW6U=@vger.kernel.org X-Gm-Message-State: AOJu0YxagHH6ft/kOmsdrhI0w4VfPHGWgPr9q0OZhFk6luO+b8McJHDU Hy0jBPrB+2WclyLLUYv3TAryZwHLOA5UIc3srasyRpU8T2v3/hzsK+Ie X-Gm-Gg: AR+sD11qUkz7mKLY/YPaorlT8hGUTWEsakZ6ymd4/MLSfpPo5NF3zkTJloPpZ/yuezZ qByvmqBWCmz3A5t+RnIQto2o/2rucLfEte1Vb+TeTbka6LznTQaZPc+toddUADuJ1K6vzidh523 y2a8uwwIoLtKcmIpQAC15LlkGNRgH2ZzzA0ySzC1dwZqoT9c04sfSCTPktEkt0DaJfhpYyRL31v 7Umqb5VrQhswTsk4lXaLoih3cq6zubf6NBYXcc/nId7HE2cNUgaVfiAQJ3YSdYkt2SW+fksrPRc hVAieIAOLNVizbOctNaPCemxi+GW0b+D8Qj16n6nxXXLwJieiQs41WafV0sjHROa6wzl9XuQegw K8GGKhGohgzhpcub3XPyOqip+6yvkkGIwlBmdIeZFnkExpiYb/FRg4u0nY6PXoIgtHW0/x+PgJN S0lPamW4mPqSee4zZ//XHcIqWtOZYbJRNchxHrM5i7eQW6v1MAB8ZFpqZ4KQpjKxbWQ4vecTvEM qkIUuSLUTGVsxxz9Z9Okoe4px/royGkfc/VgMiSdA0jSg== X-Received: by 2002:a05:6372:a80c:b0:3cd:f6c:6cdd with SMTP id adf61e73a8af0-3cd0f6cc723mr11226457637.16.1787208510058; Wed, 19 Aug 2026 23:48:30 -0700 (PDT) Received: from localhost (75-172-9-230.tukw.qwest.net. [75.172.9.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327bf10a94dsm13351085eec.15.2026.08.19.23.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2026 23:48:29 -0700 (PDT) Message-ID: <6a86a33d.92d2873c.12c24f.5c15@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 19 Aug 2026 23:48:25 -0700 From: Dennis Tighe To: Hyunchul Lee Cc: Namjae Jeon , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ntfs: validate usa_ofs before preserving the update sequence number References: <49b4a00a-351b-4eae-8466-feadb1851156@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Aug 18, 2026 at 04:46:12PM +0900, Hyunchul Lee wrote: > 2026년 8월 18일 (화) 오후 3:05, Dennis Tighe 님이 작성: > > > > When ntfs_mft_record_alloc() reuses a free mft record it reads the old > > update sequence number straight from the on-disk record: > > > > usn = *(__le16 *)((u8 *)m + le16_to_cpu(m->usa_ofs)); > > > > Here m points into the raw $MFT page-cache folio, which still holds > > unvalidated, MST-protected bytes: the folio is read by a plain > > iomap_read_folio() and neither post_read_mst_fixup() nor > > ntfs_mft_record_check() has run on it (both work on private copies). > > m->usa_ofs is therefore an untrusted u16, and a corrupted record can put > > it past the end of the record so the two-byte read lands outside the > > folio. Reading such a record while creating a file gives, under KASAN: > > > > BUG: KASAN: use-after-free in ntfs_mft_record_alloc+... > > Read of size 2 at addr ... > > ntfs_mft_record_alloc -> __ntfs_create -> ntfs_create -> path_openat > > > > Only preserve the old update sequence number when usa_ofs is even and in > > range, mirroring the check ntfs_mft_record_check() already applies; > > otherwise leave usn zero, which the existing restore below skips. > > > > Fixes: 495e90fa3348 ("ntfs: update attrib operations") > > Assisted-by: Claude:claude-opus-4-8 > > Signed-off-by: Dennis Tighe > > --- > > > > Reached by creating a file on a mounted image whose $MFT holds a > > corrupted free record. This seems like a fairly low-impact one, but > > given that > > it fires KASAN, it felt worth submitting a patch for. > > > > The KASAN error that I received on 7.1.7 is listed above. On a RW mount > > this is a > > one-shot per image and only trips KASAN when the next page happens to be > > poisoned. > > > > A reproducer is available if you'd like (just reach out privately). > > > > Found and fixed with AI assistance. > > > > fs/ntfs/mft.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c > > index fd20d7a..271a265 100644 > > --- a/fs/ntfs/mft.c > > +++ b/fs/ntfs/mft.c > > @@ -2333,7 +2333,17 @@ int ntfs_mft_record_alloc(struct ntfs_volume > > *vol, const int mode, > > * wrong with the previous mft record. > > */ > > seq_no = m->sequence_number; > > - usn = *(__le16 *)((u8 *)m + le16_to_cpu(m->usa_ofs)); > > + /* > > + * The mft record still holds unvalidated, MST-protected on-disk > > + * bytes, so m->usa_ofs is untrusted here. Only preserve the old > > + * update sequence number if that offset is in bounds; otherwise > > + * leave usn zero so it is not restored below. > > + */ > > Could you remove the above comment? > Also, as I mentioned in the previous mail, > I could not apply this patch. > That was a misconfigured email client on my end. Sorry about that! I've fixed both of those and resent. > > + if (!(le16_to_cpu(m->usa_ofs) & 1) && > > + le16_to_cpu(m->usa_ofs) + sizeof(usn) <= vol->mft_record_size) > > + usn = *(__le16 *)((u8 *)m + le16_to_cpu(m->usa_ofs)); > > + else > > + usn = 0; > > err = ntfs_mft_record_layout(vol, bit, m); > > if (unlikely(err)) { > > ntfs_error(vol->sb, "Failed to layout allocated mft record > > 0x%llx.", > > -- > > 2.47.3 > > > > > -- > Thanks, > Hyunchul