From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796340846; b=mM9Rj1UGDI6dCxD6H2w1864dTbY66jUB8WXU26kqQL8G83BnZg/MKvXOK+pU9SJPUf8N lLMosrDWruoUuiaqhc6KTujswNaKKp/OZs9Y4JsJ03T0W0VZauetAGjPp2KLt0eTW0Ju5 RIph9Jq25DUI5/0NH1e0RmnPvYs2kx3KOLmdHK+fSjiDsqUA1W+WHHd8F0QiqRHn9nMfR BRNvtt7Tw5Ls3hrU9neO2CBwwIndW9XG8UIzF6Em6rDug0p1VbFFuySbTFeUUCh6apsD1 sps2m3JaMEaQg/CwUUPzAJW41VUPWzH0OLIQJQRRthLpaq8rNoudkppUNbNxRctED8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796340846; 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=swDjUCZicOu73YHyAz209fOOSU3FdwZh3GZUlIR40YU=; b=avY83knu9M6ARAIlGv366P1+eBwswpLQiKNiFG0FkMJJxyAjIE4Q07XEalCITTDCoEyc T1VhfxMDVAolO2hVBAW+PGf4Kg+lsRGz6jr2Ku5D2MGBpfEC2QPLBRg+mjXGg9brvnwgW diZUd5BXbo+XdkNVMHnWFIKf88jGq08JINOkroB9BqqGi0WjGvh+ZVzEVbXurFAv2GHTZ cr+65Iyko+e1v5GJ1O3t/SSKqKgaJzdkroVxm+sdmuPX3t4X+w2TR0A09ad4tmz6Wbz23 be6kkhXhrmwwF/FvGbp7Vh4bjC0Ulj69fmzWYrESKQ7Z8kInqPzPs15XLgiopBSNpVw== 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="tG/b7Ess"; arc=none smtp.remote-ip=209.85.128.175 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 0D2C1606A32D for ; Thu, 3 Dec 2026 23:34:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0D2C1606A32D 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=tG/b7Ess Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-8b2d14968c9so3542097b3.0 for ; Thu, 03 Dec 2026 15:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20260707.gappssmtp.com; s=20260707; t=1796340845; x=1796945645; 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=swDjUCZicOu73YHyAz209fOOSU3FdwZh3GZUlIR40YU=; b=tG/b7Ess6KBdoRqPwArTNMeKGZUCvPU/wEZ3nCnijvufes1Hf1oaDNWxfOoaK1BxQ9 9S7wMRvgNng6wT/wQBERf0hVms2TIDQt1rwYSysl1Z6qvnGu6XLPeFVm1MF/ft3OUpOk 7PgeigB9amlAJ2jrJQN8y89XjZcOt+7m5IOpxU5nZjXKXqvWcHw+aKOpRkWF9VnVILp+ lMD7Ht8oaazrm3OPtXYW1aUOD84Tc9zLKDWAZYsSEkPsi4pmJ+Wd5O4gxEEPFSdO7G9o bTgqXykixc72YptiSDXTwY1neElG+15k/VU20g1m2WLfFTTUrtqXlMu0CQGqCStltnus NfFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796340845; x=1796945645; 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=swDjUCZicOu73YHyAz209fOOSU3FdwZh3GZUlIR40YU=; b=nxBdaqPUt9XlxtKlVH1kBkblwcUevd0v3pF6s4VMJMGmkMzJfaSSy5SAaPt6e7UuZR ZGKO16qQruGzgmLWejgR3eoLe2XRjKoXfCQw+kVd6CNXNXykJfBb5fG3yGu9dDezVuOv Q4FM4fCSlDz2Cc7CBp51oy3U4FqQs+RfC71YJtM5iaGfxZhzvgNb+woDAsE+sFLeTl5O hBnXG3akyRtzw09owpbmVgF7qOkQdcJeK/TuaYcQa4hubFVesmiu2SRrYddGxO+SIbr9 7gUCIjGLLoajeFi9KmGZk7Sok+pGgMG60o0yIxzVtuKKl06q7uFmgq7zkXbQve9Ww5U1 xMdg== X-Forwarded-Encrypted: i=1; AL+hErEzpHMclU0AWtbz+5au8yOJGNw5xKphBVBBg5QPi7L325XBLTz2NlxwSXLWMR6TmErkUNa9Rj0yLc9jnZI=@vger.kernel.org X-Gm-Message-State: APuU4Z9NXvxtxPQ/Lka31wYev0i8xWpvRabWQXA9lBLVuxAGZJk97sUd jTnrikVjrsO1u4S9HW+ZMApswokVzm1ZpdZt3U2XVzdJuA370FzxpMIjCt0PYmAYjVNSsh/iTQi R1x+RzNU= X-Gm-Gg: AZFdTZfNJfmYWx21212/DgPjPYIwMxhXiCTp/mJv9twnqVAy9vi8iDI/H+aTsAQkEwJ aO2Pu+v0nNWyC/VCROHPvheqpSggeoIPq/Ddp9CJDlLMxZgkA8fhzGZ9D8bOAujbFifZ/WMaCzj fK8fvcF8bNmjwtkiFz4vseTHDB07MLubw2yfnkBn2T7gy/mxYSjRN3UeEkP6kAEcV0eJdnUGB25 2vKbetIgEVcR1VksJJyDlbwgLBKQEogPQSKhP2dOFBlTBXyE4WkiHYdobd/3CMtRO4cu132J+sR GKJF72HWYzbmnekN5Itbg3GBEZXivrN8jlK04b6VML/xizMpTPJRofpH+xyWpXCi0Bb6QtmGhCX PU/LeNwe39QRFSz7qClaIBjzQ+PshJYSmXjogAFEiftvqHA150YG1GY1GQMaGBmcGDP/NtQX4VA fWKZfUtMP4w8IyQ+PoYw68bM5hQ+xaa0w5uDG2269Q2knc7TMDCDUWtEZ5wsTKn4jXpJ08MNeCH w0nnU6eD7WJhVR98fv7TC/HA2C5vOJZOoLnIXY2/bvcpGlP6B94VkWFvH18dvSXXeYCDcPPkVh+ yk58jfY3FzjQqGYAohg8SCY05lUuWXGatA0sti0sWhAbtoBhob6nXT6zBMfzDSo1Or2pYONPzRX /m7KxpZqMU8ImQUyyiuyupV7JrWlIxi7P6mnOD55NRNQwZNfCep0mwrnHNwMbZOs+kVPiqgFZ/v qDCwLm/wzpUl5ngmpEtWc= X-Received: by 2002:a05:690c:3686:b0:8b0:d42c:54e9 with SMTP id 00721157ae682-8b660d3fe23mr2249877b3.34.1796340844996; Thu, 03 Dec 2026 15:34:04 -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-8b660d93133sm2251097b3.28.2026.12.03.15.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 15:34:04 -0800 (PST) Message-ID: 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:34:03 -0800 In-Reply-To: <179619831256.1663618.16544869010167759924@skku.edu> 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 6JAlQEEwEKAD4WIQRVwwtrZ87KC0La2wQ5XNn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fPTgFhy69BSYyOeG3e5J+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 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. 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. However, I believe the fix is incomplete. Please, see my comments below. >=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 } 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? Frankly speaking, the function becomes grow. We need to refactor the code. Even now the code looks not very clear. > + if (node->tree->cnid =3D=3D HFSPLUS_ATTR_CNID) { We check tree CNID in multiple places. Probably, we need some helper function(s). > + u16 name_len =3D hfs_bnode_read_u16(node, > recoff + > + offsetof(struct hfsplus_attr_key, > key_name.length)); 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. Frankly speaking, logic looks confusing. I think we need to make the code more easy to understand. > + > + 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)) { It looks like we need a dedicated function for this check. retval !=3D offsetof(struct hfsplus_attr_key, + key_name.unicode) + + name_len * sizeof(hfsplus_unichr) Are you sure that this is correct? This logic is complicated and require more clean code. > + pr_err("invalid attribute name > length\n"); 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. Thanks, Slava. > + return U16_MAX; > + } > + } > =C2=A0 } > =C2=A0 return retval; > =C2=A0}