From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 B86DB3B71D0 for ; Wed, 10 Jun 2026 09:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781082590; cv=none; b=pizNbcQlw64YYsVp1n/L+MQysMp8xGbKPkeM3/lv9jTxolfqvCup6qWdklBDZnjrefUqEJItMcYvS4zXuoAbPCXZmHvw4H1xZwfzQ4aRFiAF320nNRfWqgRr6LvJoyRXqquwhGnOrqDn7zwfcNUsBdDqWPo7eSwP+0l/IaO/GYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781082590; c=relaxed/simple; bh=0WJ4UY+DGzKi6B9P1hXaTZJA18fsGtqUzi10S7pOVG8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KDELfjLSJSrtj2eYW7xv1/ckI+22m+S12MJvOm8Rq8U4lLOqDMr9hu5U3Ouq9o47IAwcqjK/IZTDyi7XU7vkGs4tjvcZlFwSAOBWadlU7LNn+NFHGFX1cCh8IOZjSnBajVJ5XnnQ5abgnsEbmjYjgvkpRhiJrpQwV2TOa8VAbJU= 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=j++iP20T; arc=none smtp.client-ip=209.85.128.41 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="j++iP20T" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-490b8ac62baso50936665e9.0 for ; Wed, 10 Jun 2026 02:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781082587; x=1781687387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=iWrkOjjLJH5qDnRo8XgcjVbW4R3sL57sCMCmEUy+meI=; b=j++iP20T/MgTGRTHqwL3SbEFJl/c43ME3gzzR72zVOvzZEhuy56QyjoZHpcwCrE/6h 4Rnw6GxHwdX+HNL3vb1CWEJxEQsba73FgOoYo+Toa8fw2cVxJiJFJxcAn3j6jemOzDWG RDj+8mYXXR+82uaPSFFHUP/xRvhyoNlafGvl3gV+YhkwX14Z018BUMDisPtCcHgLEFgV z3bUIH6PMio4/UdazBrt7UidsFrAvsbhUM9tNN56n6r5WqMBEkH740atbR5qcZrmm0vH g3gaH7p5PnMQlDFaHwlfVzKVKB7377TJAF9kpKMXuYqbPG6Gk/1FuM+5ilN+6kLQ/iRk n1cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781082587; x=1781687387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iWrkOjjLJH5qDnRo8XgcjVbW4R3sL57sCMCmEUy+meI=; b=UFHJ2ouSPL+UJzsv54HQmtnkOoaeYESTaUlbTtPQfLogKt9/XD89MjhGk83s5YTQ01 rOe3o71S1d01yVe8LgFTUve3+2JSxZnZURffSVfVdeFov2yeuvVejPxA8fwcQ6loH46O GeNOIATvvuWOL8Y1AIy05WUUzPQjosJ6B4TpO+CrHLKB6UaIXacv2qKISQkwg6tRbtPa HWk4zY47Q2rqLwcnOlj8/MNS7joEB8UGzNSZ+uwLEwywXs4+RSSQt6GxkZw/+Dk5Rr7O PJ+tpj8/Fax+9cbdxLcTBOW6TJnYTx2z12QehC6S25HCqFGNJLbtn/o1a076vF9N+pRK AROA== X-Forwarded-Encrypted: i=1; AFNElJ8DoDYTblmDsYrgBwqY1NTLmxRabfm2O9jrN+Sik4vKx5qjyOw+vnrJeYEGCOTJK8Lw4C70jxn8kYtSTx4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0jF6VXcWMIbB4XnhTTDYDAsU39YVQJX1SzyFs412kx9A3m7Xl C81rmNk3tDfzpXw8C6AEuELUgwH++zFBTgNCEwjpkku8WrTS98XF1+0fwboMneQv X-Gm-Gg: Acq92OF+RKqer6o+no8xOE3UXXkSkmmnB85HJixAzstXHSZCl4CGxDYoZqi2zel0rUs jpuERAVZhiN8sliav8WcUdCRnigTxjpYA2EIHVUJ9UoSwOIIVwXs6nYrw2g819la8CZ25Y34Edl kEhqpiQZLdVgBCaGzHLF0/8qZ0igRSU2ZbTJKHE/bUSkoU9Nq54G/VMUypmn1E+G1xS69GfznSi fdNVaARLBWjoMaNIjWE1o9T0HJY3qGJ8AnQHH6uRbYFw1SrUz6eCDE0wAGNpW5yFWpoF2nVC1KR q07DUqcRO64LYqY/TyexBU6TJO40shn/jRGRpaMJ84nM9d+4yswcXgyDj+NLc/5MH9U2sFwgwnc Ua7ylbzws1NvgRHNKj74kBsqFNL70fta0zcw1OD7+9d7Htvn8WR0U7W0VNoVQR7eULiti77BNxC c3jKKxqQ7l4QRD90usjYr+CUyjC9EiDhjPxjrZh4kq44MQCpwbefJ/RI+cD11yxJyD9Xgkghc= X-Received: by 2002:a05:600c:1c29:b0:490:7df7:9190 with SMTP id 5b1f17b1804b1-490c2ceb6f6mr344978125e9.8.1781082586982; Wed, 10 Jun 2026 02:09:46 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3918fcsm630684075e9.3.2026.06.10.02.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 02:09:46 -0700 (PDT) Date: Wed, 10 Jun 2026 10:09:44 +0100 From: David Laight To: Viacheslav Dubeyko Cc: Kees Cook , linux-hardening@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Arnd Bergmann , John Paul Adrian Glaubitz , Yangtao Li Subject: Re: [PATCH next] fs/hfsplus/xattr: Use memcpy() and strscpy() to build xattr_name Message-ID: <20260610100944.3c5a5771@pumpkin> In-Reply-To: <45e421ab38cfdbddbc0d34970a2db94902ad634b.camel@dubeyko.com> References: <20260608095523.2606-39-david.laight.linux@gmail.com> <45e421ab38cfdbddbc0d34970a2db94902ad634b.camel@dubeyko.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 09 Jun 2026 18:04:46 -0700 Viacheslav Dubeyko wrote: > On Mon, 2026-06-08 at 10:55 +0100, david.laight.linux@gmail.com wrote: > > From: David Laight > >=20 > > xattr_name is kmalloc()ed at the (assumed) maximal size and then the > > prefix > > and name concatenated together. > > Use memcpy() for the prefix - its length is passed and strscpy() for > > the > > name to ensure it really doesnt overflow. > >=20 > > Prior to bf29e886b242c the buffers were smaller and on-stack. > > (But I cant see the copy in the old code.) > > I am also not sure why the buffer isnt created "just long enough". =20 >=20 > What do you mean by "the buffer isn't created just long enough"? And > what is your vision of correct implementation of the logic? The old code is: > =C2=A0 xattr_name =3D kmalloc(xattr_name_len, GFP_KERNEL); > =C2=A0 if (!xattr_name) > =C2=A0 return -ENOMEM; > strcpy(xattr_name, prefix); > strcpy(xattr_name + prefixlen, name); It would be more usual to do: size_t name_len =3D strlen(name) + 1; xattr_name =3D kmalloc(prefixlen + name_len); memcpy(xattr_name, prefix, prefixlen) memcpy(xattr_name + prefixlen, name, name_len); So that the buffer is allocated the correct size for the strings. (Not that it really makes much difference whether you do kmalloc(32) or kmalloc(1024) for a temporary buffer - both come of a per-cpu list.) What I couldn't decide, but seems to be inferred from some of fixes, was whether a double-terminator was needed. (That might just be the attribute value.) One of the related functions got fixed to zero fill a buffer in a loop because (AFICT) something was reading beyond a '\0' terminator. This code does seem strange though. It seems to add a text prefix here and then the called function does string compares to find out which prefix has added and than act differently based on the prefix. I didn't try to follow things any further. I also don't know if 'name' itself can be 127 wide characters (before the prefix is added)? The fixed length buffer isn't long enough if all 127 characters require 6 bytes to encode. -- David >=20 > Thanks, > Slava.