From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341923; b=KD5fZUjwK74pKChwrNwfrMUnWh/vK3KmNtfopUBZOWRKl1rc0ZAZ0S/R8Mh/b68iUdhi PVOMHV9EkqfnrEmVMIQdHw6+5KmNuAjx+AvMtTYQsHD8jVlJmknvOUv/rhdxlC54tu+mB SlBq/53qLH3rnxcf5E8XgtNYyz5XMvbfyRft7JPwZlTFcGUoVcacBukTC6sqDwDDF+hIw oeo1xkcCkLpRE/BtOPhURiktI9KYKpSvqw3ywIbIF1pvqSFBhaJFCMeud3HXRX0s45OFm 1VSYahWKMAr6Ux2IjT0ZwIzR8bhkVazJNmXYPF305magebxs8rZjG4xh80TuppnmRRA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341923; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:Autocrypt: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=oEcHEPQ4IQQPK44ByK5FmfyCJcDo+jAu4fGVdQgFBo0=; b=YoralH0KhhW9mmyXIYMowoRaYTOYXaz1W/tnsL5AXBvTHkHfBHcIguWRZ9NczJFsXwsU UvI69NIzu5rvuzhHAK5gUkVsmemTT2TkqP31viy5uOKjQ+XcN9OOqkDpmZGuYx39cqnCI 8iLG+n0AXILAH1cv7FfmWBoeeDaKeJCqOR1634LHWVIk9XXzlGo2DuYiEyYht5wH6RNMf 7EUKDKkCR/8OED8ftaaLKLoGnLgpX/NAZvqna6nlAAsdft8CARoKUV5G98ZQAD2iTA14g PZk7+2ritymnIDk9WgtJIbQNJAomIL4c0vCCko+hCw7KWElJoAByPDp54MdHUbsltHg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=dubeyko.com; spf=pass smtp.mailfrom=dubeyko.com; dkim=pass header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=OqtIbqTq; arc=none smtp.remote-ip=209.85.128.178 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E8EA606A322 for ; Thu, 3 Dec 2026 23:52:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6E8EA606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dubeyko.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dubeyko-com.20260707.gappssmtp.com header.i=@dubeyko-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=OqtIbqTq Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-8b0d126f631so3118617b3.2 for ; Thu, 03 Dec 2026 15:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796341921; x=1796946721; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :from:to:cc:subject:date:message-id:reply-to:content-type; bh=oEcHEPQ4IQQPK44ByK5FmfyCJcDo+jAu4fGVdQgFBo0=; b=OqtIbqTq9cWNvmFuaT/vzx08W4iWRMiw2iR1MG6LwN9hrngZyiJDj3OBZVHPbdwhW6 ic9KSyE4p+BtmnBqFytE7cKcUPVoiFXd8fxfSjMOx7yhAzPzHaGzGe4vyeZxMoy7ICWs R+wbVSGK4gRE1F9iVFwH3Mh17Kzgf6XFt0uM2Q7Z23H/veqeMYxTvU5EmIV+Fwb2V4jT eP9uP4pC4X+DFeBNEPG3Js5xQ2rpiiArqvbd1cLXAOAKkkPKDBIakKhu6ZynHPTsD/1g QrQ5aii8EfGFrcEfJQIbUvK3HWvTiZoTBAJLqCPpE1O2JYOpbnWDv9gZid0647lnx3QR POjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796341921; x=1796946721; h=mime-version:user-agent:content-transfer-encoding:content-type :autocrypt:references:in-reply-to:date:cc:to:from:subject:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=oEcHEPQ4IQQPK44ByK5FmfyCJcDo+jAu4fGVdQgFBo0=; b=qLpbsgo1FMcrGRPatlbyd54sJluxkYZuaGyzKmZLuqryaBmmymOjIzsfFO9D+l5Esv WzmJgI4ECwaey1iEjQIn//NYxuaCddcPtIcYgHmouN/Tp7ciFEk284VTJNj1sT8btqpi DSSpPXvqBPp/uoAh8NDwYr2zlOY3jfKJo+I9lJWKS4s16MrqRpzzSDPJgu/9EhRxgfvr I1X3hWmVUNzu1NKcKPwLezHJTPiMyVRmEdA/bR3Sf3e/XA5dKNvg/O5ThfDJSNP3Axef 27fqm3D/YgrgAw9eQqiTNq3Gv9kv1YKpTJNRtDYeVxMlvVjiFh1wsQxHw+Ibn4SDMhY2 e1fg== X-Forwarded-Encrypted: i=1; AL+hErHiBPFfwhRcij7u4kNslYfNnGtSIbIsMx82ph5DMicLqVMHdSyu36UNRvpj6i8QUwWlIEfx/gn1QyNEVpM=@vger.kernel.org X-Gm-Message-State: APuU4Z+Rd5f7P20nNyULMbgoCdJWJ6ZAC+k/b84rhUgPu9WPs3MU9Z7v IPqdzvqZ60AP7GsBm0a6+BjAMxX9uCGdLKs0tLgKiB8mWkXbkQRdlBFQ7jffztTLIvAPGGqwObg 0FXA8R6I= X-Gm-Gg: AZFdTZfIH+YHMyaoxz9EZeLxKw9U9OxAga84Ug96mDOs0XHhqkLPfJ0oY0jXKhL7AbK bkPK44lLUhi8NV4sWDwZEbBKfCB68O4QrjYzJU/tb4aH4hxkV+PSNcfjD1eMu1eJtAZ8Bm/epY/ sKcxGnMGjgbfnfXhIwkobU1XAczLaQcEfo0RiU9zhs3/WNlm3/pbJaXyPICBgI/qJZ0jUOVW4+t ihMY1/I7iWEw5/jXNRTVphZrySP9ZBxCZr+xSphrjc2FaFO88M2iUua1oHEbQgUbwY3KY024Aft osyRR29CrdZdFDPWeYJndpgXSFa6VYTQIiYZ5APjdYcrfVD86iUK4o2qPveqTmyrf0sq8F7xE2O rhJRxYyc5jZKsfIlrimFqIHMhOxVLyW8T7/gtcF0CIjS2k5TfRWxwVPWoqCM8HiPR6MY7u9oGQk aIEFhUygnV06lfUOaiisvHteuGggKpmP9bcHlhS3YrNr6darKisLDCh0N01gE+PQ0ZHvANYFbyt zRztazSi2VLicYrWQDZFKYvrlDA8Fy420XKkM3noQPdv75YC8u1Rre1rSKPkomjMYltGZN8+7tC Wp9hdL1GId5YD1yJkACShpxtvTK2dl51OLT9KjDLyTTNyTbf0hoERu+RYvonmxF4hnJToWvg66C TRiJWOTPSu9dAPgHnA9qg3xyhS7fCpqpGGl2/mcLaCQafv0pFPdIUD1xw5k6u4s0Px9khLr5FC6 feBxgun08qZmS6VM3BpPg= X-Received: by 2002:a05:690c:c96:b0:8b3:1fab:fbdc with SMTP id 00721157ae682-8b660de5d2dmr2692387b3.64.1796341921316; Thu, 03 Dec 2026 15:52:01 -0800 (PST) Received: from ?IPv6:2600:1700:6476:1430:8a82:9efd:4df6:308d? ([2600:1700:6476:1430:8a82:9efd:4df6:308d]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b658c45ff8sm2617167b3.0.2026.12.03.15.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 15:52:00 -0800 (PST) Message-ID: <1eff926161520f9dd05def25e20bfd4e6c97fc20.camel@dubeyko.com> Subject: Re: [PATCH] hfsplus: validate attribute key name length From: Viacheslav Dubeyko To: Kyuwon Cho , John Paul Adrian Glaubitz , Yangtao Li Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 03 Dec 2026 15:51:59 -0800 In-Reply-To: References: <179619831256.1663618.16544869010167759924@skku.edu> Autocrypt: addr=slava@dubeyko.com; prefer-encrypt=mutual; keydata=mQINBGgaTLYBEADaJc/WqWTeunGetXyyGJ5Za7b23M/ozuDCWCp+yWUa2GqQKH40dxRIR zshgOmAue7t9RQJU9lxZ4ZHWbi1Hzz85+0omefEdAKFmxTO6+CYV0g/sapU0wPJws3sC2Pbda9/eJ ZcvScAX2n/PlhpTnzJKf3JkHh3nM1ACO3jzSe2/muSQJvqMLG2D71ccekr1RyUh8V+OZdrPtfkDam V6GOT6IvyE+d+55fzmo20nJKecvbyvdikWwZvjjCENsG9qOf3TcCJ9DDYwjyYe1To8b+mQM9nHcxp jUsUuH074BhISFwt99/htZdSgp4csiGeXr8f9BEotRB6+kjMBHaiJ6B7BIlDmlffyR4f3oR/5hxgy dvIxMocqyc03xVyM6tA4ZrshKkwDgZIFEKkx37ec22ZJczNwGywKQW2TGXUTZVbdooiG4tXbRBLxe ga/NTZ52ZdEkSxAUGw/l0y0InTtdDIWvfUT+WXtQcEPRBE6HHhoeFehLzWL/o7w5Hog+0hXhNjqte fzKpI2fWmYzoIb6ueNmE/8sP9fWXo6Av9m8B5hRvF/hVWfEysr/2LSqN+xjt9NEbg8WNRMLy/Y0MS p5fgf9pmGF78waFiBvgZIQNuQnHrM+0BmYOhR0JKoHjt7r5wLyNiKFc8b7xXndyCDYfniO3ljbr0j tXWRGxx4to6FwARAQABtCpWaWFjaGVzbGF2IER1YmV5a28gPFNsYXZhLkR1YmV5a29AaWJtLmNvbT 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+6ecRAG73xlWMFKVK 4P5XGnHU9A2JOtRhnOWQfPTgFhy69BSYyOeG3e5J+xPyUUBeHajbMVPKnD10NMCx8Ux1D2bv8OWbv 3DvpUNx9D46UhBmkwIfrQWBkr0OGD2AXFfPqo08c3jcJMOAEc2vBI08Fij9o1gHwP2suFaG0X6jUN sy6KPOKg7TVMXtMzxNsKGyFxC1pG7lv+oaEBT6TJSVs/pm71ZrOezQANRzvBeXNUixWienTdAEG8a x4uOf3EF5WvYUhDiY8XBJyRv2ZnKJmBxZ3jPStadSuh3Bmo4mNgRVpFXrfb7h8oJC1l1WGdJa9aWi xUedku0/nH+nZMTqrtWYkXoLxaMswVM5S4f3pYKd7VlHxtlZiQ95RqQd5uWYcEN6xaSvAO3Cs4Co8 D6etTHtKPcx1+d0x6BvkBvqNJ5yCiuzPPnKE6E0ss52KKvQt3injPyfe8ffofbW4s2nlEL1s0DoBv JslCebuQ6+Orb/Sl6zictIsv3XMq3jGFeZcDg2hXzngOC255+b0Z/To7jINTxYQot8jCOJQOLplxc NFdvziOa4FgUBC4X71upsZIoZJeii2V/Jtc3B4g== Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-9 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Thu, 2026-12-03 at 15:34 -0800, Viacheslav Dubeyko wrote: > On Fri, 2026-12-04 at 01:48 +0900, Kyuwon Cho wrote: > > An attributes B-tree key carries both an outer key length and an > > embedded > > Unicode string length. hfs_brec_keylen() bounds the former, but > > hfsplus_attr_bin_cmp_key() trusts the latter. A corrupted > > attributes > > tree > > can therefore make hfsplus_strcmp() read beyond the key buffer. > >=20 > > Require the embedded name length to fit the format limit and to > > describe > > the same key size as the outer length before copying the key out of > > the > > B-tree node. >=20 > Thanks for the report and the patch. The issue is real. The > attributes > tree's max_key_len is fixed at HFSPLUS_ATTR_KEYLEN - 2 by > hfs_btree_open(), so the key buffer has room for only 127 Unicode > characters, while hfsplus_strcmp() clamps the length to > HFSPLUS_MAX_STRLEN (255) only. >=20 > However, I believe the fix is incomplete. Please, see my comments > below. >=20 > >=20 > > Fixes: 3e05ca20fb57 ("hfsplus: add functionality of manipulating by > > records in attributes tree") > > Signed-off-by: Kyuwon Cho > > --- > > The issue was found by an LLM-guided test generator that we are > > developing as a research prototype. > >=20 > > The reproducer creates and mounts a crafted HFS+ image, then > > removes > > a > > file whose attribute record has an embedded name length larger than > > its > > key. Mounting the image requires root in the initial namespace. > >=20 > > The decoded trace is: > >=20 > > =C2=A0 BUG: KASAN: slab-out-of-bounds in hfsplus_strcmp > > (fs/hfsplus/unicode.c:107) > > =C2=A0 Read of size 2 at addr ff11000012fa4a18 by task test/116 > > =C2=A0 Call Trace: > > =C2=A0=C2=A0 hfsplus_strcmp (fs/hfsplus/unicode.c:107) > > =C2=A0=C2=A0 hfs_find_rec_by_key (fs/hfsplus/bfind.c:90) > > =C2=A0=C2=A0 __hfsplus_brec_find (fs/hfsplus/bfind.c:129) > > =C2=A0=C2=A0 hfsplus_brec_remove (fs/hfsplus/brec.c:224) > > =C2=A0=C2=A0 __hfsplus_delete_attr (fs/hfsplus/attributes.c:339) > > =C2=A0=C2=A0 hfsplus_delete_all_attrs (fs/hfsplus/attributes.c:444) > > =C2=A0=C2=A0 hfsplus_delete_cat (fs/hfsplus/catalog.c:415) > > =C2=A0=C2=A0 hfsplus_unlink (fs/hfsplus/dir.c:400) > >=20 > > The patch was tested on v7.4-rc5 and rebased onto the HFS tree > > commit > > a2c27efbbd43 ("hfsplus: fix UAF in hfsplus_cat_write_inode()"). > >=20 > > =C2=A0fs/hfsplus/brec.c | 12 ++++++++++++ > > =C2=A01 file changed, 12 insertions(+) > >=20 > > diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c > > index f416e562d439..b75dbadbab9b 100644 > > --- a/fs/hfsplus/brec.c > > +++ b/fs/hfsplus/brec.c > > @@ -66,6 +66,18 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 > > rec) > > =C2=A0 retval); > > =C2=A0 retval =3D U16_MAX; > > =C2=A0 } >=20 > If the outer key length is too large, retval is already U16_MAX here, > but we still fall through into the new check and print a second error > for the same record. Could we return early (or use else if) here? >=20 > Frankly speaking, the function becomes grow. We need to refactor the > code. Even now the code looks not very clear. >=20 > > + if (node->tree->cnid =3D=3D HFSPLUS_ATTR_CNID) { >=20 > We check tree CNID in multiple places. Probably, we need some helper > function(s). >=20 > > + u16 name_len =3D hfs_bnode_read_u16(node, > > recoff + > > + offsetof(struct hfsplus_attr_key, > > key_name.length)); >=20 > The record length (len) is not checked against > offsetof(struct hfsplus_attr_key, key_name.unicode) before reading > the > name length. hfs_bnode_read_u16() stays within the node, so this is > not > a memory safety issue, but for a short record we read the name length > from the next record or from the offset table. I would prefer to > reject > such a record explicitly instead of relying on the equality check > below > failing by accident. >=20 > Frankly speaking, logic looks confusing. I think we need to make the > code more easy to understand. >=20 > > + > > + if (name_len > HFSPLUS_ATTR_MAX_STRLEN || > > + =C2=A0=C2=A0=C2=A0 retval !=3D offsetof(struct > > hfsplus_attr_key, > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key_name.unicode) + > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name_len * > > sizeof(hfsplus_unichr)) { >=20 > It looks like we need a dedicated function for this check. >=20 > retval !=3D offsetof(struct hfsplus_attr_key, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key_name.unicode) + > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 name_len * > sizeof(hfsplus_unichr) >=20 > Are you sure that this is correct? This logic is complicated and > require more clean code. >=20 >=20 > > + pr_err("invalid attribute name > > length\n"); >=20 > Could you please make the message more informative? For example, > the name length, key length, node ID and record index. It would help > a lot in analyzing corruption reports. >=20 The main problem: hfs_brec_keylen() is not the only path that copies a key from a b-tree node into a key buffer. hfs_bnode_read_key() reads keys into fd->search_key without calling hfs_brec_keylen(): - hfs_brec_insert(): updating the parent key (brec.c:151) and reading the index key from the new node after a split (brec.c:169); - hfs_brec_update_parent(): brec.c:467 and brec.c:479. Then __hfs_brec_find() compares fd->key against fd->search_key, and hfsplus_strcmp() trusts the name length of fd->search_key as well. During a node split, the first record of the new node has been moved from the old node and has not necessarily passed through hfs_brec_keylen(). So I think a crafted attributes tree with a setxattr that triggers a split could reach the same out-of-bounds read via fd->search_key. Could you please move the name length validation into a small helper and call it from both hfs_brec_keylen() and hfs_bnode_read_key()? Please also note that Ozgun Kultekin's series ("hfs/hfsplus: pass the key buffer size to hfs_bnode_read_key()") is changing hfs_bnode_read_key() right now. It would be easier to rebase v2 on top of that series. Finally, could you please share the reproducer (or the crafted image)? It would be useful for checking v2 and for regression testing. Thanks, Slava.