target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: James Smart <james.smart@broadcom.com>,
	Ram Vegesna <ram.vegesna@broadcom.com>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-hardening@vger.kernel.org, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: elx: sli4: Replace deprecated strncpy() with strscpy()
Date: Mon, 7 Apr 2025 11:28:32 -0700	[thread overview]
Message-ID: <202504071126.37117C5D@keescook> (raw)
In-Reply-To: <20250226185531.1092-2-thorsten.blum@linux.dev>

On Wed, Feb 26, 2025 at 07:55:26PM +0100, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers; use
> strscpy() instead.
> 
> Compile-tested only.
> 
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/scsi/elx/libefc_sli/sli4.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/elx/libefc_sli/sli4.c b/drivers/scsi/elx/libefc_sli/sli4.c
> index 5e7fb110bc3f..d9a231fc0e0d 100644
> --- a/drivers/scsi/elx/libefc_sli/sli4.c
> +++ b/drivers/scsi/elx/libefc_sli/sli4.c
> @@ -3804,7 +3804,7 @@ sli_cmd_common_write_object(struct sli4 *sli4, void *buf, u16 noc,
>  	wr_obj->desired_write_len_dword = cpu_to_le32(dwflags);
>  
>  	wr_obj->write_offset = cpu_to_le32(offset);
> -	strncpy(wr_obj->object_name, obj_name, sizeof(wr_obj->object_name) - 1);
> +	strscpy(wr_obj->object_name, obj_name);

Standard question for these kinds of conversions: Why is it safe that
this is not NUL padded? I haven't found where this buffer is being
zeroed out, but it probably is (given the "- 1" on the length), but
without run-time testing, this needs much more careful analysis.

-Kees

>  	wr_obj->host_buffer_descriptor_count = cpu_to_le32(1);
>  
>  	bde = (struct sli4_bde *)wr_obj->host_buffer_descriptor;
> @@ -3833,7 +3833,7 @@ sli_cmd_common_delete_object(struct sli4 *sli4, void *buf, char *obj_name)
>  			 SLI4_SUBSYSTEM_COMMON, CMD_V0,
>  			 SLI4_RQST_PYLD_LEN(cmn_delete_object));
>  
> -	strncpy(req->object_name, obj_name, sizeof(req->object_name) - 1);
> +	strscpy(req->object_name, obj_name);
>  	return 0;
>  }
>  
> @@ -3856,7 +3856,7 @@ sli_cmd_common_read_object(struct sli4 *sli4, void *buf, u32 desired_read_len,
>  		cpu_to_le32(desired_read_len & SLI4_REQ_DESIRE_READLEN);
>  
>  	rd_obj->read_offset = cpu_to_le32(offset);
> -	strncpy(rd_obj->object_name, obj_name, sizeof(rd_obj->object_name) - 1);
> +	strscpy(rd_obj->object_name, obj_name);
>  	rd_obj->host_buffer_descriptor_count = cpu_to_le32(1);
>  
>  	bde = (struct sli4_bde *)rd_obj->host_buffer_descriptor;
> -- 
> 2.48.1
> 

-- 
Kees Cook

  reply	other threads:[~2025-04-07 18:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 18:55 [PATCH] scsi: elx: sli4: Replace deprecated strncpy() with strscpy() Thorsten Blum
2025-04-07 18:28 ` Kees Cook [this message]
2025-04-07 19:01   ` Thorsten Blum
2025-04-07 20:30     ` Kees Cook
2025-04-07 20:53       ` Thorsten Blum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202504071126.37117C5D@keescook \
    --to=kees@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=james.smart@broadcom.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=ram.vegesna@broadcom.com \
    --cc=target-devel@vger.kernel.org \
    --cc=thorsten.blum@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).