From nobody Thu Dec 18 20:15:01 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 7F3B024A043 for ; Thu, 13 Feb 2025 19:54:40 +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=1739476483; cv=none; b=AYdRP4vPEoQDbTF3BnTIHCpiPLV3r6mQA20OzENnpPZaemLFUGRVte+p8uJKvh0Bl6YNdEYTr3/nuGZn7dY0gj6stFalAjH08N/QaZeQTTCq7ZFoMY67+SMR3CUZlUPumklKFmGuN1gNUa91qBSBVoAzxV7jsqdEwQyeALAc9kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476483; c=relaxed/simple; bh=DTFVmRKr/sRy0lujQpNPmaprPhJHgvIYAyhefq5wfhs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=pxOlSBTx5DFsESNr7zJWkBXUm8S7qmFFVd+Fr+JjCpjDizZKqXx7M0W7yGX2gOl1R2/x8jcKiI8EJOfVLG4OxRsBfg9bKcQbhJtayHRZ1uEKCQKLtryZH4HHfJrds7WrLSIZekBtb82XsjvMjxzaPITloUpfHaUYhBDmF1x8tuQ= 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=MOnFxECN; 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="MOnFxECN" 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=1739476468; 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=239vtdGQF+N49EPmM+HoBTCJVsqE4ZMPXJ8M+TXlAZE=; b=MOnFxECN+fL3mGdpw0PfKGtjVpIR4qzFZJS7s8hkyHScierwD8RT5IOCC+peRMIAn5bd5H 2tdgaamZDqpnENViNDU1Z/nXuJwm+1gc7EAMeh9HYFs8ysNcZQ96oZNIRhq/FTYmwItStz uQI1aqFVR0zrKrSY3aXWuNab62/AcWk= From: Thorsten Blum To: Don Brace , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Thorsten Blum , linux-hardening@vger.kernel.org, Bart Van Assche , storagedev@microchip.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] scsi: hpsa: Replace deprecated strncpy() with strscpy() Date: Thu, 13 Feb 2025 20:53:33 +0100 Message-ID: <20250213195332.1464-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" strncpy() is deprecated for NUL-terminated destination buffers. Use strscpy() instead and remove the manual NUL-termination. Use min() to simplify the size calculation. Compile-tested only. Link: https://github.com/KSPP/linux/issues/90 Cc: linux-hardening@vger.kernel.org Suggested-by: Bart Van Assche Signed-off-by: Thorsten Blum --- Changes in v2: - Adjust len to copy the same number of bytes as with strncpy() - Link to v1: https://lore.kernel.org/r/34BB4FDE-062D-4C1B-B246-86CB55F631B= 8@linux.dev/ --- drivers/scsi/hpsa.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 84d8de07b7ae..c7ebae24b09f 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c @@ -460,9 +460,8 @@ static ssize_t host_store_hp_ssd_smart_path_status(stru= ct device *dev, =20 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; - len =3D count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; - strncpy(tmpbuf, buf, len); - tmpbuf[len] =3D '\0'; + len =3D min(count + 1, sizeof(tmpbuf)); + strscpy(tmpbuf, buf, len); if (sscanf(tmpbuf, "%d", &status) !=3D 1) return -EINVAL; h =3D shost_to_hba(shost); @@ -484,9 +483,8 @@ static ssize_t host_store_raid_offload_debug(struct dev= ice *dev, =20 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) return -EACCES; - len =3D count > sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count; - strncpy(tmpbuf, buf, len); - tmpbuf[len] =3D '\0'; + len =3D min(count + 1, sizeof(tmpbuf)); + strscpy(tmpbuf, buf, len); if (sscanf(tmpbuf, "%d", &debug_level) !=3D 1) return -EINVAL; if (debug_level < 0) --=20 2.48.1