From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 C320D36CE10 for ; Fri, 12 Jun 2026 18:53:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781290415; cv=none; b=Yr7CbiODdhhhCkoCEHtCATzLUmArKSe0Ozr3QGHoyJoxS2JdvzpSm+ieT6NJkFgXljt34GDou7iDZMLvq7LLwqkUk1SUlh1G5CODjSdvoU6sUBFw5NevGOklEAy9U26vNNFixNObeXLlD0oLDRrYT9A9q7EhhkeptGd/MVL/svk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781290415; c=relaxed/simple; bh=EnU1mmSugKyvT3f45kASsQfDqSHL4+wuMjzLJSGRqlQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WzBmX/JEDgmn8yDNAilBkey12eXviX0z4WB1xURcr6K0ExGQk7JL0X6xGqKlz+hTvee7D0OjQjG8Y+cZWlGGBRZ+sJkBVELOTl6kll3Usdso7SIYDzFaLlwkq3jgvQUV0+3aWICNxjKoTutWSAPxc26XENPdjziczpQzIbp6f24= 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=XughLwb+; arc=none smtp.client-ip=209.85.128.48 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="XughLwb+" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-490be29c1c5so13939775e9.2 for ; Fri, 12 Jun 2026 11:53:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781290412; x=1781895212; 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=CB3wwilAFNqCSPIrYprWyBx0bbSlAUAXEXzKdqsS5I8=; b=XughLwb+sdbkRB7dhKh6x7WdR64/e8/m8+XqSoHgSWMo23uU7Di1Q57AvXRip0lgU/ wVIkTjt8QtTCVBFx88FxweI8zRP18oCs6NbORpI995WKWQPdz9NkJAdStiryYqpviQrR xV3DzYrUlzakmGRURGwBlPg83lbTJhlH4PgKmqiysJw/Nq2/iyRtkbPYyBWLdPDNtqFG HE7dg5NDkRtrcQL7I73l/nSdf626HyGWGJOZMyMPxR5RsVX9CTwYIFUfRdTbJqZH6Sw0 nfrGxjcHXsViRABP0N7Z7piVP9H9jU98NwyitduTN5QXXaUNDM8rX1TH/Pyi7J8c7m0w Aaeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781290412; x=1781895212; 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=CB3wwilAFNqCSPIrYprWyBx0bbSlAUAXEXzKdqsS5I8=; b=arPOknbjWOP4JJigbUqrHg8QChuC4d0TUsyc/iMa3dTqNJgS225tvaDltTUlOJNVMx GM/PZiUFRQ1OYfEQcU4U6acGMxonR+XExZ7v6fqzGN1ZT7fDoLw/SwZ0JQ3EXCqf0GGC 59XZdqFEr0QBzClQyORgo9/K40DQOD47WdojbhxDSxz27ax01z5VRmnHbiIzVdRa00GC W3sLZxK/VFtuUVlhRqUijdAy3n5lr3fiUPieIKKp4bsHz4+5KhJT9ByDvoXKMBQJVu57 72SUmOJG00pPP4wRrqOZMx2fsDPTimQ99olLq3Bc2WOCeO6ziswadjQrmepbxLrI5EDA 5mLA== X-Forwarded-Encrypted: i=1; AFNElJ8gddR9wILCmXnzzmsMtdeJyh4cHDKxuyBStyWCExwb5vh3yUbfP4BfNDgNXHU7mdRJEsMuOP8g9Fb+3XU=@vger.kernel.org X-Gm-Message-State: AOJu0YyvsgyMy0rS4Mv36brYkbkXMULGWWzfOgt3EUqz8M6I8HnSuCm+ AIpBzqiTZ9fhtL64TOcBgGX2GSbzlE6idc97gKH96riUXYCsBuMMxgK/ X-Gm-Gg: Acq92OGY9cO8AVgcX2tt3iteu/sHjfcAL98GB7VgZvX1B3M/eRMcnDEasGvo1Ckyygd lYcU8VyLSidr53/bqVwMcruVaCrj1igUQ95R9dv90TTMxnRx4G6TrbyBoX0HVcYg+kDXoL92BYn E8Gy6223HnSK3o8AZ1R/OcEd3O4xMSdJRTNKSvqudT3iFkVPEwWSi+QWx7jsa2C97bYMPXvhIRj qACLKgpeS3ZDFYNyiV0Qohc1p7mzyHc77juQKRSnK9KryL+XhClzoagkrqvPQPmBSU8ekN0/yQU L2raArEr1m6si3YDlWdrTn2C9t45yY5JIlWLI5vKkyI95WGrKS1yl0FUQxGzzO2Zi97sIhyxJ+c +PW8BNNE1R3SWExu18o5OpzLoxOqrm2PwSFbNws6Kcl/sPtFYBrk+urL8zKwIvjTteZte/VMLR5 BYrQ0kjgn9VW57LgPCnuFhQJgbNfjfa5I4l6OJ6yWBnphPuDfneSSwwrh0uHBx X-Received: by 2002:a05:6000:4312:b0:460:70ae:f1a2 with SMTP id ffacd0b85a97d-46070aef2b6mr5433215f8f.17.1781290411899; Fri, 12 Jun 2026 11:53:31 -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 ffacd0b85a97d-4606f20e77asm8584369f8f.0.2026.06.12.11.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jun 2026 11:53:31 -0700 (PDT) Date: Fri, 12 Jun 2026 19:53:30 +0100 From: David Laight To: =?UTF-8?B?QW5kcsOp?= Almeida Cc: Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Christian Brauner , Kees Cook , Shuah Khan , willy@infradead.org, mathieu.desnoyers@efficios.com, Linus Torvalds , akpm@linux-foundation.org, Yafang Shao , andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com, Petr Mladek , linux-kernel@vger.kernel.org, kernel-dev@igalia.com, linux-mm@kvack.org, linux-api@vger.kernel.org Subject: Re: [PATCH v3 3/7] treewide: Replace memcpy(..., current->comm) with copy_task_comm() Message-ID: <20260612195330.1653d041@pumpkin> In-Reply-To: <20260612-tonyk-long_name-v3-3-7989b66e8a99@igalia.com> References: <20260612-tonyk-long_name-v3-0-7989b66e8a99@igalia.com> <20260612-tonyk-long_name-v3-3-7989b66e8a99@igalia.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 Fri, 12 Jun 2026 13:20:16 -0300 Andr=C3=A9 Almeida wrote: > In order to increase the size of current->comm[] and to avoid breaking any > existing code, replace memcpy() with copy_task_comm(). This new function > makes sure that the copy is NUL terminated. This is crucial given that the > source buffer might be larger than the destination buffer and could > truncate the NUL character out of it. Aren't you re-inventing get_task_comm() that the previous patch removed? ... > +/* > + * Copy task name to a buffer. Final result is always a NUL-terminated s= tring. > + */ > +#define copy_task_comm(dst, tsk, len) \ > +{ \ > + const char *_src =3D (tsk)->comm; \ > + size_t _dst_len =3D len + __must_be_array(dst), If you are using __must_be_array() then why not use sizeof to get the _dst_= len? > + _src_len =3D sizeof(_src); \ Isn't sizeof(_src) just the size of a pointer? You need to use sizeof (tsk)->comm > + char *_dst =3D dst; \ > + \ > + if (_dst_len <=3D _src_len) { \ > + memcpy(_dst, _src, _dst_len); \ > + dst[_dst_len - 1] =3D '\0'; \ If the lengths are equal you don't need to write the '\0'. (and they should really both be compile time constants.) > + } else { \ > + strscpy_pad(_dst, _src, _dst_len); \ > + } \ If you do the memcpy() the bytes after the first '\0' aren't guaranteed to be '\0' - then can be random (usually part of an old version of the task na= me). So I'm not sure the strscpy_pad() path is needed. The most you might want to do is memset() the extra bytes. But are there ever any???? There will be code that copies the task->comm to a short buffer, but are there any places where it actually gets copied to a longer one - if so why? David