From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (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 78DF93EB0ED for ; Fri, 26 Jun 2026 10:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782469458; cv=none; b=CtTuMx4vdLpZQ4RY8uMpIZr48nJ2wTYYb04lFqyRyC/n+ehT1sOWQ/oSkInHTS0/hom9J3bdMLGzNLczxCHtCZEmIlPEvgj/zUkl11MF4iE7BcqLygvlx9rc28v55R8rsgTSpKKiIyJRx0XTVIidOJlGk5aFvuLV/LFDN47uZpM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782469458; c=relaxed/simple; bh=z83CdnLi5YFF7qtCrEOr+qnnMz4U3Td81HTGSmZvel0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pMsIb8gAKC3XBLIvPn/oEkqaIFsBJG+TrIRaLUNaoJlYnvmZn2jL3QAo/i/346nAbd2WBmjWJ5xBS73ZyB4o8yEC4ia1o8UphiaoljOnB7apSxoB0YcH/4gYV60t0WuzprCmoTHUDauIKqFYxk0h+rnW1xsIyIDWBnBAspLUNFY= 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=oK2Rkyc7; arc=none smtp.client-ip=74.125.82.172 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="oK2Rkyc7" Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-30c944aacbaso1239267eec.1 for ; Fri, 26 Jun 2026 03:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782469457; x=1783074257; 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=cdNQ71yKzqYp/ZHR9FmFA9gCxqpqHZZIFlY6KfiVT+U=; b=oK2Rkyc7ZCvyz/x+Whf2aTJdeRhBj957Yu3AYuTFaDIjeh9LfMlgSu0x7OhXAgxLrv BKX7+U3G3GMClhXGLagkwIa8O8El83XM3Zbzma7r3JVlSUobvfsQ93wz0KRtYd8xHy0z twrZaoSbjykqZqDG24wYJ04sY/iegJo4yH5bXDn96Xv+Mx9sY4jwxJJ9/Nci5FFmEXG2 dr+Gpn1fDqkw0r5hz4onlEXIp5hscZY30Tl1ZuTGjgu5iZ8OiyS0AEmN5Gbzsa8rzkLE PC5YlTqmEdq4nY/rBeE0THKNr2Cv356+CZzXf/wZx6O2EPjxYCFkTtJtx5/TFIG1YxTD oVQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782469457; x=1783074257; 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=cdNQ71yKzqYp/ZHR9FmFA9gCxqpqHZZIFlY6KfiVT+U=; b=YgTbZxUaEM898/MoA3TkULdVGqg71zP0KMvkDtt1RpanfhLMm9mp8kp1jcL6tesh13 WAIlII8xM6QxbRG/TjCGyyNNMK3wL2kYksQOkj6Sle3tk0FMpG4ksFN7wyUtKJKEwoTq cb0lHW2/Dikvv0/m2wXiR4xmxcXjXE3N+QTlTBLhCTgGxJ4Ppwa1mR+Td/WkN8YnlPOp iOXRVEm5izdVhApWwTV44+TAyJ08eqh5wg2TEjZyGOZ1R+w42prA+eB580DWv5NgbWjf giVFxo0/UsWAS9wfjoSu+rT9cMTcY2+5+SJqv9L0gryx6ePOenLT3cwYSA9/MtoYQ7lu caYg== X-Forwarded-Encrypted: i=1; AHgh+RocKAxM6CbIMBS9vMTep7DGePFqtOsrJO3LRTtXs84zmdIXMzn1Y7p+b9Ov9Qaj+OTPUf9NGitZpf4GVys=@vger.kernel.org X-Gm-Message-State: AOJu0YxWA1QrDlojUuyxdHGCkwtmQkFNNATQIHMQcES/YefzF+pegv67 QBJ9m8+besiiojG4bQ9uLyiKbBCwque/KxNegeSszLnIu5szyOjV10C0nnfynUJCrpU= X-Gm-Gg: AfdE7ckq1J5GjnCfkIAl9jl9C9cWEbvR1fhD53SijRA8hDKGG+YTmAFE8cHc8AqZair hffhIFhyDQ7a0Y8CGHYdvzFwLr4NyyA2Gi98UGBudSAhOsLyp8sq7pxGR8Q1m79xaRKSaqSfMWJ Zh/a7xD657DX/zB3FrBLIZOw/cym81q8O8jpaF3iAlj1T/mJFuAoB6A3Pa5+SNXjl2WV1uOnwWi KY2ccocGX9ct/hDrb18zxeHkSoOH2SupoKsDl9NNM3D5DwfLNESmWysunfyJBVbUKXQCHibEMG1 YWQG3gQPEdUJZrM6sa1Lgx3U1EK7E12ZLD+0Vf/BLFYLo+MOUKiM2cciIE2Q1EDeQOXq9tcW1Ex sFCjipegV9Qv6lY+BlVuHaKqEXELCt6TJLw65xsyWJ3d/kHaCkZOjfpbrt99vhOx3y70bRgjtkB vgn+yt9kLGLZRvTslYn1dI1CEEZziPrLUqQMxMsi+tmkABcO5UFSndmjR7PA== X-Received: by 2002:a05:693c:8951:10b0:30c:a62b:d033 with SMTP id 5a478bee46e88-30ca62be4f9mr420484eec.15.1782469456483; Fri, 26 Jun 2026 03:24:16 -0700 (PDT) Received: from fx.tailc0aff1.ts.net ([206.206.192.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7ca87caasm15840584eec.27.2026.06.26.03.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 03:24:15 -0700 (PDT) From: Weiming Shi To: ntfs3@lists.linux.dev Cc: Konstantin Komarov , Xiang Mei , linux-kernel@vger.kernel.org, Weiming Shi Subject: [PATCH] fs/ntfs3: take run_lock when freeing offs_folio in ni_decompress_file Date: Fri, 26 Jun 2026 03:23:43 -0700 Message-ID: <20260626102341.1909289-3-bestswngs@gmail.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 attr_wof_frame_info() allocates, caches and dereferences ni->file.offs_folio under down_write(&ni->file.run_lock). ni_decompress_file() frees the same folio with folio_put() without taking run_lock. When a WOF externally-compressed file is opened for write, ni_decompress_file() can drop the last reference while a concurrent O_RDONLY reader is dereferencing the folio in attr_wof_frame_info(), leading to a use-after-free: BUG: KASAN: use-after-free in attr_wof_frame_info (fs/ntfs3/attrib.c:1619) Read of size 4 at addr ffff8880120c9000 by task exploit Call Trace: attr_wof_frame_info (fs/ntfs3/attrib.c:1619) ni_read_frame (fs/ntfs3/frecord.c:2421) ni_read_folio_cmpr (fs/ntfs3/frecord.c:1916) ntfs_read_folio (fs/ntfs3/inode.c:648) read_pages (mm/readahead.c:181) page_cache_ra_unbounded (mm/readahead.c:292) force_page_cache_ra (mm/readahead.c:364) page_cache_sync_ra (mm/readahead.c:573) filemap_get_pages (mm/filemap.c:2688) filemap_read (mm/filemap.c:2806) generic_file_read_iter (mm/filemap.c:2994) ntfs_file_read_iter (fs/ntfs3/file.c:842) vfs_read (fs/read_write.c:574) __x64_sys_pread64 (fs/read_write.c:773) Take run_lock around the folio_put(), as is done for every other access to ni->file.offs_folio. Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation") Reported-by: Xiang Mei Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Weiming Shi --- fs/ntfs3/frecord.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 2b49bc077558..b11961a1f8d8 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -2148,10 +2148,13 @@ int ni_decompress_file(struct ntfs_inode *ni) /* Clear cached flag. */ ni->ni_flags &= ~NI_FLAG_COMPRESSED_MASK; + /* offs_folio is accessed under run_lock in attr_wof_frame_info(). */ + down_write(&ni->file.run_lock); if (ni->file.offs_folio) { folio_put(ni->file.offs_folio); ni->file.offs_folio = NULL; } + up_write(&ni->file.run_lock); mapping->a_ops = &ntfs_aops; out: -- 2.43.0