From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792700570; b=TQoVyBrVWUw/vJkWdTC2vLb2ximQjJG5RRNrqlIWosBC3BDRQ6mGHz2lwWLS4graxODQ jd3o2KxQweGBomV7sto9vWPyok5ush3JA45+sMnQRQa8NPVBkiajc3SwvXENXZA+90/7E pu+BNeduluL1mEXrCOAPJzCYsT/44lB4OeWtwFH2rSn81auENLq7B2GhHSW8rsHbq5SSf D6pjVpdVVrwnSlDIsAZes1YYqIZG5lQJ2DaZ6wFWXp8rH+j7TPiqFF6+SdbCHXOrd+WSr bY98Ap8tK/NXbY6zf2QA1G7AJP9F7KwKI0NLrdFrsUgCRlxj9Hw3/uayHIYgvyZpJUg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792700570; 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=6+OZ7UAj4wpyLIvTVHWqEA215IR1A8qQvTEaOHFShS4=; b=rxNHj1pQM30Um/tMkxRisf3OutuztmVcAm4QixSAyN5rP232ZRrEMfvmxFTuP540+2Ku pjekhy4FgDBkEsTcI4ptAZbtgCxGts4yb0iSShuKLzOWPGgOricWwXomY+3yfBCH0mwfX hnxd8Uqz325KwbCijDFVd0UG1xFAEBykHKNvfW6pcretS3PjXUl8jK49j4GI0KHv3Yc2/ NqY0vOlBWQaMD5PgON3wxuthaMVuom5b1ihK8WVFQlOO93agKQLUSpw2Eu4nlesdZApVI 02y9ZcmQlKkBvJO9pvMUYODInDx0DlKrZh1wi5ZHDxHe+sba6WXALTPcGgLAZSn0eOQ== 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.20251104.gappssmtp.com header.i=@dubeyko-com.20251104.gappssmtp.com header.a=rsa-sha256 header.s=20251104 header.b="LX/PbAP3"; arc=none smtp.remote-ip=74.125.224.50 Received: from mail-yx1-f50.google.com (mail-yx1-f50.google.com [74.125.224.50]) (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 D5626606A319 for ; Thu, 22 Oct 2026 20:22:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5626606A319 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, unprotected) header.d=dubeyko-com.20251104.gappssmtp.com header.i=@dubeyko-com.20251104.gappssmtp.com header.a=rsa-sha256 header.s=20251104 header.b=LX/PbAP3 Received: by mail-yx1-f50.google.com with SMTP id 956f58d0204a3-679aeeddc6bso322551d50.2 for ; Thu, 22 Oct 2026 13:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20251104.gappssmtp.com; s=20251104; t=1792700569; x=1793305369; 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=6+OZ7UAj4wpyLIvTVHWqEA215IR1A8qQvTEaOHFShS4=; b=LX/PbAP3SVuSBH9kbpXY0xPdGlqMqb9hUY2i/eVrUHvo3AcBCIjUXvpkN7qNFuEUkr IMaSW6GIzwyYRoM26Eot6lV+mYkFX2IuQYXc5XA7qVqnyKO/PRNtI2qD4+8h3vUl7mgy P+snby1i4L73rC75zcNABoO4L/fcZDb0n8LmliR9IH1LUnjYxyZ/d2AwP0fmlMHS52hF /vrIwBii/xYYYsz9D4A03iWhrSJMERu4FLL5tDehyr9tza6Hlykp4tDWhgZOJspflkMY kB1G8Mm/JSqUSN2hj6p/w6SCHo//aJzhqBb7k9G7u7Mtyz9BP3iAVGUxsu5OPo0ydvt4 F35w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792700569; x=1793305369; 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=6+OZ7UAj4wpyLIvTVHWqEA215IR1A8qQvTEaOHFShS4=; b=I4maa1LklwdGp1iSnOGCdN05tISHQnVff0FQENZZZHW8hI+r9g/p2xL9zVAQR2aPOa XlCWLOKaA3IECaRZkKtNalkzdT9RCAfYu8c5tb74S/iyJVmiDu/be2wvmhjviiKNADq5 KdD0TBZhojxmdf117sTT16Xp6NKGbIiGaGUPr+zkvHADCfmM+pBmfgFJjPnORLM3pWOy AAK7l1n6KV0UBfAgdZeqbHzv9WourQGkmrNtyjvLLKjcxJ0wRUiuXEQk25VPPYMQW6hE dQXzaux7rVdJGFvacEfQSYjiRLgBPwdJD1xhgyikcnmTGw7pfn2nr6HTjbBYcHO80I1L cz2A== X-Forwarded-Encrypted: i=1; AKwUvBxSE3AOmHJ/VBa0BEQ6L6hTKuGHLfefZOlWNlrcUjdv6A3pLAStpc1GphRM1dDdpIr3DGADY2POALp4/N4=@vger.kernel.org X-Gm-Message-State: AFq9FYIF8y98SAgkBjj7RPh1SEtkfOVHxSHdqSwr61wQQV8O22cGLHcR uKRUdQZIRRAgIHe3kfpbhsvI1Gt4m6F+C3N0H4NvP4cwuCu4bAHmxk7ZkMfzvmP/QCM= X-Gm-Gg: AYBFou266GeIuBRJi1L6SDR+weqSgb0pyr4LTiNITVPqDHeoznGwuU4d3BhMccnuDD0 J1xL22dXHpdsdFfhb7iMnX/NBWGi1QCZd3VnEJv22klg1yxjFlisPOWo1A6zdAdXlb6Y9De66e8 qtjld1iyuF/GQKXr6LCO5eaUn9I+/3DojAqqV4i3jO5hBzACirCe81148imq7FalGspey1kFm4U sjgoymJisXBaDs8WsDbTV/eGr8Ih8Q5e2ux1MAKrZWmZK329RQrOMY9LDdeSYtDHSaKfLSuB6Nk U2B+j26NOOiNtqMVVAUBic4vmwgT6l37oGQfzfWZ2Byh7Vcy6sGkDjzOBhy0mLIHQArMt75b2C8 C7OkbLPqVQalKdzOzp1Joi/5gVESt9LwWaWXR6419PXTqN3wJbgW95FNvrgiEyjZXxIyGpWEOBc dJ759kQlhsU2caqPRZfrOowbpAWR5DHDh6ntK22yyRaFzSF4Agw8V55volN4fIA1vvhzNybUuF9 LvAzx98jQ6cHEIZdseeyKb59haTuRKgJLAStaEqmRuTs5fIbECXBGrY2L37ARydZvIMgoAn9Iqx qtmLGs9PPx2I/L3pip6YDxBAv19DcvAt1ybP/HWBFA2GZhc+UZt7dawcr5iDQISZQNLY5MkZwTN O5eoKlZw8WIk7dzQOA1/w4ZD9fSjYhAr71TKzchf9RghDpA== X-Received: by 2002:a05:690c:60c7:b0:8af:e4ee:a91c with SMTP id 00721157ae682-8b157dd761cmr909137b3.41.1792700568859; Thu, 22 Oct 2026 13:22:48 -0700 (PDT) Received: from ?IPv6:2600:1700:6476:1430:d350:a0e4:db9b:3217? ([2600:1700:6476:1430:d350:a0e4:db9b:3217]) by smtp.gmail.com with ESMTPSA id 00721157ae682-8b1561e365fsm3568247b3.45.2026.10.22.13.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 13:22:48 -0700 (PDT) Message-ID: <4d28ca686fee764bb0eb3710f390a6f5fc9c0d4a.camel@dubeyko.com> Subject: Re: [PATCH v2] hfsplus: fix truncated xattr names in listxattr() From: Viacheslav Dubeyko To: Hengyu Liang Cc: glaubitz@physik.fu-berlin.de, frank.li@vivo.com, kees@kernel.org, justinstitt@google.com, maurycy@maurycy.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Thu, 22 Oct 2026 13:22:46 -0700 In-Reply-To: <20261022111700.1288273-1-hengyul@cs.unc.edu> References: <20261022111700.1288273-1-hengyul@cs.unc.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 tXWRGxx4to6FwARAQABtCZWaWFjaGVzbGF2IER1YmV5a28gPHNsYXZhQGR1YmV5a28uY29tPokCVw QTAQoAQ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bxJlWnMhLxMPrxgtC4Kos1G3zovEy Ep+fJN7D1pwN9aR36jVKvRsX7V4leIDWGzCdfw1FGWkMUfrRwgIl6i3wgqcCP6r9YSWVQYXdmwdMu 1RFLC44iF9340S0hw9+30yGP8TWwd1mm8V/+zsdDAFAoAwisi5QLLkQnEsJSgLzJ9daAsE8KjMthv hUWHdpiUSjyCpigT+KPl9YunZhyrC1jZXERCDPCQVYgaPt+Xbhdjcem/ykv8UVIDAGVXjuk4OW8la nf8SP+uxkTTDKcPHOa5rYRaeNj7T/NClRSd4z6aV3F6pKEJnEGvv/DFMXtSHlbylhyiGKN2Amd0b4 9jg+DW85oNN7q2UYzYuPwkHsFFq5iyF1QggiwYYTpoVXsw Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.1 (by Flathub.org) 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-10-22 at 07:17 -0400, Hengyu Liang wrote: > From: Maurycy Pawlowski-Wieronski >=20 > Commit 7dcbf17e3f91 ("hfsplus: refactor copy_name to not use > strncpy") > made copy_name() build names in the osx. namespace with scnprintf(). >=20 > However, the size passed to scnprintf() leaves no room for the > terminating NUL, so the last character of the name is dropped. As of > now, listxattr() returns every osx. name without its last character, > and these names cannot be passed back to getxattr(). Yeah, I see the point now. Thanks for clear explanation. The main=20 point that scnprintf() expects buffer size that includes terminating NUL too. >=20 > The issue can be reproduced with: >=20 > =C2=A0=C2=A0=C2=A0 truncate -s 64M hfs.img > =C2=A0=C2=A0=C2=A0 mkfs.hfsplus hfs.img > =C2=A0=C2=A0=C2=A0 mount -o loop hfs.img /mnt > =C2=A0=C2=A0=C2=A0 touch /mnt/file > =C2=A0=C2=A0=C2=A0 setfattr -n osx.test -v 1 /mnt/file > =C2=A0=C2=A0=C2=A0 getfattr -m - /mnt/file >=20 > Without this patch, getfattr lists "osx.com.apple.FinderInf" and > "osx.tes". With this patch, it lists "osx.com.apple.FinderInfo" and > "osx.test". >=20 > This patch adds room for the NUL to the size passed to scnprintf(). Usually, "This patch" is not good idea to use. :) It will be better another way: "Add room for the NUL to the size passed to scnprintf()". >=20 > Fixes: 7dcbf17e3f91 ("hfsplus: refactor copy_name to not use > strncpy") > Cc: stable@vger.kernel.org=C2=A0# v6.10+ > Signed-off-by: Maurycy Pawlowski-Wieronski > Signed-off-by: Hengyu Liang > --- > Changes in v2: > - Rewrite the commit message. No code change. > - v1: > https://lore.kernel.org/r/20260828-hfsplus-copy_name-fix-v1-1-75ed9f0f378= c@maurycy.com >=20 > Maurycy, v1 got no follow-up, so I am resending it as Viacheslav > asked > in the thread below, with you kept as the author. Let me know if you > would rather send it yourself. > https://lore.kernel.org/r/dc187921249a3f6716b829624853e64c10321cd1.camel@= dubeyko.com >=20 > Answers to the questions on v1: > - generic/377 passes with and without this patch. It only uses user. > =C2=A0 names, which go through the strscpy() branch. That branch already > =C2=A0 passes name_len + 1. No xfstests test uses osx. names. > - Why + 1 helps: the prefix and the name are name_len + > =C2=A0 XATTR_MAC_OSX_PREFIX_LEN characters long, and scnprintf() writes a= t > =C2=A0 most size - 1 characters before the NUL. Zeroing the buffer first > =C2=A0 does not help, as the last character is never written. > - Why the write stays in bounds: both callers check that the buffer > =C2=A0 has room for name_len() bytes, which covers the prefix, the name > and > =C2=A0 the NUL, before calling copy_name(). This is also the number of > bytes > =C2=A0 copy_name() wrote before commit 7dcbf17e3f91. > - All xfstests: see the full run below. >=20 > Tested in KVM with KASAN on a804c5742bff, without and with this > patch: > - The commands above, and a C test that compares listxattr() with the > =C2=A0 names set on files and a directory: short, long (up to 127 > =C2=A0 characters) and non-ASCII osx. names, FinderInfo, and user. and > =C2=A0 trusted. names. Without the patch, every osx. name loses its last > =C2=A0 character, fewer bytes are copied than the size query returns, a > =C2=A0 buffer one byte short does not get -ERANGE, and getxattr() fails o= n > =C2=A0 the listed osx. names. With it, the names match, the copied length > =C2=A0 equals the size query, and a buffer one byte short gets -ERANGE. > =C2=A0 KASAN reported nothing with exact-size buffers. > - generic/377 and generic/062: 5/5 passed on both kernels. > - Full fstests (805 generic tests, 608 not run on both kernels): 188 > =C2=A0 passed and 9 failed without the patch, 187 and 10 with it. The onl= y > =C2=A0 difference is generic/617, which fails on both kernels most of the > =C2=A0 time (19 of 20 reruns without the patch, 18 of 20 with it). > =C2=A0 fsck.hfsplus -fn reported no errors. The xfstests cannot help with testing osx. names. This is how I missed the issue. It will be great to have a KUnit test(s) dedicated to testing HFS+ xattr functionality. >=20 > =C2=A0fs/hfsplus/xattr.c | 4 ++-- > =C2=A01 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c > index 71364e093fa7..470f090b2699 100644 > --- a/fs/hfsplus/xattr.c > +++ b/fs/hfsplus/xattr.c > @@ -515,8 +515,8 @@ static ssize_t copy_name(char *buffer, const char > *xattr_name, size_t name_len) > =C2=A0 memset(buffer, 0, name_len); > =C2=A0 > =C2=A0 if (!is_known_namespace(xattr_name)) { > - len =3D scnprintf(buffer, name_len + > XATTR_MAC_OSX_PREFIX_LEN, > - "%s%s", XATTR_MAC_OSX_PREFIX, > xattr_name); > + len =3D scnprintf(buffer, name_len + > XATTR_MAC_OSX_PREFIX_LEN + 1, > + "%s%s", XATTR_MAC_OSX_PREFIX, > xattr_name); > =C2=A0 } else { > =C2=A0 len =3D strscpy(buffer, xattr_name, name_len + 1); > =C2=A0 if (len < 0) { >=20 > base-commit: a804c5742bff224d4cb4d25dd383554d598be32b Looks good. Reviewed-by: Viacheslav Dubeyko Thanks, Slava.