From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 97C2038239B for ; Sat, 9 May 2026 06:12:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778307176; cv=none; b=sXOL1IXw/Y74EOGl6jcQLRJv9VhE38Bll4x5XPYtd7MVVuT9s6JxmRjk7FcEIMrqu6ONE2SHM4C3IdiOdeXVQjHpaCIQnS0WDZGdMm0or3vNK2aLdyOcoPTjGUWKQ1V3vcwtOGL098Qct8tmNVxAy2Bki0/KR9sf1aJZn78PqrM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778307176; c=relaxed/simple; bh=0iDZOjepnYHKbwUNptbhXbh2gt66eTQ2spfZriwBAiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f6Vz5dLplIoplKlBQ/uYUWDjbd5sz5aE5OYo8mV+UftfmRz29cWryduGH7/QgyyKJ2CnTRYKYy9b48TPuO6Dx08mn6lxin5OOruk8yxz5Bkv8kNqVpLRzgP0qnV3pbOUrXNg2j1XFSrVNva5cfZiSEE+z0qGfoMe2pV8mKcGdec= 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=f5xz103r; arc=none smtp.client-ip=209.85.214.170 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="f5xz103r" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2ae3a007bd1so3929575ad.2 for ; Fri, 08 May 2026 23:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778307175; x=1778911975; 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=DFcSdFJcr0n6ORD4bjAB2j+Li1vLVOxo6IRxDvRQ+ZE=; b=f5xz103rkTMajunazNWYd48UvvJR6qjefoD7Z64k5lSdGgwiGyicnItwgMU6dvXCnd YAlDaEh5GoJozdDwpN0XrcOeXNXZy5CdbKV5VUvI8vo18N1lqNuxHzBBqxeGCue1hDvM K4C50pGZJvrFo40euOkKwA+R4sIe04krWRrqb9hpapfdhQM66RrYCP1l6eutaaqtSGow 5BzdXrF1gDkI+Fw3kiVmzYemTeU4kbEr58zVbSt46pyBsjBkPRguQNDZ4GbhwTDHF25w PtywGr3knIC10WaRYV08TpXclyXkD5O8LRgAsoTs24nTaXa8ULlp6tBjEj7KG7jZo6bi wVww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778307175; x=1778911975; 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=DFcSdFJcr0n6ORD4bjAB2j+Li1vLVOxo6IRxDvRQ+ZE=; b=iumLqCmH7YF4vHWp2IP1IqcFUuZjozgPFGqVMwEI4Sx41b/1s4KQ8YgQJRILfNt30S znjNxjIdtq90/xPiW5lvFPhxxCM42DZad/gY93P7EJtK83TZr8w7cdqKqDdlMtBq+7GI ySMvtkieGwoFsa/1V+DtptbkqQA8FVPTXd4eR6Y9J1BG0rXrTE6zQZIZCstgaUi3abT8 tJNlyG+biaEwnellwDWJU8f725WBDqbhSbatijybEF+/01vn3juflsMrVBjdOPQp+Gio 6HkGw3leGxm7cw6i2KHspU0DwzPyY8sp1ZMHyN9xehQwanPDSuo9mDZUhWzf1wI8GHhA Sjwg== X-Forwarded-Encrypted: i=1; AFNElJ9CJzyN1NfwcQooUuBRkwmEHkwlS8s3Zaqia92l0dY5Q8N/W2LUpZIx8crgaDXLX25zHqh8nT0E9JfCBwo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7N8vf/8tYPWwh/JNNM13nX/Ib3OADT/DC3konrTErhezhlfvI 7R86a59tNrFoY99S21GaVNdaXu64nds7mAUJACVcK9Z9aB71pwvddfnp1L/XJw== X-Gm-Gg: Acq92OE3nlrMErK287WZk3OY1TOZ27eGX4/sK9XDo8xfg2qHvoc7DkUfSDeK3HX8icD Zrv/PuNQAvCxY5sQnRIHONnhdOAa5wh7E8UQRZ5LH0w0PzCT6Z4HD1qzWKy1SAKRDF2x93STsp0 LKkATr1H2Alvw+yis5U/klwHIK8nF3YY74lnRGBbwi4LupgJ7V6rZtDtgF9tRPYREn1NENdUDPz s7aE4G/OKzQfkVDxV60TXQ0dVQ3nNdXXVWzATTxkDC2MrtbqaVonUZJPUNj+vsRmmwlRT7UPSiW 3FbgRoMetNtkIt6qKf6w92D86JUZOaKQlfqnLNnNYzYX7huEtLXENVWzqu3uB7CktAuCwXMQWMd opovyNDzM6M2TbtM6c006m+hn6O5eBrb2VyNA0uKEjXECO04QAVGPjPA/Q43BV77SDrjffDQxCv dcqAH+dVyIjW6O+Fyi6pxytrVtJpI= X-Received: by 2002:a05:6a20:160f:b0:3a1:6a7c:dba5 with SMTP id adf61e73a8af0-3aa5aa8a08bmr8415806637.6.1778307174930; Fri, 08 May 2026 23:12:54 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-839659487afsm13380429b3a.18.2026.05.08.23.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 23:12:54 -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 3/3] ntfs: validate attribute name bounds before returning it Date: Sat, 9 May 2026 15:12:37 +0900 Message-ID: <20260509061237.3233714-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: 1da177e4c3f4 ("Linux-2.6.12-rc2") 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 97b660eaa00c..1a0e1f9e0853 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c @@ -672,6 +672,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 @@ -699,6 +702,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) @@ -712,14 +729,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.43.0