Skip to content

Commit 0fc6ff5

Browse files
JustinStittjgross1
authored andcommitted
xen/efi: refactor deprecated strncpy
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. `efi_loader_signature` has space for 4 bytes. We are copying "Xen" (3 bytes) plus a NUL-byte which makes 4 total bytes. With that being said, there is currently not a bug with the current `strncpy()` implementation in terms of buffer overreads but we should favor a more robust string interface either way. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer while being functionally the same in this case. Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Cc: linux-hardening@vger.kernel.org Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Justin Stitt <justinstitt@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230911-strncpy-arch-x86-xen-efi-c-v1-1-96ab2bba2feb@google.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 49147be commit 0fc6ff5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/xen/efi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void __init xen_efi_init(struct boot_params *boot_params)
138138
if (efi_systab_xen == NULL)
139139
return;
140140

141-
strncpy((char *)&boot_params->efi_info.efi_loader_signature, "Xen",
141+
strscpy((char *)&boot_params->efi_info.efi_loader_signature, "Xen",
142142
sizeof(boot_params->efi_info.efi_loader_signature));
143143
boot_params->efi_info.efi_systab = (__u32)__pa(efi_systab_xen);
144144
boot_params->efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32);

0 commit comments

Comments
 (0)