linux/drivers/scsi/libfc
Justin Stitt 3e24118ec1 scsi: libfc: replace deprecated strncpy() with memcpy()
strncpy() is deprecated [1] and as such we should use different apis to
copy string data.

We can see that ct is NUL-initialized with fc_ct_hdr_fill:
|       ct = fc_ct_hdr_fill(fp, op, sizeof(struct fc_ns_rspn) + len,
...

In fc_ct_hdr_fill():
|       memset(ct, 0, ct_plen);

We also calculate the length of the source string:
|       len = strnlen(fc_host_symbolic_name(lport->host), 255);

...then this argument is used in strncpy(), which is bad because the
pattern of (dest, src, strlen(src)) usually leaves the destination
buffer without NUL-termination. However, it looks as though we do not
require NUL-termination since fr_name is part of a seq_buf-like
structure wherein its length is monitored:
|       struct fc_ns_rspn {
|       	struct fc_ns_fid fr_fid;	/* port ID object */
|       	__u8		fr_name_len;
|       	char		fr_name[];
|       } __attribute__((__packed__));

So, this is really just a byte copy into a length-bounded buffer. Let's use
memcpy().

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240221-strncpy-drivers-scsi-libfc-fc_encode-h-v2-1-019a0889c5ca@google.com
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2024-02-26 21:21:23 -05:00
..
fc_disc.c scsi: libfc: Include the correct header 2022-12-01 03:03:36 +00:00
fc_elsct.c scsi: libfc: Move scsi/fc_encode.h to libfc 2020-10-29 21:49:25 -04:00
fc_encode.h scsi: libfc: replace deprecated strncpy() with memcpy() 2024-02-26 21:21:23 -05:00
fc_exch.c scsi: libfc: Remove get_cpu() semantics in fc_exch_em_alloc() 2022-05-16 21:26:50 -04:00
fc_fcp.c scsi: libfc: Map FC_TIMED_OUT to DID_TIME_OUT 2023-12-05 21:32:11 -05:00
fc_frame.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 335 2019-06-05 17:37:06 +02:00
fc_libfc.c scsi: libfc: Move scsi/fc_encode.h to libfc 2020-10-29 21:49:25 -04:00
fc_libfc.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 335 2019-06-05 17:37:06 +02:00
fc_lport.c scsi: libfc: Fix potential NULL pointer dereference in fc_lport_ptp_setup() 2023-10-13 14:15:54 -04:00
fc_npiv.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 335 2019-06-05 17:37:06 +02:00
fc_rport.c scsi: libfc: Fix array index out of bound exception 2021-06-28 22:31:16 -04:00
Makefile