From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.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 67CFF28B4FA for ; Sun, 26 Apr 2026 04:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777176161; cv=none; b=PvUSyPE7cluPmZ0mls3TaFX83Q3JQUAwYiMhsUyKA6K/sdvz4cxAaxUZMOY4RBoVdfxYAzGTIR9c32znyfoZDIbRbp8EenXdgcztIE2b6uiKLLr2ZPZFHXFWAixgNB8UbD4fEjInHoMsNEaAlDLx8oOgvdgZETdOsQqaJiUwP7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777176161; c=relaxed/simple; bh=NOPrFI7RLm8u7swVuJKgRPinfyrR/M4hXTZLZJbep1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EKPM5JBmSxNXBFeJtEMbgfaNZ49g/eEHqlB1YZw1gYzA5cjuyyBVD7CKNTgUmWT1A1LapYr2Dk8OPCN8RjHnNEALHVLVR3s8h7Lq1PbLgqfbUFJML/DBQl8OAUqIRrtPH4V9o+JGWsG5nHtoISOcK6gwlfzUBrog23PpKQcR7Nc= 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=ZWymFA4D; arc=none smtp.client-ip=209.85.214.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="ZWymFA4D" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2b240d753ceso17375015ad.3 for ; Sat, 25 Apr 2026 21:02:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777176159; x=1777780959; 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=WzH7L75D2jOePwdGm5ThItXQqqZktxKIOM1J4bLi7lU=; b=ZWymFA4DPxhvGuMocQnpnGiaioct8X1Hmj68vq2WIjTOajGew3mzR85Zfx/4DWsuMd UpAcnAjVyFeL4O/nMizX1i8TNU8rjrKCtyFES4zyNugqdMIIWRkzDHQS0r3zTR5cN/Y5 mlu43hXFCDXN2NqcmIF5399w0vtlAclWYomSZXyUsuLko4v2gUJxdOAaJu3p5dZ0Gnej B8jKyAiUosgm1GpJeQ8HVDvTSsO0pN7PbPsfBqJL2uI50r2vOhrHlEA5YIWMbQjkRWG1 zzGiFmTopCRn6kZ0mgQ/sK1SNgnV2w2WtPrjFqt6+v+cZRZqkSXAHpVuFLf1Mzl52tbL 9pzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777176159; x=1777780959; 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=WzH7L75D2jOePwdGm5ThItXQqqZktxKIOM1J4bLi7lU=; b=T1vTITkDdW6dNKGJrISv3TOqMH0mB5G/+OZk3RQs0uZDjRIHf1te/dL+pwr6ZaLwdX u3iMBY8VeVYji3BUKSiVvtel/jcgDFJzODuur2rndLm7wrWj3qYNp00WEQOLxUzxr9Mp UiO2wkJ7Dj9tnGtfrpEumaL4qmsBWi+JV37kfxq49GZ06v2aYImDRfY9ZwPdmgTDuc5U /rhsTYjgbgp9UKyg0OkT/4zkVv0077TNpQWFFhJparILZW7I8d13RgJRtDyqurvj9jyI a3y5gPY3oHfBtYWn44Zvy47tzTImUpF2YNcrsHb4h6mAer8/cqDkYhqUUNuxGGLtLQJ6 J/hA== X-Forwarded-Encrypted: i=1; AFNElJ86aYbzsjBL6y3hdxiAj54NWoUu85pd8XBtWDOTMcg4IdHmwa0g+zBvZfMGnXtxHpO/TiLwFR6UHYU59vw=@vger.kernel.org X-Gm-Message-State: AOJu0YzvuzRgIanr3qxQN2lYfNEf+Yi5wgej1Px8fAPCslQmaIVASq+p vadtBU6ZSzpUg6VuLWor3vnzzNyGjoI6ILqpBFwNs2s4CXL1MSnK+G8b X-Gm-Gg: AeBDiesGnzY3qIQNMJ5y8+npcocAmj+lzY0M+KzrUrW+2qjZnqAUp5H9ADiQdD423Hi vL98V+gp0WPOEhQ6O9d6+kqdMVaWyqs3nodLlLutrW6KSN8gdWeK5HX4yswVuvjThDwXyWNVbRN 90A4RiVaKF0RvRt2bNzBc9oU8Q0WR+WybKkNhJP8Kwy2JZt103JmMDlUU/NCw56UpW6aGMOqc9k H22XDSBfC1L1CgqTuyLyf5vmtswK9bxk65pBCNBtQFHSEn/yVgkKQI6TmGipZLnhHXQj6B74MrW wSNRxd3RF8reQEKC8iNzbqebXFXwvX5QbSPDSSIVh2AXyAYhzJpfbphxwIB+vG7ZgKXhdIF+nkE 5nFfX3ujy874bA7GB7MEbFdy55UzdJYZma2HDfP180jZ+ZfzqTob/YFuppigIlvK6orTT8QLLtr J9UIekluyo1jru2rcMiHKxgkuDFLQ= X-Received: by 2002:a17:902:8696:b0:2b2:5c84:32ba with SMTP id d9443c01a7336-2b5f9ece9f3mr149677855ad.2.1777176158608; Sat, 25 Apr 2026 21:02:38 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b5fab0c17esm265149125ad.41.2026.04.25.21.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2026 21:02:38 -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 v2 1/2] ntfs: fix NULL dereference in ntfs_index_walk_down() Date: Sun, 26 Apr 2026 13:02:31 +0900 Message-ID: <411dcca8f8b760bf9744a2b590becaf3fb871d84.1777175371.git.charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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..a547bdcfa456 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(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