* [PATCH] vmcore: replace strncpy with strtomem
@ 2024-03-27 21:10 ` Justin Stitt
0 siblings, 0 replies; 8+ messages in thread
From: Justin Stitt @ 2024-03-27 21:10 UTC (permalink / raw)
To: Baoquan He, Vivek Goyal, Dave Young
Cc: kexec, linux-kernel, linux-fsdevel, linux-hardening, Justin Stitt
strncpy() is in the process of being replaced as it is deprecated in
some situations [1]. While the specific use of strncpy that this patch
targets is not exactly deprecated, the real mission is to rid the kernel
of all its uses.
Looking at vmcoredd_header's definition:
| struct vmcoredd_header {
| __u32 n_namesz; /* Name size */
| __u32 n_descsz; /* Content size */
| __u32 n_type; /* NT_VMCOREDD */
| __u8 name[8]; /* LINUX\0\0\0 */
| __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
| };
... we can see that both `name` and `dump_name` are u8s. It seems `name`
wants to be NUL-padded (based on the comment above), but for the sake of
symmetry lets NUL-pad both of these.
Mark these buffers as __nonstring and use strtomem_pad.
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>
---
Note: build-tested only.
Found with: $ rg "strncpy\("
---
fs/proc/vmcore.c | 5 ++---
include/uapi/linux/vmcore.h | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 1fb213f379a5..5d7ecf3b75e8 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
vdd_hdr->n_type = NT_VMCOREDD;
- strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
- sizeof(vdd_hdr->name));
- memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
+ strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
+ strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
}
/**
diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
index 3e9da91866ff..7053e2b62fa0 100644
--- a/include/uapi/linux/vmcore.h
+++ b/include/uapi/linux/vmcore.h
@@ -11,8 +11,8 @@ struct vmcoredd_header {
__u32 n_namesz; /* Name size */
__u32 n_descsz; /* Content size */
__u32 n_type; /* NT_VMCOREDD */
- __u8 name[8]; /* LINUX\0\0\0 */
- __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
+ __u8 name[8] __nonstring; /* LINUX\0\0\0 */
+ __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
};
#endif /* _UAPI_VMCORE_H */
---
base-commit: 928a87efa42302a23bb9554be081a28058495f22
change-id: 20240327-strncpy-fs-proc-vmcore-c-b18d761feaef
Best regards,
--
Justin Stitt <justinstitt@google.com>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH] vmcore: replace strncpy with strtomem
@ 2024-03-27 21:10 ` Justin Stitt
0 siblings, 0 replies; 8+ messages in thread
From: Justin Stitt @ 2024-03-27 21:10 UTC (permalink / raw)
To: Baoquan He, Vivek Goyal, Dave Young
Cc: kexec, linux-kernel, linux-fsdevel, linux-hardening, Justin Stitt
strncpy() is in the process of being replaced as it is deprecated in
some situations [1]. While the specific use of strncpy that this patch
targets is not exactly deprecated, the real mission is to rid the kernel
of all its uses.
Looking at vmcoredd_header's definition:
| struct vmcoredd_header {
| __u32 n_namesz; /* Name size */
| __u32 n_descsz; /* Content size */
| __u32 n_type; /* NT_VMCOREDD */
| __u8 name[8]; /* LINUX\0\0\0 */
| __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
| };
... we can see that both `name` and `dump_name` are u8s. It seems `name`
wants to be NUL-padded (based on the comment above), but for the sake of
symmetry lets NUL-pad both of these.
Mark these buffers as __nonstring and use strtomem_pad.
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>
---
Note: build-tested only.
Found with: $ rg "strncpy\("
---
fs/proc/vmcore.c | 5 ++---
include/uapi/linux/vmcore.h | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 1fb213f379a5..5d7ecf3b75e8 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
vdd_hdr->n_type = NT_VMCOREDD;
- strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
- sizeof(vdd_hdr->name));
- memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
+ strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
+ strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
}
/**
diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
index 3e9da91866ff..7053e2b62fa0 100644
--- a/include/uapi/linux/vmcore.h
+++ b/include/uapi/linux/vmcore.h
@@ -11,8 +11,8 @@ struct vmcoredd_header {
__u32 n_namesz; /* Name size */
__u32 n_descsz; /* Content size */
__u32 n_type; /* NT_VMCOREDD */
- __u8 name[8]; /* LINUX\0\0\0 */
- __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
+ __u8 name[8] __nonstring; /* LINUX\0\0\0 */
+ __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
};
#endif /* _UAPI_VMCORE_H */
---
base-commit: 928a87efa42302a23bb9554be081a28058495f22
change-id: 20240327-strncpy-fs-proc-vmcore-c-b18d761feaef
Best regards,
--
Justin Stitt <justinstitt@google.com>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
2024-03-27 21:10 ` Justin Stitt
@ 2024-03-28 1:48 ` Baoquan He
-1 siblings, 0 replies; 8+ messages in thread
From: Baoquan He @ 2024-03-28 1:48 UTC (permalink / raw)
To: Justin Stitt
Cc: Vivek Goyal, Dave Young, kexec, linux-kernel, linux-fsdevel,
linux-hardening
On 03/27/24 at 09:10pm, Justin Stitt wrote:
> strncpy() is in the process of being replaced as it is deprecated in
> some situations [1]. While the specific use of strncpy that this patch
> targets is not exactly deprecated, the real mission is to rid the kernel
> of all its uses.
>
> Looking at vmcoredd_header's definition:
> | struct vmcoredd_header {
> | __u32 n_namesz; /* Name size */
> | __u32 n_descsz; /* Content size */
> | __u32 n_type; /* NT_VMCOREDD */
> | __u8 name[8]; /* LINUX\0\0\0 */
> | __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> | };
> ... we can see that both `name` and `dump_name` are u8s. It seems `name`
> wants to be NUL-padded (based on the comment above), but for the sake of
> symmetry lets NUL-pad both of these.
>
> Mark these buffers as __nonstring and use strtomem_pad.
Thanks.
I didn't build, wondering if '__nonstring' has to be set so that
strtomem_pad() can be used.
Thanks
Baoquan
>
> 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>
> ---
> Note: build-tested only.
>
> Found with: $ rg "strncpy\("
> ---
> fs/proc/vmcore.c | 5 ++---
> include/uapi/linux/vmcore.h | 4 ++--
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 1fb213f379a5..5d7ecf3b75e8 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
> vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
> vdd_hdr->n_type = NT_VMCOREDD;
>
> - strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
> - sizeof(vdd_hdr->name));
> - memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
> + strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
> + strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
> }
>
> /**
> diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
> index 3e9da91866ff..7053e2b62fa0 100644
> --- a/include/uapi/linux/vmcore.h
> +++ b/include/uapi/linux/vmcore.h
> @@ -11,8 +11,8 @@ struct vmcoredd_header {
> __u32 n_namesz; /* Name size */
> __u32 n_descsz; /* Content size */
> __u32 n_type; /* NT_VMCOREDD */
> - __u8 name[8]; /* LINUX\0\0\0 */
> - __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> + __u8 name[8] __nonstring; /* LINUX\0\0\0 */
> + __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
> };
>
> #endif /* _UAPI_VMCORE_H */
>
> ---
> base-commit: 928a87efa42302a23bb9554be081a28058495f22
> change-id: 20240327-strncpy-fs-proc-vmcore-c-b18d761feaef
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
@ 2024-03-28 1:48 ` Baoquan He
0 siblings, 0 replies; 8+ messages in thread
From: Baoquan He @ 2024-03-28 1:48 UTC (permalink / raw)
To: Justin Stitt
Cc: Vivek Goyal, Dave Young, kexec, linux-kernel, linux-fsdevel,
linux-hardening
On 03/27/24 at 09:10pm, Justin Stitt wrote:
> strncpy() is in the process of being replaced as it is deprecated in
> some situations [1]. While the specific use of strncpy that this patch
> targets is not exactly deprecated, the real mission is to rid the kernel
> of all its uses.
>
> Looking at vmcoredd_header's definition:
> | struct vmcoredd_header {
> | __u32 n_namesz; /* Name size */
> | __u32 n_descsz; /* Content size */
> | __u32 n_type; /* NT_VMCOREDD */
> | __u8 name[8]; /* LINUX\0\0\0 */
> | __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> | };
> ... we can see that both `name` and `dump_name` are u8s. It seems `name`
> wants to be NUL-padded (based on the comment above), but for the sake of
> symmetry lets NUL-pad both of these.
>
> Mark these buffers as __nonstring and use strtomem_pad.
Thanks.
I didn't build, wondering if '__nonstring' has to be set so that
strtomem_pad() can be used.
Thanks
Baoquan
>
> 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>
> ---
> Note: build-tested only.
>
> Found with: $ rg "strncpy\("
> ---
> fs/proc/vmcore.c | 5 ++---
> include/uapi/linux/vmcore.h | 4 ++--
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 1fb213f379a5..5d7ecf3b75e8 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
> vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
> vdd_hdr->n_type = NT_VMCOREDD;
>
> - strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
> - sizeof(vdd_hdr->name));
> - memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
> + strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
> + strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
> }
>
> /**
> diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
> index 3e9da91866ff..7053e2b62fa0 100644
> --- a/include/uapi/linux/vmcore.h
> +++ b/include/uapi/linux/vmcore.h
> @@ -11,8 +11,8 @@ struct vmcoredd_header {
> __u32 n_namesz; /* Name size */
> __u32 n_descsz; /* Content size */
> __u32 n_type; /* NT_VMCOREDD */
> - __u8 name[8]; /* LINUX\0\0\0 */
> - __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> + __u8 name[8] __nonstring; /* LINUX\0\0\0 */
> + __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
> };
>
> #endif /* _UAPI_VMCORE_H */
>
> ---
> base-commit: 928a87efa42302a23bb9554be081a28058495f22
> change-id: 20240327-strncpy-fs-proc-vmcore-c-b18d761feaef
>
> Best regards,
> --
> Justin Stitt <justinstitt@google.com>
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
2024-03-28 1:48 ` Baoquan He
@ 2024-03-28 20:42 ` Justin Stitt
-1 siblings, 0 replies; 8+ messages in thread
From: Justin Stitt @ 2024-03-28 20:42 UTC (permalink / raw)
To: Baoquan He
Cc: Vivek Goyal, Dave Young, kexec, linux-kernel, linux-fsdevel,
linux-hardening
Hi,
On Wed, Mar 27, 2024 at 6:48 PM Baoquan He <bhe@redhat.com> wrote:
> > Mark these buffers as __nonstring and use strtomem_pad.
>
> Thanks.
>
> I didn't build, wondering if '__nonstring' has to be set so that
> strtomem_pad() can be used.
I do not believe marking buffers as __nonstring is strictly a
requirement. However, the documentation from string.h +302 says we
should do it:
/**
* strtomem_pad - Copy NUL-terminated string to non-NUL-terminated buffer
*
* @dest: Pointer of destination character array (marked as __nonstring)
...
and so does [1] ... "mark the destination buffer variable (or
structure member) with the __nonstring attribute..."
FWIW, this builds just fine without the __nonstring attribute but we
should use it :)
>
> Thanks
> Baoquan
>
[1] https://github.com/KSPP/linux/issues/90
Thanks
Justin
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
@ 2024-03-28 20:42 ` Justin Stitt
0 siblings, 0 replies; 8+ messages in thread
From: Justin Stitt @ 2024-03-28 20:42 UTC (permalink / raw)
To: Baoquan He
Cc: Vivek Goyal, Dave Young, kexec, linux-kernel, linux-fsdevel,
linux-hardening
Hi,
On Wed, Mar 27, 2024 at 6:48 PM Baoquan He <bhe@redhat.com> wrote:
> > Mark these buffers as __nonstring and use strtomem_pad.
>
> Thanks.
>
> I didn't build, wondering if '__nonstring' has to be set so that
> strtomem_pad() can be used.
I do not believe marking buffers as __nonstring is strictly a
requirement. However, the documentation from string.h +302 says we
should do it:
/**
* strtomem_pad - Copy NUL-terminated string to non-NUL-terminated buffer
*
* @dest: Pointer of destination character array (marked as __nonstring)
...
and so does [1] ... "mark the destination buffer variable (or
structure member) with the __nonstring attribute..."
FWIW, this builds just fine without the __nonstring attribute but we
should use it :)
>
> Thanks
> Baoquan
>
[1] https://github.com/KSPP/linux/issues/90
Thanks
Justin
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
2024-03-27 21:10 ` Justin Stitt
@ 2024-03-28 22:03 ` Kees Cook
-1 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2024-03-28 22:03 UTC (permalink / raw)
To: Justin Stitt
Cc: Baoquan He, Vivek Goyal, Dave Young, kexec, linux-kernel,
linux-fsdevel, linux-hardening
On Wed, Mar 27, 2024 at 09:10:52PM +0000, Justin Stitt wrote:
> strncpy() is in the process of being replaced as it is deprecated in
> some situations [1]. While the specific use of strncpy that this patch
> targets is not exactly deprecated, the real mission is to rid the kernel
> of all its uses.
>
> Looking at vmcoredd_header's definition:
> | struct vmcoredd_header {
> | __u32 n_namesz; /* Name size */
> | __u32 n_descsz; /* Content size */
> | __u32 n_type; /* NT_VMCOREDD */
> | __u8 name[8]; /* LINUX\0\0\0 */
> | __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> | };
> ... we can see that both `name` and `dump_name` are u8s. It seems `name`
> wants to be NUL-padded (based on the comment above), but for the sake of
> symmetry lets NUL-pad both of these.
Do we have a way to know that dump_name is not parsed by userspace as a
NUL-terminated string?
>
> Mark these buffers as __nonstring and use strtomem_pad.
>
> 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>
> ---
> Note: build-tested only.
>
> Found with: $ rg "strncpy\("
> ---
> fs/proc/vmcore.c | 5 ++---
> include/uapi/linux/vmcore.h | 4 ++--
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 1fb213f379a5..5d7ecf3b75e8 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
> vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
> vdd_hdr->n_type = NT_VMCOREDD;
>
> - strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
> - sizeof(vdd_hdr->name));
> - memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
> + strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
> + strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
> }
>
> /**
> diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
> index 3e9da91866ff..7053e2b62fa0 100644
> --- a/include/uapi/linux/vmcore.h
> +++ b/include/uapi/linux/vmcore.h
> @@ -11,8 +11,8 @@ struct vmcoredd_header {
> __u32 n_namesz; /* Name size */
> __u32 n_descsz; /* Content size */
> __u32 n_type; /* NT_VMCOREDD */
> - __u8 name[8]; /* LINUX\0\0\0 */
> - __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> + __u8 name[8] __nonstring; /* LINUX\0\0\0 */
> + __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
> };
Unfortunately since this is UAPI, we can't sanely use __nonstring here.
:(
--
Kees Cook
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] vmcore: replace strncpy with strtomem
@ 2024-03-28 22:03 ` Kees Cook
0 siblings, 0 replies; 8+ messages in thread
From: Kees Cook @ 2024-03-28 22:03 UTC (permalink / raw)
To: Justin Stitt
Cc: Baoquan He, Vivek Goyal, Dave Young, kexec, linux-kernel,
linux-fsdevel, linux-hardening
On Wed, Mar 27, 2024 at 09:10:52PM +0000, Justin Stitt wrote:
> strncpy() is in the process of being replaced as it is deprecated in
> some situations [1]. While the specific use of strncpy that this patch
> targets is not exactly deprecated, the real mission is to rid the kernel
> of all its uses.
>
> Looking at vmcoredd_header's definition:
> | struct vmcoredd_header {
> | __u32 n_namesz; /* Name size */
> | __u32 n_descsz; /* Content size */
> | __u32 n_type; /* NT_VMCOREDD */
> | __u8 name[8]; /* LINUX\0\0\0 */
> | __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> | };
> ... we can see that both `name` and `dump_name` are u8s. It seems `name`
> wants to be NUL-padded (based on the comment above), but for the sake of
> symmetry lets NUL-pad both of these.
Do we have a way to know that dump_name is not parsed by userspace as a
NUL-terminated string?
>
> Mark these buffers as __nonstring and use strtomem_pad.
>
> 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>
> ---
> Note: build-tested only.
>
> Found with: $ rg "strncpy\("
> ---
> fs/proc/vmcore.c | 5 ++---
> include/uapi/linux/vmcore.h | 4 ++--
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
> index 1fb213f379a5..5d7ecf3b75e8 100644
> --- a/fs/proc/vmcore.c
> +++ b/fs/proc/vmcore.c
> @@ -1370,9 +1370,8 @@ static void vmcoredd_write_header(void *buf, struct vmcoredd_data *data,
> vdd_hdr->n_descsz = size + sizeof(vdd_hdr->dump_name);
> vdd_hdr->n_type = NT_VMCOREDD;
>
> - strncpy((char *)vdd_hdr->name, VMCOREDD_NOTE_NAME,
> - sizeof(vdd_hdr->name));
> - memcpy(vdd_hdr->dump_name, data->dump_name, sizeof(vdd_hdr->dump_name));
> + strtomem_pad(vdd_hdr->name, VMCOREDD_NOTE_NAME, 0);
> + strtomem_pad(vdd_hdr->dump_name, data->dump_name, 0);
> }
>
> /**
> diff --git a/include/uapi/linux/vmcore.h b/include/uapi/linux/vmcore.h
> index 3e9da91866ff..7053e2b62fa0 100644
> --- a/include/uapi/linux/vmcore.h
> +++ b/include/uapi/linux/vmcore.h
> @@ -11,8 +11,8 @@ struct vmcoredd_header {
> __u32 n_namesz; /* Name size */
> __u32 n_descsz; /* Content size */
> __u32 n_type; /* NT_VMCOREDD */
> - __u8 name[8]; /* LINUX\0\0\0 */
> - __u8 dump_name[VMCOREDD_MAX_NAME_BYTES]; /* Device dump's name */
> + __u8 name[8] __nonstring; /* LINUX\0\0\0 */
> + __u8 dump_name[VMCOREDD_MAX_NAME_BYTES] __nonstring; /* Device dump's name */
> };
Unfortunately since this is UAPI, we can't sanely use __nonstring here.
:(
--
Kees Cook
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-03-28 22:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 21:10 [PATCH] vmcore: replace strncpy with strtomem Justin Stitt
2024-03-27 21:10 ` Justin Stitt
2024-03-28 1:48 ` Baoquan He
2024-03-28 1:48 ` Baoquan He
2024-03-28 20:42 ` Justin Stitt
2024-03-28 20:42 ` Justin Stitt
2024-03-28 22:03 ` Kees Cook
2024-03-28 22:03 ` Kees Cook
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.