From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 5F7EA23D2A4 for ; Sun, 10 May 2026 02:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778379199; cv=none; b=Ja9rDQC5RgqegRlbu8//B8/v9mnx/gpsyvcNcq6AeRH+GhUK7eicmTUcMuwaLj27hSUWOYgymDvBpQ4unLZaD1L2inqHQnu+NlzYZac65TU6C+iF+w81h0ixTBZzzvhuQ98vuewVb09Vp8KfHNWxZQzYBDRS8hwFWAuy8JIIu1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778379199; c=relaxed/simple; bh=yXheuGFy2qbjBy2ZCssglZXPh1JICTl/KL9JvoD65vI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oQAtEPbsF6TTSOtAdtC31BY3VpxlJT16usjV7UcYQJHQBFNMIRLobGT0mQiNbszu/3nRa+7MqqEYk0qRhzqJimUOnTwK3nnfHUaPl1VWWgzWPNO3q5J+YNiG7e85lyhnftDTVrmuKJI9QjX6M5yb3P6Y2StR6zBIrQEgT4uJEF4= 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=Xn4dYpi6; arc=none smtp.client-ip=209.85.216.49 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="Xn4dYpi6" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3652cd851abso201924a91.3 for ; Sat, 09 May 2026 19:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778379198; x=1778983998; 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=orcsdW0I4eD4Fzyp6eZiaAfyMuG71YnoyR/PNIS2A3o=; b=Xn4dYpi6kHhDAqcty0unKFvaSDraH/hk0y5vi5F7GEzxc63PXjr6UezfLk3tGeSYW6 bl32g+XeF2KLQTu8bV+mfH4t2yA+BlxKNOdrjAmwyh2dizyuSs0dZxUbc5xsum3E+hNd fp3Rj1w07mujxpYzPcR4JObctN2Micyac/3EKgvzTtZXobupQWlp5QPo9vUn98l7AV+a TPo58i8UseuF8leYsNwYSh9SgZLNywipxXJDQDlbWc6kM76ioRlLtzqCu07tELcor6s6 Lm+RaD6jziyyVuV3H8YtEm6b7YnW37ecSR3V/Jux9fuLJ6ElTdpQkKnbrV41GcRy1Cqn G2gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778379198; x=1778983998; 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=orcsdW0I4eD4Fzyp6eZiaAfyMuG71YnoyR/PNIS2A3o=; b=XA2YJqm77oegy5uQg761FlKRaUfxooUyeyhvvhPMwR7JmHo4gxTa68O61cC7JAbT9h +z11Nt8Mq1DW74OxN3Ssv8JAnRl+VN4+wKmUFRlT6YXuMAxKpi8tdpR9qEAfWuhKStaG 3F0WQzRhs3CGLJgi5mb7v9QPwAK4M0KapLW4R4Ulc0CNHDjwZgcsGsmxMmyeNLqzUnnU JYrTsT5jImZQNwvzMIbMxZ+EVVff1oHFv+Ye/nJBbwz6BoftRwEJOr9qvkuYQE2wxa9F hAVnXmHjQ1FLirWB4HWFcCMTLzH+JlmJKgA191rl9Lijb1Fs/8yD01VAz7+5FBUwspVa Djrw== X-Forwarded-Encrypted: i=1; AFNElJ/u6eAKTsJ7HWRuVco0q/yX24OMqCL2De1upH7l4GYb5jgn2Ne91E1uFmo9F3ZLdr1CoTS7/Bw4sOxLg68=@vger.kernel.org X-Gm-Message-State: AOJu0YxB7vkZMS9oVvLTh9C6bCcZnhSeL+9HIy0RvY7zHarxlf5VoXgH WC03V9IWut5jCa+5U7IvXmBoa9qube+fnyCaV/r7JWgrlpKIjFKkaCkX X-Gm-Gg: Acq92OGELaL6SYgCuhLMsrblYjO8sFy1pggVyJjWiZnIRuCPIBpOlZGCf1v799v4ypQ 5aui5xXQEkXvq+3vaLFO+QkBBMy5PgatxLwTKc72ag7xTYXFrSerEg6euUIDBKFa5bWveSkweZS TaLH26V5195scE+Wh2m0vdW8fKLEoIjo5mz+N8LVdkekSt7w8LMfRFZa0i7WI/Qo5T3iJi6Xl8i kGNbfqHa9osjNxBaXflI+Db0QJlrkWlNhGZBkFiUslxjULSwhX43dIYScFLOyEo/Z+bY47+axcb /IhYTJ4PKGOgoF9pLSLyAvqyIZ66bWtRLVeDmHPcFNkscVpb1NwaHYLH5yF7qCKkk4yDJ1+B/fx dmi4mdu4N7fGdBl6HqmDhMcvv31iyZW5v7jt+VHcyrp3rrg3/9nygldqtu4Dcd8CMV1iWHJ7+PS C4YQK7h0Z2BV8tfhjS9QYMXTCbOPQ= X-Received: by 2002:a17:90b:48c4:b0:367:e244:4c43 with SMTP id 98e67ed59e1d1-367e24450b3mr1964505a91.5.1778379197657; Sat, 09 May 2026 19:13:17 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-367d65ed459sm4121295a91.14.2026.05.09.19.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2026 19:13:17 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon Cc: Hyunchul Lee , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, DaeMyung Kang Subject: [PATCH] ntfs: fix empty_buf and ra lifetime bugs in ntfs_empty_logfile() Date: Sun, 10 May 2026 11:13:11 +0900 Message-ID: <20260510021311.3995015-1-charsyam@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 ntfs_empty_logfile() has three related allocator bugs around the @empty_buf and @ra buffers it uses inside the per-cluster loop. When the loop encounters a runlist entry with LCN_RL_NOT_MAPPED, the function kvfrees @empty_buf and goes to map_vcn to remap. @empty_buf is not cleared. If ntfs_map_runlist_nolock() fails on re-entry, control jumps to the err label which kvfrees @empty_buf a second time. In the same branch, @ra is left allocated. When the remap succeeds the function falls through the @empty_buf re-allocation and the @ra re-allocation, overwriting the previous @ra pointer and leaking it. The success path frees @empty_buf with kfree() instead of kvfree(). kvzalloc() may fall back to vmalloc(), in which case kfree() does not correctly release the memory. A KASAN-enabled QEMU harness mirroring this control flow reports "BUG: KASAN: double-free" when the second ntfs_map_runlist_nolock() fails. Clear both @empty_buf and @ra after the in-loop releases so the err path is a no-op when the buffers have already been freed and so the remap-success path does not leak the previous @ra. Switch the success path to kvfree() to match the @empty_buf allocator. Fixes: 5218cd102aec ("ntfs: update misc operations") Signed-off-by: DaeMyung Kang --- fs/ntfs/logfile.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/ntfs/logfile.c b/fs/ntfs/logfile.c index 2f960b8f8cde..5a09f2b05df5 100644 --- a/fs/ntfs/logfile.c +++ b/fs/ntfs/logfile.c @@ -768,6 +768,9 @@ bool ntfs_empty_logfile(struct inode *log_vi) if (unlikely(lcn == LCN_RL_NOT_MAPPED)) { vcn = rl->vcn; kvfree(empty_buf); + empty_buf = NULL; + kfree(ra); + ra = NULL; goto map_vcn; } /* If this run is not valid abort with an error. */ @@ -821,7 +824,7 @@ bool ntfs_empty_logfile(struct inode *log_vi) } while (start < end); } while ((++rl)->vcn < end_vcn); up_write(&log_ni->runlist.lock); - kfree(empty_buf); + kvfree(empty_buf); kfree(ra); truncate_inode_pages(log_vi->i_mapping, 0); /* Set the flag so we do not have to do it again on remount. */ -- 2.34.1