From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 8E02037CD34 for ; Sat, 25 Apr 2026 18:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777142572; cv=none; b=KWpMs64w0uDIjYF6OIReWJ7WKm8V9SQ4uz3L5FWFOeQqLXAXe1TZMr59QzKoAthH4/5zATHRm1aPtclTCrWiBMm0uLigwVtMihil3PTIBjFI0lhxXVP5IoUS+dJ4uLYXTbUBJLKaRkDNUS61k8natqCeD6WRYGt6meFmqzNo5wI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777142572; c=relaxed/simple; bh=7vjQFDQ3ngEfFpRcZSO66m3dz8MlsyyYwJ6Y/OWi6nw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OwznHsFw9naU2fsnVAeGMpprbLYF4jy+JUOxtM+v7FoomI96GDGGPAMAnpuX+VIDckiTfAa9sbJPKL3MUfm9usHs4E3U/iQIlTimm06UskOZPDnTjZbsTE1sU5n3igFUPkgftez6VScmKbfDpUdEsIIpK5+al6Pto0F7wiE5hA8= 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=D3Fcu2g7; arc=none smtp.client-ip=209.85.216.44 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="D3Fcu2g7" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-35fba4f0a53so1467806a91.0 for ; Sat, 25 Apr 2026 11:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777142571; x=1777747371; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i6T7QXBLhmGguBHO1L+/WMwTbhQuI0+KzV9ksg4NtKw=; b=D3Fcu2g7kSIpN4IEqpFscIPIGWGzMf/vh23owWwJyjVPS4tJcWybXTPmTMQrSq+Bd6 lrRLhToo53c3hGqOZOdZ3tOOB1Z4WkeV4txv3O1wPBnG/hoCpMftKvGTPrLtBiJmqf+O wd9nn7zFypXR2Mu78X5S9JenCFrSpGZtmxprt2EItltXoHkZYStvoMJAvnsuXzWxYqaL dfbu/FVj1XxxwvpSPFo3RcoCEWg39rPp60gRE2L7CZa1cNc210dk5sLVK36H5UECr3qt pbgDdcOP4ovJG08cIFe+x94yyq+4eWV8DvFnJEbDoBtGrFfuHCSrDic0cvZbXIOmhy+3 XWyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777142571; x=1777747371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i6T7QXBLhmGguBHO1L+/WMwTbhQuI0+KzV9ksg4NtKw=; b=e9TNZXS1thYEvk9mJeriNxmdbsa25RvDJW3oYhK6C70XC5C7JaLQkomczv+3cc4drc EcPMh8qjl/CWobShLMyWfBflPf0BN2W9+hOTxvnO/engcZmOWmoaDHUGk0DxMe/6t+Fn G++FF6p/9/jsq1VoHQM2gaeNgFjL5YnJ/ArDeqXK5kXVDZSBTYiutGPwK9dOBgUPOHjW oZsOFgKbesF7pJ0bgitoZUgh4VJXWilFXuka0Hmu4BfR4MioAGqY9GfX7BQtl6puuEqz 84x1DE4uwzWF+ViLg0IWEqxi6saH1aE9zCKK9Jnblx0Bv8za/RJ1DJc73xBQxABZvLWx hkJg== X-Forwarded-Encrypted: i=1; AFNElJ8q5boO5IHVUA3YSlse0Ofi7u8u8xvAd6s9R54eBCapbTIGnUk9AIxStdAlNlSB24e0UBByQrXk48gp1QA=@vger.kernel.org X-Gm-Message-State: AOJu0YxV5cZGw7KKnuU7PMDHN24PcfSSLIjCgVN3ULL1YLijJdDa0/dp WdycYmBEcrsNxztc3PHomDApv9fR9KAhffiD6QtDexFd9g0PRu/tmtsi X-Gm-Gg: AeBDiet/d/5O6lwI4f2xkdQqE5jyZqKFgMWlf9QRVWU31Rs7jjuwRhlR0I3HdLv8I2W NyNhrWmjfkxFzwSLfcCO+YEmtel5tsP8Cdu1TjoTkqIwwpPm8HpdBBrpIh46Wg3+tKZzhGymQRz OD4UXKPpkHcZIBiM1uMiX2/Nln3P/qa5ulyzqR90u/l9Naz5461HLWOe0WSIQmtzOcrgoedOjJt C1i5y66qzGeoJuywE1ILCG4i0qvK8E4jM79plPaQG7yYlBjA/JBDy6sOrQ2tLXLkRSEb/WtO6oU 9P1Nq/dxFqObeHvn+oSNBNulRy/W7rYVQmStebGytP/wqNAsVLmxXZnScBVPGXeADCOuUa+zRWh D0I6kMnJgmw9jZ4EGVSfekYvdb5QnD/xdhdtkIinMkDHfgabuicxnQ3WX7EUzggkkP1zfn/BweU 7u6h5gAeS4UC9ssENEuRvG8FQn4MY= X-Received: by 2002:a05:6a20:2583:b0:39f:c9b1:52ce with SMTP id adf61e73a8af0-3a08d8fe2a9mr23390576637.8.1777142570922; Sat, 25 Apr 2026 11:42:50 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8ebba485sm33975874b3a.38.2026.04.25.11.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2026 11:42:50 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon , Hyunchul Lee Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, DaeMyung Kang Subject: [PATCH 1/2] ntfs: fix NULL dereference in ntfs_index_walk_down() Date: Sun, 26 Apr 2026 03:42:42 +0900 Message-ID: <20260425184243.116396-2-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260425184243.116396-1-charsyam@gmail.com> References: <20260425184243.116396-1-charsyam@gmail.com> 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_index_walk_down() allocates ictx->ib when descending from the root into an index allocation block. If that allocation fails, the old code still passes the NULL buffer to ntfs_ib_read(), which can write through it via ntfs_inode_attr_pread(). Allocate the index block into a temporary pointer and return -ENOMEM before changing the index context on allocation failure. Also propagate ERR_PTR() through ntfs_index_next() and ntfs_readdir() so walk-down allocation or index block read failures are not mistaken for normal index iteration inside the filesystem. ntfs_readdir() keeps the existing userspace-visible behavior of suppressing readdir errors after marking end_in_iterate; this change only prevents the walk-down failure path from dereferencing NULL internally. The failure was reproduced with failslab fail-nth injection on getdents64; the original module hits a NULL pointer dereference in memcpy_orig through ntfs_ib_read(), while the patched module reaches the same ntfs_index_walk_down() allocation failure without crashing. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Signed-off-by: DaeMyung Kang --- fs/ntfs/dir.c | 13 ++++++++++--- fs/ntfs/index.c | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c index bfa904d2ce66..20f5c7074bdd 100644 --- a/fs/ntfs/dir.c +++ b/fs/ntfs/dir.c @@ -911,8 +911,8 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor) if (next->flags & INDEX_ENTRY_NODE) { next = ntfs_index_walk_down(next, ictx); - if (!next) { - err = -EIO; + if (IS_ERR(next)) { + err = PTR_ERR(next); goto out; } } @@ -920,7 +920,14 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor) if (next && !(next->flags & INDEX_ENTRY_END)) goto nextdir; - while ((next = ntfs_index_next(next, ictx)) != NULL) { + while (1) { + next = ntfs_index_next(next, ictx); + if (IS_ERR(next)) { + err = PTR_ERR(next); + goto out; + } + if (!next) + break; nextdir: /* Check the consistency of an index entry */ if (ntfs_index_entry_inconsistent(ictx, vol, next, COLLATION_FILE_NAME, diff --git a/fs/ntfs/index.c b/fs/ntfs/index.c index 2080f3969137..f50082708bd1 100644 --- a/fs/ntfs/index.c +++ b/fs/ntfs/index.c @@ -1969,15 +1969,19 @@ int ntfs_index_remove(struct ntfs_inode *dir_ni, const void *key, const u32 keyl struct index_entry *ntfs_index_walk_down(struct index_entry *ie, struct ntfs_index_context *ictx) { struct index_entry *entry; + struct index_block *ib; s64 vcn; entry = ie; do { vcn = ntfs_ie_get_vcn(entry); if (ictx->is_in_root) { + ib = kvzalloc(ictx->block_size, GFP_NOFS); + if (!ib) + return ERR_PTR(-ENOMEM); /* down from level zero */ ictx->ir = NULL; - ictx->ib = kvzalloc(ictx->block_size, GFP_NOFS); + ictx->ib = ib; ictx->pindex = 1; ictx->is_in_root = false; } else { @@ -1991,8 +1995,8 @@ struct index_entry *ntfs_index_walk_down(struct index_entry *ie, struct ntfs_ind ictx->entry = ntfs_ie_get_first(&ictx->ib->index); entry = ictx->entry; } else - entry = NULL; - } while (entry && (entry->flags & INDEX_ENTRY_NODE)); + entry = ERR_PTR(-EIO); + } while (!IS_ERR_OR_NULL(entry) && (entry->flags & INDEX_ENTRY_NODE)); return entry; } @@ -2097,10 +2101,15 @@ struct index_entry *ntfs_index_next(struct index_entry *ie, struct ntfs_index_co /* walk down if it has a subnode */ if (flags & INDEX_ENTRY_NODE) { - if (!ictx->ia_ni) + if (!ictx->ia_ni) { ictx->ia_ni = ntfs_ia_open(ictx, ictx->idx_ni); + if (!ictx->ia_ni) + return ERR_PTR(-EIO); + } next = ntfs_index_walk_down(next, ictx); + if (IS_ERR(next)) + return next; } else { /* walk up it has no subnode, nor data */ -- 2.43.0