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 51E6B33B6C9 for ; Wed, 26 Aug 2026 04:44:36 +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=1787719477; cv=none; b=KDrktY8ujrsFVMZtvDZiUk5MA4GyP3AGdbuZIaDDz7LH/IF8FFwqRq1WtF+vBtdQ4NU7n1+ZWiGtDk0mVi3hc/dWgilkejx8qe1JzojOuyZCc2NppxGkUEYnD1tEHaPf30PEdanugClQWowsRr5Epg/QlKCyyUoUMQfKyyuFoEI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787719477; c=relaxed/simple; bh=WwCaBsH4oLqHXKummXL3cGn/RQ7bD/S39q7wytygq+M=; h=Message-ID:Date:From:To:Cc:Subject:MIME-Version:Content-Type: Content-Disposition; b=qx8+1pS2ZyFjc0dNoieDl6gTmrcTatH7X5CHX4wUUhrOHkDi/P59qtzPwFYeQ6ZDTK0U/ipJD+zK0/cveVutz/EGSP3Ds88FVPAjeLRWMgwLo0ivzW3qMePBFU36SFNhF3aQ62kxLxhrhwh/BOVIaSQ1eIMc/X1ZxH7QbuH1hNI= 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=T5LrsAX3; 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="T5LrsAX3" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2d6fe26ef1cso6609475ad.2 for ; Tue, 25 Aug 2026 21:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787719476; x=1788324276; 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=cqv4vSBtkWp4LVhCDMdBCum88ni/PanP/bbO0zmwvxg=; b=T5LrsAX3ajTL2MrMhoNF78nOvsikankbl4uF3TPk6jybv73np+A9UGKndcYDM3pg9V Edy4RHRCzBiKDG1c860sOjnihsEx6+M33tDy2XBgWxvQ2pZRgpg10P6FB3YidPIOQ10p +RlBuE0UXY+wtO/fdNKV6/Yz6OFmN0D1wiBrtMiPYZMcHSa6QAeXTOJ8ZIx2lLJmNEFz CbfVZ3gldOxOP+02rvxwVDcaTuS0wazgjR4eX1LyEZUMccvl3mo5UME/eeZdjcxLiwgG df1vB8mgU8PGD4GUdiJjO23IUAEFaADrIJ9A8wkygiXjEurK5xJgmhy0GiEkP9jiUX4s 8Gyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787719476; x=1788324276; 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=cqv4vSBtkWp4LVhCDMdBCum88ni/PanP/bbO0zmwvxg=; b=j+ckIz5cQqvKEt/FEvINwAfNngxiweDvtKHPbMb0+89ftnkJt7iaaHKKt+vPlQMYY/ z+yBx0E9cTBgxHQJWxZx/Egg/gZtmPAUIUfKP9DFwZ0Ct6mJS9dgM/jUxgwV5PxWYRao Hncw8yZrc3+8jvzuYEbyI+dusMDSWyyj4qHMfGR1yhnUnxYaQJViVC+lqkepj/1ywjcQ rE1rDbUOsASI0/Jl/0C1mmCI9JMd5zZZZloUTTUKUEtVxub1gSG/ptpZOrfao7EBh9rH ivoq478uvmTIAz88tAwcBPGGqlH04P1WchC16i3okviDurlONmi4OrjUD4Aul42yKyiP /f/A== X-Forwarded-Encrypted: i=1; AHgh+Rqq/MXqfXJGEUFPQK1Y7K2TzpJLz2pNbeocnd7hthThvNWKEus3T42gHW4p069qlmoNSzSA44o3i+D/438=@vger.kernel.org X-Gm-Message-State: AFuF++mdZGNvUU3U/nQk3DU+JtYGQYoI6JXYcOBJo4Bmrg4iCBrocikV gdcemdJwZi/73bPzGdhCXCaKDF5rcHHgblH/t+sQxxRqZ2D6Z7eRjg9/ X-Gm-Gg: AR+sD12q9X7YHs44nJIAnU/GvW7hSu4FZBBV40xrBtCXsr4z5rSOHSTUDAM1z9DOeES T9Tl6BHXsmPRVhhp/KVwWbLgKk89Bo9QteuKshBbwchSGkevq5pPz0rNVGriZSQkC5OTHX3yib2 X6FAnUQupLSIkyhXcTxzxiKoNi49zI/PJRE61XOpc8jxfO5YRWDPWrYlqZ1UKKFC3oZZv1WbD5U NLNt4W7VA2GTFAoT5Gpc+MKuS3OceCQrMfO6W15b+S51KfNFT7TY88BiKOIhgKBLcXK/uqlBRij LhYjUJqq+2vxCZoek7HDOcMNfNEOT6NJpg6q2hofIJgUZSl2Em+OOT2ML6Cw4uUq9WP92Vaoald PfUoFwjf36Sym1B2XfkCsPpCh51h5WUO6xHDSO94cgax4xEs89OhFBnp5gCVbNhMqmdPsnUmCjI HOMpAgayrdZbE8gqXnutVeFUvc8FIFV9ZaPuy/F0Q93UwmkQp5WnZ5Ahocordqkijz2X55VJsVT wc68pmFTx63CN6kUPyReNguIRNLGYTi83A8ldgeRFc90A== X-Received: by 2002:a17:902:d581:b0:2d1:134:b86e with SMTP id d9443c01a7336-2d707a0190cmr70840405ad.2.1787719468915; Tue, 25 Aug 2026 21:44:28 -0700 (PDT) Received: from localhost (75-172-73-38.tukw.qwest.net. [75.172.73.38]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d704c11ab7sm3821795ad.65.2026.08.25.21.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2026 21:44:28 -0700 (PDT) Message-ID: <6a8e6f2c.8c92e5db.197682.4689@mx.google.com> X-Google-Original-Message-ID: Date: Tue, 25 Aug 2026 21:44:24 -0700 From: Dennis Tighe To: Namjae Jeon , Hyunchul Lee Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] 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 --- Changes in v2: - Rewrite the loop guard to bound the entry offset without forming a pointer past the end of the buffer. Good call by Namjae Jeon. fs/ntfs/attrib.c | 4 ++-- fs/ntfs/super.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 990c3937a..7d0816de7 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -1737,8 +1737,8 @@ 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 < - vol->attrdef_size && ad->type; ++ad) { + for (ad = vol->attrdef; (u8 *)ad - (u8 *)vol->attrdef <= + vol->attrdef_size - (s32)sizeof(*ad) && ad->type; ++ad) { /* We have not found it yet, carry on searching. */ if (likely(le32_to_cpu(ad->type) < le32_to_cpu(type))) continue; 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)