From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f176.google.com (mail-dy1-f176.google.com [74.125.82.176]) (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 7393D19C54E for ; Thu, 25 Jun 2026 04:01:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782360074; cv=none; b=EzQZR1tFIhVs/OwpJSDVBWJyS5nq1CL99NAlxxWR3FzbqL6pAk129TOauaRHUyxI86nw7yCjBF6ixJlLDn98AlvqPaH6mo5tWUKR5qkaYYzFBTblEsO8mFyKMHkk35IJm3o9TllQ7KH+P0KMEmJMqRALRxoXufDTrEW9lfhXnao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782360074; c=relaxed/simple; bh=8lgjXnHC+R8rd6QvlTlcWKmTiAZkvg82N1eDc85A4Os=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Y/WkGECpicD7nMti4mlzgFZUsNZDHydBPhUl4EnnwafosmgLM4zzT9Dt9M0Qaapx6yl1hUSQWzxNXiCr7yOHIUk/wAl+KVFTXIbvVtYvxqQ/8KgjSANOuaZ5ItpAOPSVJkopKXMr6bWGmka7pJHeP0wzqp3gmyRHYGl1NYcxW8g= 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=bNKFSrJR; arc=none smtp.client-ip=74.125.82.176 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="bNKFSrJR" Received: by mail-dy1-f176.google.com with SMTP id 5a478bee46e88-30c6c8d7503so4014709eec.0 for ; Wed, 24 Jun 2026 21:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782360071; x=1782964871; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rvXshwkE2Fi1VZ/yJhFDR9Y1t/o2CZ9mT65d7Nkx+jo=; b=bNKFSrJRQ2rqNNphtlvcdlI4nZm+CROrKjxhK+6JnsBIQxd25/CAvIo+MWWxru/YcU 0XR6EfnktjAl2IHYkL8J14v0EAPwfwhxpjtm3tn+2whAEbgsyiwxD/70ymkj//a8Lo8e vl/rG4OmwH4iCCaYrpVSLLi9U4JztK/IH5f6PkLpOhEy9aSKbSeyLWZTpf1iEo1muaIt kHWM/4DBAIARL9goaAYnPfubPTewU56+SUe8r1AVnY2bE/pCYiY6PlJt5RVUWOB/C+f7 NFvglyjfPPAokVX5/upXdZMy1PNPtqM8vCSdTEhY0+OOuFgmqPGKscLZv1bivIRYOcqn EKCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782360071; x=1782964871; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rvXshwkE2Fi1VZ/yJhFDR9Y1t/o2CZ9mT65d7Nkx+jo=; b=k5T46l0cV6NoeEfU4bYlR32lwF5zS9bHvXpP8zmZa3hbvhIKjDyfKHEJ2kD/ypcNMr eZuOs8AZ89f63GuYFIry8xclqmr2fjxnWvwipucxER6tthVQe57x6Fidf36SsRGj4Jmy 1SBTgr6jwelNB4u25qdJG1fI2f5qG1yHwXdOioH7nExTEEV+/LzGSF0hQ+IJTCyT6gUx WoTkdq3PSdkAmbO6p49Hd+cH7eziOXJkcLF0dxJPgLWj911V3yU1MHdoO6kVYzbUQkGj migdSK4BZcCeOwcLDlQLg2ECw/aTdhtisOX1BsNXhLA/71k2e4WUbNceCkbkpOPef0V0 qrOg== X-Gm-Message-State: AOJu0Yy47q2jPsf2wtBpmletJpEO+zuhX+sJN9r7mqKpo7uPEezvvVr1 v/h5xtkkqATjH5SEhLs9CAo2FgJyeyPDbj0qe63Xoa6bwH/yKes+boL5 X-Gm-Gg: AfdE7clJBHSuYn31+ed2Kz9xFaz9iXVKzNDlbeo4tj0qUiu87a0vMz111ndfElTPrbr scX6Hwp9IhpItmj+pihbE6VjX7Vpw3y3n0/VNbUWEHFgNSo5QlIalmhFfgxLc03f1qm3zkYi605 95f5//r57qPTvNX90699pzRFSIZ97r+qqu6w3n/3jqph3jNcI/qZsnJc2QRQ6MuhLovdCmx1Pli JTMwy4OMs+IEc36Y6/jtiU3VKyyWx5nDoOmHEl0kXgKxeMFPXb1c+kAPHJoSVZljKGaYUo7HzM4 dRM69hk4jALcFMOqvPrkxEXdRvDnHtd7z4RwN/hy7ZBbFSFBm5QPlES8Z1wTPG/wdPrF2SGTqxu u+X/5kDf3f22AUqKa1ZzJqhi5IqQTAwKQCsus1aIuJ+vM+DsNL8U3u0NxRR4iT8RvkOrCW2QZ3R /DDZy/HITBzt+2zzWFzWbSYenQ2ue/WR9chr5TCGtkgfOUjkPvStDUJBu8TA== X-Received: by 2002:a05:7300:1824:b0:2ea:5057:a304 with SMTP id 5a478bee46e88-30c84d9e27emr928042eec.2.1782360071356; Wed, 24 Jun 2026 21:01:11 -0700 (PDT) Received: from fx.tailc0aff1.ts.net ([206.206.192.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30c7c4c9dafsm4627340eec.1.2026.06.24.21.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 21:01:10 -0700 (PDT) From: Weiming Shi To: Konstantin Komarov , ntfs3@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Xiang Mei , Weiming Shi Subject: [PATCH] fs/ntfs3: validate ef->size covers the record's name and value Date: Wed, 24 Jun 2026 21:00:38 -0700 Message-ID: <20260625040036.996396-3-bestswngs@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When an EA record has a non-zero ef->size, ntfs_read_ea() only checks that the record fits in the remaining buffer (ea_size > bytes), not that ef->size is large enough to hold the record's own name_len + 1 + elength. A crafted image can pass validation with, e.g., ef->size = 24 but elength = 0xffff. ntfs_get_ea() then trusts elength and copies it out of the undersized record, reading past the kmalloc(info->size) allocation and leaking heap memory to userspace via getxattr(): BUG: KASAN: slab-out-of-bounds in ntfs_get_ea (fs/ntfs3/xattr.c:302) Read of size 65535 at addr ffff888100794550 by task exploit __asan_memcpy (mm/kasan/shadow.c:105) ntfs_get_ea (fs/ntfs3/xattr.c:302) ntfs_getxattr (fs/ntfs3/xattr.c:848) __vfs_getxattr (fs/xattr.c:441) vfs_getxattr (fs/xattr.c:474) do_getxattr (fs/xattr.c:800) path_getxattrat (fs/xattr.c:868) do_syscall_64 (arch/x86/entry/syscall_64.c:94) The buggy address is located 80 bytes inside of allocated 84-byte region in cache kmalloc-96 Compute the size the record needs and require ef->size to cover it. Fixes: 0e8235d28f3a ("fs/ntfs3: Check fields while reading") Reported-by: Xiang Mei Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Weiming Shi --- fs/ntfs3/xattr.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 9eeac0ab2b71..9097ded7d7dc 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -146,26 +146,29 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea, for (off = 0; off < size; off += ea_size) { const struct EA_FULL *ef = Add2Ptr(ea_p, off); u32 bytes = size - off; + size_t need; /* Check if we can use field ea->size. */ if (bytes < sizeof(ef->size)) goto out1; + /* Check if we can use fields ef->name_len and ef->elength. */ + if (bytes < offsetof(struct EA_FULL, name)) + goto out1; + + /* Size needed to hold this record's name and value. */ + need = struct_size(ef, name, + 1 + ef->name_len + le16_to_cpu(ef->elength)); + if (ef->size) { ea_size = le32_to_cpu(ef->size); - if (ea_size > bytes) + /* ef->size must fit the list and cover the record. */ + if (ea_size > bytes || ea_size < need) goto out1; continue; } - /* Check if we can use fields ef->name_len and ef->elength. */ - if (bytes < offsetof(struct EA_FULL, name)) - goto out1; - - ea_size = ALIGN(struct_size(ef, name, - 1 + ef->name_len + - le16_to_cpu(ef->elength)), - 4); + ea_size = ALIGN(need, 4); if (ea_size > bytes) goto out1; } -- 2.43.0