From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793969168; b=mVQVYxq9HBDJHFbkgu4iMMh6pAfbCUfrxRXltJbMCLJ/XbxiuFOvaiKlkOXFuFRENGXL /akByME/XUo/TAmGi2J75RjS058ZuL+765YMcNIc7fgm9yUR4LZ9FMZP1XpCzumggKQQ/ eIUTdRACrvIVwH/9dF2faXvPQYXaflNXacVwngsSLwm9E55MNKhnUBJ/gtTpw8q9ULueY KsrtRbeOrL2Dpw1Pb54KELz2UJG0Tnjeuiyu8Hu7MtfCQwvN3L9ByDxdsGIms/49D6IX7 hqt3Sf2lrymn2LWUjaY06M8mhX3jFTlijn7zs3/ofc1i3jryztIr5JbW+ZCbPeG7MzA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793969168; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=v7NAa1AOfWrbfnp/EeNFL0KXkV/5wtZ7cjfajD4eOnk=; b=qDFZ2uDAw4uXiQydqJ6cT2gT4veUmrdzt2tONj3MrRtZEO+MoTcWd/3BvfT5xXH8R1cm 1MpsmO4/yUlKXDBfGLuZODi4fPrA0pfFKRMBbFp6IyvFmpE5ZN+JxsCflb+L5PpShHqUB /1fFKcvFUcQR5t3Eap2QyQyJcnhyELI5PvWhyR0+rjh5TZNW0sNlHFhWnHqxnoyMj0Y4q P5j2wifZ5FYeznC+ZcACHZyHkoXBDN7odqfG5EVfLIiQv1bFFHsExCTNF3T0kmeC1eK5d 45bhnJS/2T4uv+W9XD7WoPKs2hvfb/GIEh6h7s21wTt7DVWQjFYVnSN6w4/rL2HdDIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZKMrIy2t; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A4FE606A336 for ; Fri, 6 Nov 2026 12:46:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9A4FE606A336 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ZKMrIy2t Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-37071c0f42aso173862eec.0 for ; Fri, 06 Nov 2026 04:46:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793969167; x=1794573967; 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:content-type; bh=v7NAa1AOfWrbfnp/EeNFL0KXkV/5wtZ7cjfajD4eOnk=; b=ZKMrIy2tc7o01+01zW+B6xXvNtwD1DjIQVLY++gLeXaXPOpnhp7nOsCBvxXiWojgv+ 3HJmPEJpyHZARyLx+czkHayTQEvNs6rWHsm5SnG2M+t+2v0HEhp73a+71EOUB9EGSuR6 NmffL8RA+Wy9xrdBvjdecpWgYBSsD/ahJ79dsS3a35olzO5mvoPjx5VThkn4IU3x17hQ 1Xl0r9INRI6M7qYJ9UFfR5jyGgggFADXIHOnpRCuU0T29LGF3M7hq/L2+wguPA0HvqIt hVemwfnh9vy+XRjDaHkj6vXjSQpRC1W+eaSCmDkU3dcwf2Q+iq4/c0U75rPQQye7Yf52 +Mng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793969167; x=1794573967; 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:content-type; bh=v7NAa1AOfWrbfnp/EeNFL0KXkV/5wtZ7cjfajD4eOnk=; b=ozY4Y9jP++0bejURDdcBPn6grdSAosHIXdhu50yiEOUrRdhgr/2zSs3YB4zP3sZXGM 2ch87l5REtbhbK6rYkaCsevlElLVo1HMsphfJaXIj7AjtIf6Pex7KFSWi5g+221+AtsB 0ELlQOTVTdbU76xeLHU7FGPq9cOjX+yVkL7E+dg8FjMF4xLrwYH2TqE4sx9eB6LhMnYy EoG4O7NRp1KI3CaxmvMjhWWymEqm83Xlufm34jTzXilUJRlkoRXESRPR5CVNfw3NEdC6 mfO39agLwRXalFwEOarU50UU7GfsIuVzSTx+qP076XuEdaIdYUYDY1fSNLitkKXIfQu5 oTiA== X-Forwarded-Encrypted: i=1; AL+hErEJ5moz8Jv4Aaqaf1M8LGVR2h7EGV/utIMod3Ru7F9KmjjYbPsmXozSZjZHdULfy8+lAlp3Ct29TZdnoXs=@vger.kernel.org X-Gm-Message-State: APuU4Z/R8AVKMTzTUTBwOzBpQsoUke8TamQ6fM35gFBbdOs9iLvgoMPM TUhrcKD5iqyesm6f3TUH49dIJi2+6CbQzcDaLsHFtsx1Fm/FRwSKBhxp X-Gm-Gg: AYBFou0lIB1ysPRFkDrFG1zwvwq/XhwB84cm14sfvh1HLiWlddP1Xqc+Ik1yOc4ebSO tNapVXUUU2x589BCW6WQKuU6lUcDTUijgQc6a1oDAPEFwIGAxTqRdcUF7X/CcpdTve1x8kFXR6R SGl2qKeS33CNL1F64Fs8zmBYjQGTEk59um/AJFNewKgqbvQBNQajdAKaAXFgIwOOhb0T3uL/Orl OX5BNm7BwdLGiXLBB5Q4q0yWjqtFRYdrGEJgizexob6UcBuAIXf0YI6QV3pG0NjjPAAmb1d2QAK zQrzMw+nsmWeoMt2eu5v4nv9jGmjou2ag9X2FHbLM9QdvYWfeDyj3TGGmj8IKZ1SUchIysG1H94 WyWflZ2lWLe0QxJA6kvIGFPCbF8Q28j2qW1jnf4HTSXHo/W7R/iR9ZGGrjEHpqLbDlD82wY8nDE 9RWfdBE1zs2yJ401k1y5aL91+upNJOjZ35SMnQCMw40n39NkDmyC15g595qTwPWCC9h2BMu6dVn /p3V0qwuzmU2ujshCWU6YeJWvrlPc1qmokYHBCw0Ib77yuhR+eWh7m11rFdzMXCkbiJCPfDPQUg /JYH8MAeVbPprl/5npS3D+R66jeHBFwM2aSa6BNm103ToZ75eM3X/rW4tqYiwaeruw== X-Received: by 2002:a05:7301:9a81:b0:369:38e3:5363 with SMTP id 5a478bee46e88-36f7494cfb5mr3376030eec.7.1793969166328; Fri, 06 Nov 2026 04:46:06 -0800 (PST) Received: from anon-laptop ([103.187.196.159]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36fa651eccdsm6802331eec.1.2026.11.06.04.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 04:46:05 -0800 (PST) From: Wahid Khan To: Namjae Jeon , Hyunchul Lee Cc: ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Wahid Khan , stable@vger.kernel.org Subject: [PATCH v2 1/3] ntfs: do not read an index block outside $INDEX_ALLOCATION Date: Fri, 6 Nov 2026 18:15:51 +0530 Message-ID: <20261106124553.2617026-2-wahidzk0091@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261106124553.2617026-1-wahidzk0091@gmail.com> References: <20261106124553.2617026-1-wahidzk0091@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A directory whose $INDEX_ROOT has a child node but whose $INDEX_ALLOCATION is missing or damaged gets an empty index inode from ntfs_read_locked_index_inode(): size 0 and not non-resident. ntfs_lookup_inode_by_name() still follows the child node and reads a folio from that inode while it holds the mft record lock of the directory. Since the resident iomap read started to take base_ni->mrec_lock, that read waits for a lock the caller already holds: INFO: task init:1 is blocked on a mutex likely owned by task init:1. __mutex_lock __ntfs_read_iomap_begin ntfs_read_iomap_next iomap_read_folio ntfs_read_folio ntfs_lookup_inode_by_name ntfs_lookup The task never returns, and neither does anything else that needs the directory's mft record. It takes one corrupted byte on an image from mkntfs: change the first byte of the type of the $INDEX_ALLOCATION attribute header of a directory with index blocks from 0xa0 to 0x00. The first lookup in that directory hangs. Check that the index inode is non-resident and that the vcn lies inside it before every index block read, and fail with -EIO otherwise. This also rejects a negative vcn, which was only checked on later descents. Fixes: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock") Cc: stable@vger.kernel.org # v7.3+ Signed-off-by: Wahid Khan --- fs/ntfs/dir.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c index fce10baa2..9fb5bb3d3 100644 --- a/fs/ntfs/dir.c +++ b/fs/ntfs/dir.c @@ -308,6 +308,20 @@ u64 ntfs_lookup_inode_by_name(struct ntfs_inode *dir_n= i, const __le16 *uname, =20 ia_mapping =3D ia_vi->i_mapping; descend_into_child_node: + /* + * The child node has to be inside $INDEX_ALLOCATION. A directory that + * lacks the attribute gets an empty index inode that is not + * non-resident, and reading a folio from it locks the mft record that + * is already locked here. + */ + if (!NInoNonResident(NTFS_I(ia_vi)) || vcn < 0 || + (u64)vcn >=3D (u64)i_size_read(ia_vi) >> dir_ni->itype.index.vcn_size= _bits) { + ntfs_error(sb, + "Child node vcn %lld is outside $INDEX_ALLOCATION in directory inode 0x= %llx.", + vcn, dir_ni->mft_no); + err =3D -EIO; + goto err_out; + } /* * Convert vcn to index into the index allocation attribute in units * of PAGE_SIZE and map the page cache page, reading it from --=20 2.53.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793969171; b=XZvvbYcK3y0pOL5+ehrPpFdUZ0ZH8+/ReNeB2hMTEC6/UQAXpevmjY0rG4SIcW7LkGCW sCH126BpPQx+MNNJnjhzx8FliqqtmGT0m3oEnfXlCB+h76SDcLw30J8dSoWBB60moCQaX q5lIu7laI36Ocre9xwAfB5eQKpD2O+CmyD+9uOWWJQhGIdfZCA0asx3RhthIwhDyVYnp1 s7ADODqQCd8NrOhX+7Pc5+EU9ttbx6W35jk12l4H++vIs0o86PibvMNe9/M1hynQdba+A /jxPpj31KKPWMFQc8oUcXRCFEXjk0PSjcedfiZMitk3cZk2JJggQGr75ypJfi/450NQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793969171; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=JNftfiQYVNrVOWb9CroEjxPZDzjxD7afgRSnyOU7AVE=; b=gnxX37LI5OH5toxvzzaVP/B9U7Aj4zM8PE6wJ1/9oCy9N4HjHfJhYuWZ9rqM1NEu4rj1 qn3ngUOKKiiUTJKElOqOwJumkMCZ7b1Id6c7dB6ndAtURtT8sEnPqQg1DWolHuoXmaa00 3WTz9ocUwArYwZwHUur4AAjjaEvWit4SWWcGWFjkJoEZjoeVF7jIBIw8IQgCo0kaeY3+1 1wuVUr5A4IRo/XnlyyHJw8tdRxkWMgGKgyassXG+9VknlkCyuaes+KR70fdSVSu+y3k2R Y0a7SmFsaLOWLdU+6YXPEbfE7b4q9nGXNTARPWpNloJpGL1niYM+TO9E6qyaUs57I9g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KoMcPaAb; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C22F0606A33C for ; Fri, 6 Nov 2026 12:46:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C22F0606A33C 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=KoMcPaAb Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-37000e7234bso1207248eec.1 for ; Fri, 06 Nov 2026 04:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793969170; x=1794573970; 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:content-type; bh=JNftfiQYVNrVOWb9CroEjxPZDzjxD7afgRSnyOU7AVE=; b=KoMcPaAbexCKQpS7dN1txsf8/njskB012eFKiEQpGj3gqecgq5PAIUgUmDia8cSqL8 C44cb4NnJTdZiSTKt86qJpLxbqUYOV2w792sEsC387W9Ul6vqmayQFme0IZBoDxko10q JYhZgKSPsTDKKGJAVix5JGhGgWEjJgx+w3EcwMp6kwk1P2tLWEDOQiH1R+6apRrPM+IA DQs4tGERGDkTrBWnofrRQqFNOfma+zcPpmeVNQjJ0uSXNzIhMWw3uvV/Ag+s4rRg6Zrl 8lTllhb2tSd17+vt4BT/bVvwdYNUkQSgkx8wiJDkB68wS0xTz8fqAmu0Cd0CgGIrL0Ap f8cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793969170; x=1794573970; 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:content-type; bh=JNftfiQYVNrVOWb9CroEjxPZDzjxD7afgRSnyOU7AVE=; b=e4Acj84x4xU8rFOrikfr7zK2ewyNH2nEmGGIID5/P0gBsCV05Zw5DWd/2SRXxCk3q/ zh2wp8EwYhN7wkpGigUNUIbAjXzCYl5YTrSEOyLDynuj7j/ZfjhaZvg1eyAHiUVr/klu qIRoTpipvwp2Dne+oX7QzeT/BQFrhwxzFfMcO8Z//hPYw3ZoqufRRcdd2COC0iL+hFs2 mQ/2kmvFDHaWowiB35+haQweYymXzGjjPV7myn6tYW8/8MfwjtjUzS2F/tbJ5B1IBBCY KP6TgCipC8EkHFdAcP55NP+SX2fRCN32/5jsH8fP2klw24lOCut37a6XprL4pAa8Xdm7 9MBQ== X-Forwarded-Encrypted: i=1; AL+hErHVwnSQBsvATywFqd/jF7jx6lUpfoZVMchl9MjAvjg8a0f3iQoxXd5gD5KznFHs24pDSpF4g1C30wyLO08=@vger.kernel.org X-Gm-Message-State: APuU4Z82dNTx8r6cttlRi4xofeJw2PrhE1biRobdVT4EkdzF19uXdXX0 LCk0CeUkmcozEMmK+S7Gr9hyF22CMJyXP4MXVw6G1ZDi6DoTAjuy0eotEtP+zK/wZSEZaw== X-Gm-Gg: AYBFou36/51DozX4WaQdXL6EupsPo37tTJ6fMv0JXJhd3syvciPI4aDmNqSW/Hatljc xn77ChhtModVviwmUhzCrhfzLBMlc8IvF/60uA7ZPML+s33hoyCPnYmTwdWmMArrue+A64yKTKn weYK7icMRuQm/ebmNnDyqOv4fj4jeLF3fhVPchPL5QPTlGMla0GfFW21tEWBAMKGv5gIs7ol1Oz WFy6shFtZDwCvy5x1rLi87uuIymZQCPaaXhqWkAnALBC5wXT07MGfUvi95wG6C49c3oi3jWRSup +i1H4Ur8bX5DJs82rTd/83rJr3Ujq1tehv1DaY5vv3B5X33yHylsb/hIMFI8vgFLynk9Mru7wg9 9BU3ot9ktcY21nbaOrZc1qPZPUdkQXMn3XXMniVur8T5eEey7RcrvAAPkujoeLXlvMVHg0oWL0r vMOCe6qlauYGgr36dACcf2t0c+XLJsMZfHfEiEinFd21fawTs2USFb6Cs0Levqoi+a9y0MZnfvz myYZFvbAEcbdkSql02s9j3A7I4C92RDSIyEGrBiYVFfiJ1IECQi4/OHTZR6JoGWI6LnlUIHWUqR Qkf1Px1hqSCF9GRJkmEL42cUj6BFWrJ1ced8oll4NJ+CcsgRbjhdFHtj+u0tF7DCew== X-Received: by 2002:a05:7300:10c:b0:369:f97f:72c1 with SMTP id 5a478bee46e88-36f771025d2mr3480312eec.36.1793969169592; Fri, 06 Nov 2026 04:46:09 -0800 (PST) Received: from anon-laptop ([103.187.196.159]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36fa651eccdsm6802331eec.1.2026.11.06.04.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 04:46:09 -0800 (PST) From: Wahid Khan To: Namjae Jeon , Hyunchul Lee Cc: ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Wahid Khan , stable@vger.kernel.org Subject: [PATCH v2 2/3] ntfs: open the index allocation before reading or writing an index block Date: Fri, 6 Nov 2026 18:15:52 +0530 Message-ID: <20261106124553.2617026-3-wahidzk0091@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261106124553.2617026-1-wahidzk0091@gmail.com> References: <20261106124553.2617026-1-wahidzk0091@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ntfs_ib_write() and ntfs_ib_read() use icx->ia_ni without checking it. ntfs_ir_reparent() only opens the index allocation through ntfs_ia_add() when the root is a small index. For a root that is already marked as a large index it calls ntfs_ib_write() directly. The lookup does not open the index allocation either when it ends in the root. If the last entry of the root has no child node, ia_ni is still NULL when the root has to be moved into an index block, and the write dereferences it: Oops: general protection fault, KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f] RIP: 0010:ntfs_inode_attr_pwrite+0x52/0x1600 ntfs_ir_make_space ntfs_ie_add ntfs_index_add_filename __ntfs_link ntfs_link vfs_link A single byte of an image from mkntfs is enough. In a directory that has one empty index block, clear INDEX_ENTRY_NODE (flags 3 -> 2) of the last entry of the $INDEX_ROOT and link() a file into the directory. Commit 9365c4a1357e ("ntfs: fix NULL dereference on index allocation open f= ailure") covers the case where ntfs_ia_open() fails in the lookup. Here it was never tried. Open the index allocation on demand in both helpers and fail with -EIO if that does not work. ntfs_ia_open() also succeeds for a directory that has no $INDEX_ALLOCATION attribute. The inode it returns is then an empty resident stub that does not describe an index allocation, so reject that case too. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Wahid Khan --- fs/ntfs/index.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/ntfs/index.c b/fs/ntfs/index.c index 322cb371d..74716f916 100644 --- a/fs/ntfs/index.c +++ b/fs/ntfs/index.c @@ -99,12 +99,30 @@ static s64 ntfs_ib_pos_to_vcn(struct ntfs_index_context= *icx, s64 pos) return pos >> icx->vcn_size_bits; } =20 +/* Open the index allocation inode if no earlier step of the operation did= . */ +static int ntfs_icx_ia_ensure(struct ntfs_index_context *icx) +{ + if (!icx->ia_ni) { + icx->ia_ni =3D ntfs_ia_open(icx, icx->idx_ni); + if (!icx->ia_ni) + return -EIO; + } + /* Without $INDEX_ALLOCATION the index inode is an empty resident stub. */ + if (!NInoNonResident(icx->ia_ni)) + return -EIO; + return 0; +} + static int ntfs_ib_write(struct ntfs_index_context *icx, struct index_bloc= k *ib) { s64 ret, vcn =3D le64_to_cpu(ib->index_block_vcn); =20 ntfs_debug("vcn: %lld\n", vcn); =20 + ret =3D ntfs_icx_ia_ensure(icx); + if (ret) + return ret; + ret =3D pre_write_mst_fixup((struct ntfs_record *)ib, icx->block_size); if (ret) return -EIO; @@ -805,6 +823,10 @@ static int ntfs_ib_read(struct ntfs_index_context *icx= , s64 vcn, struct index_bl =20 ntfs_debug("vcn: %lld\n", vcn); =20 + ret =3D ntfs_icx_ia_ensure(icx); + if (ret) + return ret; + pos =3D ntfs_ib_vcn_to_pos(icx, vcn); =20 ret =3D ntfs_inode_attr_pread(VFS_I(icx->ia_ni), pos, icx->block_size, (u= 8 *)dst); --=20 2.53.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793969174; b=nJKs0LmPKSOjsUrGiOEppzKblLKg9WUmF7kZZ+SZ68lA7RPMfz10EPquLD++TPWC1a1Z zmyGPNZauRedHWtOkm5Fz3l/ffQsowwZlFjC9Q7BfSC+kgWXcsM5qC2oWNxVkz3jMktD+ aloas7sbYUprBZ0aZV3FeCBSA9d2oxvA9ws1QLATAGMz8pFwOzWFXy4FZf+Ynj+yiSyKq J6JXxNfVDoLoMRPhznwcpo438fkH/yxRb4Srb70Lk787AcPFsy7CelY64UT2zFZ3Iawq4 C7pm9AqVN3XW/okg7wYI3YuZj/Wtwn/4yY9zqZY26DX9SWxVW91jO48zaDBarcb3NoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793969174; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=to5ZYe36a7Xl7ja/Fvmb8moZkHvXAEhFxAyr4iAV0io=; b=Fenp2BcuFzYPNik5QDCRJN6yzmH3ePwPlpq0Rj5L+9O+1J8Y5wuKO80KBCSh/3AzPUmR Ghmhkpu2IzjDga4TZkYfGDh1EJpz5t145fVJ+n5DqVQVLTykn7gUfwLhnUgXKBtaU518l GEG8anqC4YQfI10IfkhPU/IfPMgPSKnTEg+UsZ0qjzjvQ/8MTWEBaPVjSGo532BxCgHra 7CSe5Xe25S68dJbVLOTMVTzQajK5rCFDlsNMPPn45f3lrK926GMtp66RbRkbNVjXG55MF GZUaWv/NlrAUMGucmn9cBli1SVhMYRtj/AkTyeCMlWA5OeSrBRx+/TnvGJQHkB0EqRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OtI1fWwO; arc=none smtp.remote-ip=74.125.82.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38EB2606D822 for ; Fri, 6 Nov 2026 12:46:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38EB2606D822 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=OtI1fWwO Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-3700ed8dbe3so480951eec.0 for ; Fri, 06 Nov 2026 04:46:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793969173; x=1794573973; 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:content-type; bh=to5ZYe36a7Xl7ja/Fvmb8moZkHvXAEhFxAyr4iAV0io=; b=OtI1fWwOBO1UK/xBVF361zKX5pNVC4vlOBT8ozO8B7jwOHG6ejWk0PFQSiaUO6goh1 lqLolKuP/ZuEkvIasGgWRMlSwGUPYOU2TU7EAJBPDqdrcmOlq6Gv/y/kjwPBFsoMk+8g HLztc8XnbL13xQXeFLXuyOuZZ5+5QTP0FgLCdYiULs/twiNDdBYStOmozF7hKRfh+PhI pChKKxj9DXmURGSQHP92wwb7befLbFwo6kZn7sfpYZ7RGTmsMd9807/pXqyYsbZskAzG GpLDAKkvHnHuHMAStFBet+Rz5WhPr2n+9S1T1PRdarZ/DSu3iqlO8geZpC5DtSEVHydB xitg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793969173; x=1794573973; 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:content-type; bh=to5ZYe36a7Xl7ja/Fvmb8moZkHvXAEhFxAyr4iAV0io=; b=1OGJMeIiq6fXyBIJzHfcD7bvHFpfK+mvoDMaOHyjTXKwinoKpYrPzQ3EGQalzpmxQl z5TcS6N0mRQakGLlTsCUtBsOUHamxHtMt4TYHRLGTGqRRvzCBMfNAbNvEUGJG1r+zO71 rhxQNFGT8lY+gIW2PuFskfPEx1XacaQiz4FA5zQPd+r0X1oKFeEIV/zr9BmhEFY0Y+1M hMpocZSRwo946INw1bWZb07sm+LOZcEOu22tgTTJdY9bqP0rs3/XXVCiG+rU8IFC9DXG d0Ke+OpGfjE9KO2u9oh8umrA0DgIjwQ7IbrFFnP8LD+bqygcY1Z4aHZZCxm4EXizjpIq yxWg== X-Forwarded-Encrypted: i=1; AL+hErFpAPxrXIx0sxlkKqwoSHHdgkUszMNmOk1ImpeJMc66IH/epyxOzSEiHcp410X9Jum7SR4C06nzU8wgnyw=@vger.kernel.org X-Gm-Message-State: APuU4Z92JrrxJ8kUcj7iGXwhajrjsYU4Fksck02wbnhryFNKJ1sTp6Qa mDjIA9NiU3PFP6rbxLU4LTA6ggQp5Kg2x6FHdzgEaCPnShoZGc3Ke8pe X-Gm-Gg: AYBFou17s6Fh5eg8xyAsb03803W1Jx3K72dBgB0z0iQTAbA0N8RbFmLL4YJueVFXdbo J7NFqycyPa+RXFRWBzpNUxWHcXRlf2u7xEGFRH3uGVBPyKB2/w4jhH6eavKneZN8nFFaesQ7f4K 0JOGznak71u5U11L4SPvlnx9HAi0Wrv4mJkVSw06beYbQjB5L33/YuvMlNdBAMaevrdCW6J5Et0 AHeyzRmRRgrd/5rn+9S4UjnWGpAjQjyaW77vr/T1TDOkZJLdAOkcjGqw1ro7UOiCblqU7QHBEgp 05LN9zD+xXy0A+Ky4gaKlStBZ8WvsaLc+ihyZeDKaNkyrMRvub8Epb8NpoOXuTs8k97pO/xr0oh +NRiLn0SIf7EWMZmPI7Lg5zqBGPV8GFNm85WIE7ymTqRqzPIQ/KRgvHFV36CUt/h+zbFo9g+anS 0Am1ZXV6uEGcs1WH4k+AZYIRqR1OF7x4G5Of+Lbfi5w197wWDRwoipcuQEclXJraGfqLE8iAqb2 2HsyVe9TpgWENZAGNhTbhKORz/5Sah51ixSvcaQ5H++4RS6XbqUKx/iDwjEJDsntqTW6JfqcarH qnH3OYxVrKuppmaFeXpFlOSVC0D+mkXmcCImKNuJj8Vj26Gp3um+CcIdWYJP68txRQ== X-Received: by 2002:a05:7301:424a:b0:36c:9afe:fcd8 with SMTP id 5a478bee46e88-36f772f9061mr3192845eec.30.1793969172763; Fri, 06 Nov 2026 04:46:12 -0800 (PST) Received: from anon-laptop ([103.187.196.159]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36fa651eccdsm6802331eec.1.2026.11.06.04.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 04:46:12 -0800 (PST) From: Wahid Khan To: Namjae Jeon , Hyunchul Lee Cc: ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Wahid Khan , stable@vger.kernel.org Subject: [PATCH v2 3/3] ntfs: do not convert a named $DATA stream when making room in a record Date: Fri, 6 Nov 2026 18:15:53 +0530 Message-ID: <20261106124553.2617026-4-wahidzk0091@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261106124553.2617026-1-wahidzk0091@gmail.com> References: <20261106124553.2617026-1-wahidzk0091@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When an attribute has to grow and the mft record is full, ntfs_resident_attr_resize() walks the other resident attributes and converts them to non-resident ones. For $DATA it always opens the unnamed data inode of the base inode, even if the attribute found is a named stream: tvi =3D ntfs_iget(sb, base_ni->mft_no); ntfs_attr_make_non_resident(NTFS_I(tvi), value_len); value_len is the length of the stream, so it does not match the attribute that ntfs_attr_make_non_resident() looks up for the unnamed inode, and the WARN_ON() on entry fires: WARNING: fs/ntfs/attrib.c:2115 at ntfs_attr_make_non_resident ntfs_resident_attr_resize ntfs_attr_expand_locked ntfs_expand_for_write ntfs_file_write_iter vfs_write With debug output the values were attr_size 13 (unnamed $DATA) and data_size 550 (named stream) for the same mft record. It does not need a damaged volume. A file with an alternate data stream whose record has no room left is enough. The fuzzer found it through a single changed byte in a file name of an image from mkntfs, which made a write grow a resident attribute in such a record. Opening the stream by name instead would convert it with only the mft record lock held. Its folio would be locked under that lock, while the read path takes the folio lock first and the mft record lock inside ntfs_read_iomap_begin_resident(). Streams are not converted from this loop, which only tries to make room, so skip them. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Wahid Khan --- fs/ntfs/attrib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index ce7c1b524..800e53df5 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -4932,6 +4932,12 @@ static int ntfs_resident_attr_resize(struct ntfs_ino= de *attr_ni, const s64 newsi continue; if (a->type =3D=3D AT_DATA && !value_len) continue; + /* + * Named streams have inodes of their own and are not converted + * from here. + */ + if (a->type =3D=3D AT_DATA && a->name_length) + continue; =20 if (a->type =3D=3D AT_DATA) tvi =3D ntfs_iget(sb, base_ni->mft_no); --=20 2.53.0