From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 3B987438493 for ; Fri, 21 Aug 2026 23:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787355683; cv=none; b=DgbVc0hZERzqdiHhq+3h/ZHCT5ZU9yodLxQXE0WKDIsbUn2X/tx7xm6Ik94IqLnXpTx8Ib0L4M2acBYZjDqSYCmBHZtxBVNtqmCVl5ZtbTogN01FEUdiW+o3U67kqUcUZuuda1fWsp49JCvyqr1EAW9AeUVOnotf8m1rG2FaAek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787355683; c=relaxed/simple; bh=73xzuFPs2JJWbAgU4+I+Qwk2eNu9ebrZ9MIDWhKyETQ=; h=Message-ID:Date:From:To:Cc:Subject:MIME-Version:Content-Type: Content-Disposition; b=WPznPhokLIj84xl5uA1lHtSXrB+Aw/I1cSZIe9JH4vUH7sS+VUV24Plwm+iov6AeXuZ9JNG6IN2aNcH3hVhJJrl2EuP4t9+sVTUYEWUaquK629c0Schsa/Y3wT4uIKFfJkEBLOHxAqI9XjKw2S460cJ2OCukxAxqp17HNBt7uDs= 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=GtYkrwnM; arc=none smtp.client-ip=209.85.214.179 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="GtYkrwnM" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2ccf2360620so14018985ad.3 for ; Fri, 21 Aug 2026 16:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787355681; x=1787960481; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:subject:cc:to:from :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BX/q/fzHpO9j+bEE1N60OvmhKcTiaQqPpyDyZokjCRA=; b=GtYkrwnMnu2k5VdK0T5aj+Z4fffGlm87rP96eW2nbZLa4tyUbtzxcW1YnL8GAwe+3c pgxX6P2zi42pGx04YpEynu6f/N3k0JEhPWmqmtrIWxQ5+iUzf5yVVk3Ef5qqhB3RJYDF gbDA3tvaBR0P0Jkaa1hDRanEeUh+fQfuT2RCFK7eMcwsXgROi/1ayrgIR6oLS+lxHT8z BtYrZKOUbRqvfDv9pa1UKJhBEFarsB3YsDDdgJSJt3vEF8ZjE8RSXFC5bHKeagHMQze9 5Wl3BtowP8FZjT2TFGoZ4dZQZ9JnMjLG+vANj8gualAv1eVxbsPiXB8dVhbUrujbSYeQ 0zbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787355681; x=1787960481; h=content-disposition:content-type:mime-version:subject:cc:to:from :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BX/q/fzHpO9j+bEE1N60OvmhKcTiaQqPpyDyZokjCRA=; b=ctnfwgB4pMwctZ4RiupJrPxl8HXPGSZmcR3kTgknOUBynGcizSMwKUWqDqF3gJhdt5 GDkLy4I9TALK1ko6VL+SdO5GCRPqJs+m1G9VI/dkjDN5Sm1jt5xTGyytxGyheARIiJtr OXXY1aJAg0/hy2sT3QAPQ925EEM7j0tJze59tILcWFu+dQKv6HpO6J3IG9fvxFOWf2uN fX8Ppb4wsa6AsgYtq0qYfY6u9BUoQsIWisKrLBXN3EQb5+B+6jGgIwtawy0Py8faJ/7W 1tQqdMgd1j42KzcR2Ws446hhHI+bquhhjXdmo/v2HwBoFQtdEmO+ocDmE9uNCgSht3Lw 7/TQ== X-Forwarded-Encrypted: i=1; AHgh+RrSTN8YrYZyeb/2pi6s/IaEmTzlmeIS7coHp0NbvsmqUHOxs4yTKc/3KoHgSbBXPuixciFq0lGoA+dlWMU=@vger.kernel.org X-Gm-Message-State: AFuF++mRWz/nCaRVafMX5nChAW03amqjJL52ZveSXuNINNji/QVjP/Nr qlvDnjIblRp+oTQNTludlMF3oZU/KHlo+3IMWnQJq0F1IQ/sukBkJnpc X-Gm-Gg: AR+sD11YIgQeB0h1NR9h+t2gvYa3IcBFjr7f75kyF1aDPyAjiIVP+iF44ZhrOic6por 0T7LDVFAfq6nn/d9/3oAYrKJSfggwxitQjzK8tYhOPXoEV4lKXj3ZtzXLYUsf/3I9PLvXZlQ7lw +aLkMsLv0IRdXCh5qmZBH9rAdT20Xl3QLz+ZlYXGdXP4oanJMWY/ht4tYSxFaPY2liGBSCjoBB0 9UMztud6jLQu3i5tUuN9VLHqrGSdzuD/d+0g6i1U0Z2WE9BZILdGaVugENZDOFS7OgyumBLEJYL VKELCy+LFAYThDz/QQrTUXMhNHXknp0MKlKe5k2IsfWfd+63y9yHZPVDiJ2sKOq/78XMg6ajtwX 8Q16M/MGghq4V1/eMwO8Zf94bYX4HqioQnYu3KDtXeWqHBwFBDIrna2J7ajtjR/EKEYBvbqRPhP iyRNQf8lSlJLeCRDIgRnitwr4Nu12G4IyEQTCRbYoPweOfW2gqTcjv/AaUznZEme7Fum36qwsct bV/lMfyZgvIViNSl43QYKufyuLd9ZmPnz+hhshFdq2fhg== X-Received: by 2002:a17:902:ec87:b0:2cf:9347:f445 with SMTP id d9443c01a7336-2d64b024c86mr170032115ad.10.1787355681276; Fri, 21 Aug 2026 16:41:21 -0700 (PDT) Received: from localhost (75-172-9-230.tukw.qwest.net. [75.172.9.230]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-327f90c0dd3sm311677eec.7.2026.08.21.16.41.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 16:41:20 -0700 (PDT) Message-ID: <6a88e220.1e1ac41d.2d530b.7cac@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 21 Aug 2026 16:41:10 -0700 From: Dennis Tighe To: Namjae Jeon , Hyunchul Lee Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ntfs: bound $AttrDef table walk to the loaded table size Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline ntfs_attr_find_in_attrdef() walks the in-memory $AttrDef table, but the loop condition bounds only the start of each entry, not the whole entry: for (ad = vol->attrdef; (u8 *)ad - (u8 *)vol->attrdef < vol->attrdef_size && ad->type; ++ad) struct attr_def is 160 bytes; the guard reads ad->type at offset 128 and the loop body reads further fields. vol->attrdef is kvzalloc(i_size), where i_size is the on-disk $AttrDef data size, checked in load_and_init_attrdef() only as 0 < i_size <= 0x7fffffff. A volume whose $AttrDef data size is smaller than one entry (e.g. 120 bytes) makes the read of ad->type run past the allocation. Creating a file reaches this through ntfs_attr_size_bounds_check() and reads out of bounds: BUG: KASAN: slab-out-of-bounds in ntfs_attr_find_in_attrdef+0x66/0xa0 Read of size 4 at addr ffff888005833280 by task init/1 ntfs_attr_find_in_attrdef ntfs_attr_size_bounds_check ntfs_attr_can_be_non_resident ntfs_attr_add Require the whole entry to lie within attrdef_size in the loop guard, and reject at mount a $AttrDef too small to hold one attr_def entry. Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Dennis Tighe --- Two parts in this change. 1/ The loop guard in ntfs_attr_find_in_attrdef() to fix the OOB access. 2/ A mount-time check in load_and_init_attrdef() that rejects a $AttrDef that can't hold an entry. This is a clearly corrupt table and is refused up front. A reproducer is available on request. fs/ntfs/attrib.c | 2 +- fs/ntfs/super.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 990c3937a..3f68a8ad1 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -1737,7 +1737,7 @@ static struct attr_def *ntfs_attr_find_in_attrdef(const struct ntfs_volume *vol, struct attr_def *ad; WARN_ON(!type); - for (ad = vol->attrdef; (u8 *)ad - (u8 *)vol->attrdef < + for (ad = vol->attrdef; (u8 *)(ad + 1) - (u8 *)vol->attrdef <= vol->attrdef_size && ad->type; ++ad) { /* We have not found it yet, carry on searching. */ if (likely(le32_to_cpu(ad->type) < le32_to_cpu(type))) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index cd8fa2c13..2fd7db672 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -1241,9 +1241,9 @@ static bool load_and_init_attrdef(struct ntfs_volume *vol) goto failed; } NInoSetSparseDisabled(NTFS_I(ino)); - /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ + /* FILE_AttrDef must hold at least one entry and fit inside 31 bits. */ i_size = i_size_read(ino); - if (i_size <= 0 || i_size > 0x7fffffff) + if (i_size < (s64)sizeof(struct attr_def) || i_size > 0x7fffffff) goto iput_failed; vol->attrdef = kvzalloc(i_size, GFP_NOFS); if (!vol->attrdef)