From patchwork Tue Mar 5 23:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13583098 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 4369712E1C5 for ; Tue, 5 Mar 2024 23:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709681688; cv=none; b=pVWYORPFTboZhIyNQW6pLalAZ1QkmwyegkVBkoVNBrELpCCVU4YE8/4qI5KqIILfZdSnDWKO9fnr8VDgw/x8RBf7DwidbURyT2hrJYUMed2ASipmdQ2k+7br/jIrEvTk1ucqdTvBN3DgahiXAwA/ckCTeHZF618q4KyysrveTsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709681688; c=relaxed/simple; bh=oKHJz8KX639JHaY4FxkGeuRgysM8ixCYP31PDePvR/I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=B5qB/cPyJB1FSrB3lBPPYydbnH6E+TH3l9EYXoNPpSFsMFG6sxVwmQei8obnh30HRoKbsKS8/Hy4AQN6xzjeOA+i/78AlOWXg2BD8sF8AkpEzu7CQx6R1efJgd1MoiK4xSfvY3NvJ40+nzOXztdGyIZYojXjjmKA78h7xhCA39w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ht2ltYkY; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ht2ltYkY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60948e99cd4so96416567b3.1 for ; Tue, 05 Mar 2024 15:34:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709681684; x=1710286484; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=R/Gd0jRGfWXRd5LSFgmnGhf286BOGmU7x4htLcq4bds=; b=ht2ltYkYovKDw+rkhfKf8Wo+0OReFa20ICI9kZuXwFDMwVBueoyUI2Co2xDjAT9IYI lDc6J1WERayjV/yvNVmXpUSk87eJjeHbTTQYQM2IuRmRqh5cD3DmgEaSLNpzUZ0Zohx3 94mzdXh9Tnpu2qyEAQJvnTjScRK8M2LbLg0/sT+DkfrsKFn9tnhUvuuBzkXhHZEI5ifV /tfgs2mMWdRuoqTbhcQeXrKvn6nFJkPGNPJL3kcIHPgJbU+e42nQAmcTcYfCZNIxrnyV 8rY5yq8cB8M5gerkAwrXS4tKg2FbeTf1dW9BW/413/2T9IC4K1EoOUrEjsGb5nRTp2Ck Jq6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709681684; x=1710286484; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R/Gd0jRGfWXRd5LSFgmnGhf286BOGmU7x4htLcq4bds=; b=DEcK0XVEzrq4cRoeLmI+o6Ranfqkc/LlZGoAo4KO53fw6SsjyvbWsVhTk82e4CyXJe Ib1mvaqjQdmZVI/xi7AgyoKW7Q60tJ/EsmrhpceGy8/IeZpL6dxoGW5ii5ms+Qb7jr+K EcTHsC4bRXvDT7yHBdO1Nf5o0a8Wz3bA4GOvCt8pPQ1EhZkrnzCqkwROcXDVMZhWKd1N /llqlhA8SB5ktxkurma0DeHpL3Ov3OOBW8Y7JjeA4PQzVN/rK6sJspOnBjPf/FVZrh/3 c3+0hzRhcN38JQVAwPDGtzaStfNxmL+17pIDDu0Io433bv/MkE0nMRYMzXOV7YQvc3n2 //Dw== X-Forwarded-Encrypted: i=1; AJvYcCUDzQ3PjABb+9Ydp9Yzn3U0ihXaMFu5lMWtwRWznBb8b2jZle4YCG+jiCsbXolA6VSVfccBAicJl6sMlVlzrDC2Qk60DsZKDEQ3d94Uxw1z X-Gm-Message-State: AOJu0YwZQNku2yO9OiILwWa8mZJafZoLxTUgNGzLyU20NclHd8Op9Vbl pzdtCvRQ5HF293DHBcKWSILR5BT13hZbP32QBmLFQGDYNFrgq3/j2+CA4VZZg26b/ESXaOA3cCf +YA4oByWVZVo7W8s8mQnOMQ== X-Google-Smtp-Source: AGHT+IGAp9/lowPpevoGgxO6AVRrNKa1EDrxjPg50w1kHJVDcThAxX6KQnG119Aw9qN/A+OBNDlix25FOCb265goww== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:7947:0:b0:609:359a:9313 with SMTP id u68-20020a817947000000b00609359a9313mr2995157ywc.1.1709681684397; Tue, 05 Mar 2024 15:34:44 -0800 (PST) Date: Tue, 05 Mar 2024 23:34:38 +0000 In-Reply-To: <20240305-strncpy-drivers-scsi-mpi3mr-mpi3mr_fw-c-v3-0-5b78a13ff984@google.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240305-strncpy-drivers-scsi-mpi3mr-mpi3mr_fw-c-v3-0-5b78a13ff984@google.com> X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1709681680; l=2333; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=oKHJz8KX639JHaY4FxkGeuRgysM8ixCYP31PDePvR/I=; b=it20B8oEmrPPFj34tDnAo4Ojh4hPjBzwi2qKfmpt/w+DdvBX6HYJceOYTm/Cy2VY/qxpBA2UD lqH/vh4t55GDuJiu/Zvhhq9hXwO+V8wMcpojq7qCbWnxBJHE5ZwhMEb X-Mailer: b4 0.12.3 Message-ID: <20240305-strncpy-drivers-scsi-mpi3mr-mpi3mr_fw-c-v3-3-5b78a13ff984@google.com> Subject: [PATCH v3 3/7] scsi: qedf: replace deprecated strncpy with strscpy From: Justin Stitt To: Sathya Prakash Veerichetty , Kashyap Desai , Sumit Saxena , Sreekanth Reddy , "James E.J. Bottomley" , "Martin K. Petersen" , Suganath Prabu Subramani , Ariel Elior , Manish Chopra , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Saurav Kashyap , Javed Hasan , GR-QLogic-Storage-Upstream@marvell.com, Nilesh Javali , Manish Rangankar , Don Brace Cc: mpi3mr-linuxdrv.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Kees Cook , MPT-FusionLinux.pdl@broadcom.com, netdev@vger.kernel.org, storagedev@microchip.com, Justin Stitt We expect slowpath_params.name to be NUL-terminated based on its future usage with other string APIs: | static int qed_slowpath_start(struct qed_dev *cdev, | struct qed_slowpath_params *params) ... | strscpy(drv_version.name, params->name, | MCP_DRV_VER_STR_SIZE - 4); Moreover, NUL-padding is not necessary as the only use for this slowpath name parameter is to copy into the drv_version.name field. Also, let's prefer using strscpy(src, dest, sizeof(src)) in two instances (one of which is outside of the scsi system but it is trivial and related to this patch). We can see the drv_version.name size here: | struct qed_mcp_drv_version { | u32 version; | u8 name[MCP_DRV_VER_STR_SIZE - 4]; | }; Reviewed-by: Kees Cook Signed-off-by: Justin Stitt --- drivers/net/ethernet/qlogic/qed/qed_main.c | 2 +- drivers/scsi/qedf/qedf_main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c b/drivers/net/ethernet/qlogic/qed/qed_main.c index c278f8893042..d39e198fe8db 100644 --- a/drivers/net/ethernet/qlogic/qed/qed_main.c +++ b/drivers/net/ethernet/qlogic/qed/qed_main.c @@ -1351,7 +1351,7 @@ static int qed_slowpath_start(struct qed_dev *cdev, (params->drv_rev << 8) | (params->drv_eng); strscpy(drv_version.name, params->name, - MCP_DRV_VER_STR_SIZE - 4); + sizeof(drv_version.name)); rc = qed_mcp_send_drv_version(hwfn, hwfn->p_main_ptt, &drv_version); if (rc) { diff --git a/drivers/scsi/qedf/qedf_main.c b/drivers/scsi/qedf/qedf_main.c index a58353b7b4e8..fd12439cbaab 100644 --- a/drivers/scsi/qedf/qedf_main.c +++ b/drivers/scsi/qedf/qedf_main.c @@ -3468,7 +3468,7 @@ static int __qedf_probe(struct pci_dev *pdev, int mode) slowpath_params.drv_minor = QEDF_DRIVER_MINOR_VER; slowpath_params.drv_rev = QEDF_DRIVER_REV_VER; slowpath_params.drv_eng = QEDF_DRIVER_ENG_VER; - strncpy(slowpath_params.name, "qedf", QED_DRV_VER_STR_SIZE); + strscpy(slowpath_params.name, "qedf", sizeof(slowpath_params.name)); rc = qed_ops->common->slowpath_start(qedf->cdev, &slowpath_params); if (rc) { QEDF_ERR(&(qedf->dbg_ctx), "Cannot start slowpath.\n");