From nobody Mon Jun 8 05:24:48 2026 Received: from mailtransmit05.runbox.com (mailtransmit05.runbox.com [185.226.149.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0706D24A076 for ; Sat, 6 Jun 2026 20:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.38 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780777622; cv=none; b=mQJv2gsCnfQvBlZIWsQOBJM0cN4hkIgmQi75zH7MIj6l9xX1LS5Gwjwkm5Xfg45hcrtvphrOeeLLxgUrEDdviHiPLGh2RYq9uNwr58dB2Q/qVINnB0uzJo/Nh1OkX6gDgjH/DGTdcz9LZOKbEvv+oukU0upxoCBAS/Gus9x736k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780777622; c=relaxed/simple; bh=/OcoZiJiWCr4pvTzofGANdRUxEA1k0LfbIXSeQvtSqo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Ps8sgwibgR3ce/wwU/qXfU+06FHSJDYLktrxMlv8HiQa3aODmftl5PX31UKRDyF/N8QhFev89nqxAtNt0i8Q/02i4pJ6pZjBRnJLaoa9la/atnrHDOtRiKKpSqPxm8TQt0pHMy9OkTP/LY4/pwG1YwyktNYtQCRGvU6bbPZUnbM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=runbox.com; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b=B2VldlYr; arc=none smtp.client-ip=185.226.149.38 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=runbox.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=runbox.com header.i=@runbox.com header.b="B2VldlYr" Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1wVxbV-007cBZ-Ng; Sat, 06 Jun 2026 22:26:49 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From; bh=OMfZOaaOtzLptKPrhdF2twX7AMe5ZC+9HNX6YGyz4D0=; b=B2Vldl Yrgonnw6FkliXLXtjQTlHzymlzTMNVwdqlB2zPnVj4Tdf8NrN2MTs/ZzqeWGBCk/XXKBEYVPqeNfL Fi5P4k62lJ8ULW/Nanm5eyR5I/+z/RhWxqM7FBuDLww6wrx1iPcYQzecfhmLJ7rNRr9133gEJW2HD o2Geth95QJTUIZbjOp0HNy4T/FUA9ZsEv2tv/JnXl4VJ6IJNuSM/akPswR+abVtMnXzE4a2msvawY BACiReOUosvxY0u3xhHFVjH9Adl4ifpmn/Xi6frxY7sCOYEdWWHHEparA1gRlhyH+t36Wk4oCK6HZ KGPKfpVODK1kp2gqKUJin1jxcmzg==; Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1wVxbV-0000sY-Bn; Sat, 06 Jun 2026 22:26:49 +0200 Received: by submission01.runbox with esmtpsa [Authenticated ID (1493616)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.95) id 1wVxbT-006V18-9S; Sat, 06 Jun 2026 22:26:47 +0200 From: david.laight.linux@gmail.com To: Kees Cook , linux-hardening@vger.kernel.org, Arnd Bergmann , driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , David Laight Subject: [PATCH next] driver core: Replace strcpy() with memcpy() Date: Sat, 6 Jun 2026 21:25:55 +0100 Message-Id: <20260606202633.5018-1-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight The length of the string is calculated in order to allocate the correct sized memory block, use the same length to copy in the string. Signed-off-by: David Laight --- This is one of a group of patches that remove potentially unbounded strcpy() calls. They are mostly replaced by strscpy() or, when strlen() has just been called, with memcpy() (usually including the '\0'). Calls with copy string literals into arrays are left unchanged. They are safe and easily detected as such. The changes were made by getting the compiler to detect the calls and then fixing the code by hand. Note that all the changes are only compile tested. Some Makefiles were changed to allow files to contain strcpy(). As well as 'difficult to fix' files, this included 'show' functions as they really need to use sysfs_emit() or seq_printf(). All the patches are being sent individually to avoid very long cc lists. Apologies for the terse commit messages and likely unexpected tags. (There are about 100 patches in total.) drivers/base/platform.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 75b4698d0e58..63fdfffe1a8c 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -617,10 +617,11 @@ static void platform_device_release(struct device *de= v) struct platform_device *platform_device_alloc(const char *name, int id) { struct platform_object *pa; + size_t len =3D strlen(name); =20 - pa =3D kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL); + pa =3D kzalloc(sizeof(*pa) + len + 1, GFP_KERNEL); if (pa) { - strcpy(pa->name, name); + memcpy(pa->name, name, len); pa->pdev.name =3D pa->name; pa->pdev.id =3D id; device_initialize(&pa->pdev.dev); --=20 2.39.5