From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 AAC5840148A for ; Fri, 8 May 2026 15:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254467; cv=none; b=kOcVEpGlsL6PeA5/Ip/2WZ+b9b3/ASAaK1SLJOrX56S+MXUGiAElC9gmCpubf8U2oyIUD21WEaQvy5Ur7IQ77d1NjRfvg0Ol2vw7TeAjEov1nPDn6LGyMT60yefQnD5Y7bxK7TNw1X23loFzQM5ognyIDPkdg2rnK9U6VM5FV5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778254467; c=relaxed/simple; bh=EnMncloGY38zNHH2IlD/jQ3ejkAbYcKTAZzgUACfn+I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qFXe9UXKzFYKkGW9Qq2v9e+P+mFiPbJ6ZSLYNLE897Y1ZFWPpq3nk62bt3X/KPogAHT/hPstWDS0pjx/SJpHluV44gMr4q1amHqQMhXi6kH0Xa4LVcgMllYgFpXv+Uy3fUTNKOb3o+AQq5yFbmnZykc/7uZUtQqz8IuFR19fL+8= 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=CdMQ7ayH; arc=none smtp.client-ip=209.85.214.171 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="CdMQ7ayH" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ad2b375e58so1272125ad.3 for ; Fri, 08 May 2026 08:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778254466; x=1778859266; 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=qq6X5xns9piV5RmWtTQbxwisodvE8nTQSWemS5y31r0=; b=CdMQ7ayHMTnQAmUROqKyBPffUNrNgKSvBnqLAyqa4jIarxFUGCa/pLMYnIB2MnJ71w Gkf1DQxysROzzMIT/uOvCVsrTLvUPNG5OcljeHVIjJx3QL1Y9YUA6YyZiPLM8yfAd2Oh Y0nRYz4ul/OxMTRfyEICzGt56SkZJz0VPa+Bs69LGEfugyzIUHkbFBPVh+NIcKCPioEs dH7sZNcFtLNQ3c17dTjlLU1We6qTSTcgyM9Jj0FUgsIx7A6A9GGLLgyWB6aHUfJdohKh 0QtDMR271Mu7Qo/0Iay2fYwewwJo/lxDTZ5thqA78/O7ac5X1GcaWzPfQmLyqOF+S5Uq sDMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778254466; x=1778859266; 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=qq6X5xns9piV5RmWtTQbxwisodvE8nTQSWemS5y31r0=; b=Frk8gOGfwXCfut5Msb9+bMvyv456nDvCMx7/qZWt0urydrcAccXU9wnzuSdy2tqMr+ iNkjqveokSvd/SOAeLERMvbnvBsKgy9KgBdcAIoKoB7VTe9BOcNCumo7pP+TGLSWqz11 tVyPtHLbpfx72K5lPhsSnDHJw/ZOY32Rtym16yRRj+YmV6dH/dJaT+Hpq2IjCp7a/AOb MjyZ0/88UjV4qT7n48VuWWltjlDD/C8qz79KhqOBTh81Tga7V8fWEQg+QS6CpJqHxM49 iw2lERvsbJOwiprICrDvsHbbsLIewuYKFTQGQQXpwwmmXh6Z5MbEjFoRsqtWtuaF5i2E wp2A== X-Forwarded-Encrypted: i=1; AFNElJ8scHMJhU0bN7cg2DYzBa4x0BGWZthjoSMZ6PHoeT/XGGKy6DdB4VMjI7ygK4nGt/lr9kA+5HHpWz06mP4=@vger.kernel.org X-Gm-Message-State: AOJu0YxLImkGc7NgbNCnAI1FUZRW+AzCIe1ZH/qWZIqdUPZNQW+jZMAG es8+dOw6kEgG72x4ZW8QaMA8t2Kq5vw5SY818kZ+HScrfPleDcemDpBn X-Gm-Gg: Acq92OEoUpc8h273+8Qutii1hLsEleEbIMRv9nRTru5cFtfdB+Rc1kKgVxElgM0u1DN xwHblOQwA5HgUgQPRQe8uEkj8fHRWQXck60gPDTm/gsWbz/k+evQA92Ia2kLgpzlvBimyqs2Pht I3bSwOD5ZmrSFkaoLTCirYRC52F4joQOeqyYRrFLt4HACNOI/Kojrog651sevo+D+rXqAx9aosK 42FDokyEELGFZGLlWZJoqUSiSNfwxiPW7vKiYbjb0v+k51f4wmxcjqz8us3NLzY4D5/Mpe5Sp5g 7rzcxukpxdwr6D1KIWkrksoSRPhSNHW/NzMOn9oNFM4+cVfYL45y10R+4x3Dz3vMaRoPJB7CuuT 8cV3v4vlmV2OP5Ajm0lYuw9R5oL3z5mny+BgMASyHXUETU8E5TIUu8lCQlyH6Z5O3FhkJZldOYD UZLZfYsIIsC0xb3h612pKENBVy8Rk= X-Received: by 2002:a17:903:1a2f:b0:2b9:42a3:6013 with SMTP id d9443c01a7336-2ba7afccfa5mr67838505ad.1.1778254465930; Fri, 08 May 2026 08:34:25 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d4094fsm26666365ad.19.2026.05.08.08.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 08:34:25 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon Cc: Hyunchul Lee , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] ntfs: validate attribute name bounds before returning it Date: Sat, 9 May 2026 00:34:10 +0900 Message-ID: <20260508153410.2624801-4-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260508153410.2624801-1-charsyam@gmail.com> References: <20260508153410.2624801-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_attr_find() validates a named attribute before comparing it with the requested name, but that check is currently after the AT_UNUSED handling. When callers enumerate attributes with AT_UNUSED, ntfs_attr_find() can return a malformed named attribute before checking whether name_offset and name_length stay within the attribute record. Some enumeration callers use the returned attribute name pointer directly. For example, one path passes (attr + name_offset, name_length) to ntfs_attr_iget(), where the name can later be copied according to name_length. A malformed on-disk name_offset/name_length pair should not be exposed to those callers. Move the existing name bounds validation before returning attributes during AT_UNUSED enumeration, and write it as an offset/remaining-size check so the subtraction cannot underflow. Extract the converted values into local variables (name_offset, attr_len, name_size) to make the intent explicit and avoid repeating the endian conversions inside the bounds check. This keeps matching attributes on the same checked path while also covering attribute enumeration. A small userspace ASAN model with attr length=32, name_offset=124 and name_length=8 reproduces a heap-buffer-overflow read in the old enumeration path. With this change the same malformed attribute is rejected before the name pointer is returned to the caller. Fixes: d3ad708fecaa ("ntfs: Initial commit") Signed-off-by: DaeMyung Kang --- fs/ntfs/attrib.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index 330127975b26..f51917b4a494 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -675,6 +675,9 @@ static int ntfs_attr_find(const __le32 type, const __le16 *name, __le16 *upcase = vol->upcase; u32 upcase_len = vol->upcase_len; unsigned int space; + u16 name_offset; + u32 attr_len; + u32 name_size; /* * Iterate over attributes in mft record starting at @ctx->attr, or the @@ -702,6 +705,20 @@ static int ntfs_attr_find(const __le32 type, const __le16 *name, return -ENOENT; if (unlikely(!a->length)) break; + if (a->name_length) { + name_offset = le16_to_cpu(a->name_offset); + attr_len = le32_to_cpu(a->length); + name_size = a->name_length * sizeof(__le16); + + if (name_offset > attr_len || + attr_len - name_offset < name_size) { + ntfs_error(vol->sb, + "Corrupt attribute name in MFT record %llu\n", + ctx->ntfs_ino->mft_no); + break; + } + } + if (type == AT_UNUSED) return 0; if (a->type != type) @@ -715,14 +732,6 @@ static int ntfs_attr_find(const __le32 type, const __le16 *name, if (a->name_length) return -ENOENT; } else { - if (a->name_length && ((le16_to_cpu(a->name_offset) + - a->name_length * sizeof(__le16)) > - le32_to_cpu(a->length))) { - ntfs_error(vol->sb, "Corrupt attribute name in MFT record %llu\n", - ctx->ntfs_ino->mft_no); - break; - } - if (!ntfs_are_names_equal(name, name_len, (__le16 *)((u8 *)a + le16_to_cpu(a->name_offset)), a->name_length, ic, upcase, upcase_len)) { -- 2.34.1