From nobody Sun Dec 14 12:06:26 2025 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (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 DD3BA1AF0C8 for ; Sat, 19 Apr 2025 11:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745063017; cv=none; b=FqAgKaiSLn927uIS/lUs+5TxsgpEUIZ0AzJy6LljWrSoIWFkJufubN1ie84kHjmy09/ERjtM7aXMZN9rTaoupWsaOHWrBS4V4y1iMbi/4YMmhNjKv8c+8V5OvN5shdQd5N5mh3GcId9AFIQU25YzW7KR+lJSUg9sOYUw7s5fUxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745063017; c=relaxed/simple; bh=TUleW9KRGX0FGrCbp8T9MpS2ex+KPStgayd09seZX9k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=r3A3M5/swW2g8rX41Z/z0QaJnqFVEsF+ri1jnTbaxzUgDhnvVOOpgkn5tlNkRmnffzoQT1iDxE+43A/lP9G/UmPAELpQm32L8vXIH0OM19DMl1+syMCckAc5Z78tQy5FDIRWj18EPutwMMNKapg3pe/lD7vyAYAQDv2B4CBwOwI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=blwLTlLt; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="blwLTlLt" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1745063000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QowPVoBoSNnEHK0cULG/V4c+a1cIPM2plKANNmK/tiU=; b=blwLTlLtzlO6QHzgtCzVoPdEcKjZ9Iwa+POC7b+NgZOj9Ttmk+F2LvFhqK5C60dHGJTt/u ij3VB7YvmsEO5Mt4gAUVl7FAh3lHuQ6VAhNR2LI0MmdiI1DoSfy7Ahd6jNshsjXH5BWoAc uGoFUo+a/cHAsu3IiMHRMOUGH/daJ0g= From: Thorsten Blum To: Richard Henderson , Matt Turner , Arnd Bergmann , Al Viro , Geert Uytterhoeven , "Mike Rapoport (Microsoft)" , Guo Weikang Cc: Thorsten Blum , linux-hardening@vger.kernel.org, Andrew Morton , "Paul E. McKenney" , Alexander Gordeev , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] alpha: Replace sprintf()/strcpy() with scnprintf()/strscpy() Date: Sat, 19 Apr 2025 13:40:11 +0200 Message-ID: <20250419114011.164512-3-thorsten.blum@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Replace sprintf() with the safer variant scnprintf() and use its return value instead of calculating the string length again using strlen(). Use strscpy() instead of the deprecated strcpy(). No functional changes intended. Link: https://github.com/KSPP/linux/issues/88 Cc: linux-hardening@vger.kernel.org Signed-off-by: Thorsten Blum --- arch/alpha/kernel/core_marvel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/alpha/kernel/core_marvel.c b/arch/alpha/kernel/core_marve= l.c index b1bfbd11980d..d38f4d6759e4 100644 --- a/arch/alpha/kernel/core_marvel.c +++ b/arch/alpha/kernel/core_marvel.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -79,10 +80,12 @@ mk_resource_name(int pe, int port, char *str) { char tmp[80]; char *name; -=09 - sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port); - name =3D memblock_alloc_or_panic(strlen(tmp) + 1, SMP_CACHE_BYTES); - strcpy(name, tmp); + size_t sz; + + sz =3D scnprintf(tmp, sizeof(tmp), "PCI %s PE %d PORT %d", str, pe, port); + sz +=3D 1; /* NUL terminator */ + name =3D memblock_alloc_or_panic(sz, SMP_CACHE_BYTES); + strscpy(name, tmp, sz); =20 return name; } --=20 2.49.0