Introduce new wrappers to copy user-arrays
Subsystems (7)
cover Introduce new wrappers to copy user-arrays
Hi!
David Airlie suggested that we could implement new wrappers around (v)memdup_user() for duplicating user arrays.
This small patch series first implements the two new wrapper functions memdup_array_user() and vmemdup_array_user(). They calculate the array-sizes safely, i.e., they return an error in case of an overflow.
It then implements the new wrappers in two components in kernel/ and two in the drm-subsystem.
In total, there are 18 files in the kernel that use (v)memdup_user() to duplicate arrays. My plan is to provide patches for the other 14 successively once this series has been merged.
P.
Philipp Stanner (5):
string.h: add array-wrappers for (v)memdup_user()
kernel: kexec: copy user-array safely
kernel: watch_queue: copy user-array safely drm_lease.c: copy user-array safely
drm: vmgfx_surface.c: copy user-array safely
drivers/gpu/drm/drm_lease.c | 4 +-- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 +-- include/linux/string.h | 42 +++++++++++++++++++++++++ kernel/kexec.c | 2 +- kernel/watch_queue.c | 2 +- 5 files changed, 48 insertions(+), 6 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/5 string.h: add array-wrappers for (v)memdup_user()
Currently, user array duplications are sometimes done without an overflow check. Sometimes the checks are done manually; sometimes the array size is calculated with array_size() and sometimes by calculating n * size directly in code.
Introduce wrappers for arrays for memdup_user() and vmemdup_user() to provide a standardized and safe way for duplicating user arrays.
This is both for new code as well as replacing usage of (v)memdup_user() in existing code that uses, e.g., n * size to calculate array sizes.
--- include/linux/string.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
include/linux/string.h +42 -0
@@ -6,6 +6,8 @@#include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */ +#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */ #include <linux/stdarg.h> #include <uapi/linux/string.h>
@@ -14,6 +16,46 @@ extern void *memdup_user(const void __user *, size_t);extern void *vmemdup_user (const void __user *,size_t );extern void *memdup_user_nul (const void __user *,size_t ); +/** +* memdup_array_user - duplicate array from user space +* +* @src: source address in user space +* @n: number of array members to copy +* @size: size of one array member +* +* Return: an ERR_PTR() on failure. Result is physically +* contiguous, to be freed by kfree(). +*/ +static inline void *memdup_array_user (const void __user *src,size_t n,size_t size) +{ +size_t nbytes; + +if (unlikely (check_mul_overflow (n, size, &nbytes))) +return ERR_PTR (-EINVAL ); + +return memdup_user (src, nbytes); +} + +/** +* vmemdup_array_user - duplicate array from user space +* +* @src: source address in user space +* @n: number of array members to copy +* @size: size of one array member +* +* Return: an ERR_PTR() on failure. Result may be not +* physically contiguous. Use kvfree() to free. +*/ +static inline void *vmemdup_array_user (const void __user *src,size_t n,size_t size) +{ +size_t nbytes; + +if (unlikely (check_mul_overflow (n, size, &nbytes))) +return ERR_PTR (-EINVAL ); + +return vmemdup_user (src, nbytes); +} +/* * Include machine specific inline routines */
Signature · 1 line
2.41.0
PATCH 2/5 kernel: kexec: copy user-array safely
In reply to Philipp StannerCurrently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely.
--- kernel/kexec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kexec.c +1 -1
@@ -242,7 +242,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, ((flags & KEXEC_ARCH_MASK) != KEXEC_ARCH_DEFAULT))return -EINVAL ; - ksegments =memdup_user (segments, nr_segments *sizeof (ksegments[0 ])); + ksegments =memdup_array_user (segments, nr_segments,sizeof (ksegments[0 ]));if (IS_ERR (ksegments))return PTR_ERR (ksegments);
Signature · 1 line
2.41.0
PATCH 3/5 kernel: watch_queue: copy user-array safely
In reply to Philipp StannerCurrently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely.
--- kernel/watch_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/watch_queue.c +1 -1
@@ -331,7 +331,7 @@ long watch_queue_set_filter(struct pipe_inode_info *pipe, filter.__reserved != 0)return -EINVAL ; - tf =memdup_user (_filter->filters, filter.nr_filters *sizeof (*tf)); + tf =memdup_array_user (_filter->filters, filter.nr_filters,sizeof (*tf));if (IS_ERR (tf))return PTR_ERR (tf);
Signature · 1 line
2.41.0
PATCH 4/5 drm_lease.c: copy user-array safely
In reply to Philipp StannerCurrently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely.
--- drivers/gpu/drm/drm_lease.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_lease.c +2 -2
@@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,/* Handle leased objects, if any */ idr_init (&leases);if (object_count !=0 ) { - object_ids =memdup_user (u64_to_user_ptr (cl->object_ids), -array_size (object_count,sizeof (__u32))); + object_ids =memdup_array_user (u64_to_user_ptr (cl->object_ids), + object_count,sizeof (__u32));if (IS_ERR (object_ids)) { ret =PTR_ERR (object_ids);idr_destroy (&leases);
Signature · 1 line
2.41.0
PATCH 5/5 drm: vmgfx_surface.c: copy user-array safely
In reply to Philipp StannerCurrently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for duplicating the user-space array safely.
--- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +2 -2
@@ -777,9 +777,9 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, sizeof(metadata->mip_levels)); metadata->num_sizes = num_sizes; metadata->sizes = -memdup_user ((struct drm_vmw_size __user *)(unsigned long ) +memdup_array_user ((struct drm_vmw_size __user *)(unsigned long ) req->size_addr, -sizeof (*metadata->sizes) * metadata->num_sizes); + metadata->num_sizes,sizeof (*metadata->sizes));if (IS_ERR (metadata->sizes)) { ret =PTR_ERR (metadata->sizes); goto out_no_sizes;
Signature · 7 lines
2.41.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to Philipp StannerQuoted 11 lines · Philipp Stanner
Currently, user array duplications are sometimes done without an overflow check. Sometimes the checks are done manually; sometimes the array size is calculated with
array_size()and sometimes by calculating n * size directly in code.Introduce wrappers for arrays for
memdup_user()andvmemdup_user()to provide a standardized and safe way for duplicating user arrays.This is both for new code as well as replacing usage of (v)memdup_user() in existing code that uses, e.g., n * size to calculate array sizes.
...
include/linux/string.h
Quoted 2 lines
include/linux/string.h +0
-0
I'm wondering if this has no side-effects as string.h/string.c IIRC is used also for early stages where some of the APIs are not available.
include/linux/string.h line 10
Quoted 6 lines
include/linux/string.h +2
-0@@ -6,6 +6,8 @@#include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */ +#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */
Can we preserve order (to some extent)?
Quoted 2 lines
include/linux/string.h +0
-0#include <linux/stdarg.h> #include <uapi/linux/string.h>
...
Quoted 4 lines
+/**
+ *memdup_array_user- duplicate array from user space+ *
Do we need this blank line?
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result is physically
+ * contiguous, to be freed bykfree().
+ */
...
Quoted 4 lines
+/**
+ *vmemdup_array_user- duplicate array from user space+ *
Redundant?
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result may be not
+ * physically contiguous. Usekvfree()to free.
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to Philipp Stannerinclude/linux/string.h extern void *memdup_user(const void __user *, size_t); · line 54
Quoted 5 lines · Philipp Stanner
include/linux/string.h +4
-0+if (unlikely (check_mul_overflow (n, size, &nbytes))) +return ERR_PTR (-EINVAL ); +if (unlikely (check_mul_overflow (n, size, &nbytes))) +return ERR_PTR (-EINVAL );
Btw, why not -EOVERFLOW ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to Andy ShevchenkoQuoted 28 lines · Andy Shevchenko
Quoted 16 lines · Philipp Stanner
Currently, user array duplications are sometimes done without an overflow check. Sometimes the checks are done manually; sometimes the
array size is calculated witharray_size()and sometimes by calculating
n * size directly in code.Introduce wrappers for arrays for
memdup_user()andvmemdup_user()to
provide a standardized and safe way for duplicating user arrays.This is both for new code as well as replacing usage of (v)memdup_user()
in existing code that uses, e.g., n * size to calculate array sizes....
include/linux/string.h
Quoted 2 lines
include/linux/string.h +0
-0I'm wondering if this has no side-effects as
string.h/string.cIIRC is
used also for early stages where some of the APIs are not available.
Quoted 8 lines
include/linux/string.h line 10
Quoted 6 lines
include/linux/string.h +2
-0@@ -6,6 +6,8 @@ #include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */ +#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */Can we preserve order (to some extent)?
Sure. I just put it there so the comments build a congruent block. Which order would you prefer?
Quoted 4 lines
include/linux/string.h line 12
Quoted 3 lines
include/linux/string.h +0
-0#include <linux/stdarg.h> #include <uapi/linux/string.h>
Quoted 8 lines
...
Quoted 4 lines
+/**
+ *memdup_array_user- duplicate array from user space+ *
Do we need this blank line?
I more or less directly copied the docstring format from the original functions (v)memdup_user() in mm/util.c
I guess this is common style?
Quoted 9 lines
Quoted 8 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result is physically
+ * contiguous, to be freed bykfree().
+ */
Quoted 8 lines
...
Quoted 4 lines
+/**
+ *vmemdup_array_user- duplicate array from user space+ *
Redundant?
No, there are two functions:
* memdup_array_user()
* vmemdup_array_user()
On the deeper layers they utilize kmalloc() or kvmalloc(), respectively.
Greetings,
P.
Quoted 9 lines
Quoted 8 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result may be not
+ * physically contiguous. Usekvfree()to free.
+ */
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
Quoted 5 lines · Philipp Stanner
+ if (
unlikely(check_mul_overflow(n, size, &nbytes))) + returnERR_PTR(-EINVAL);+ if (
unlikely(check_mul_overflow(n, size, &nbytes))) + returnERR_PTR(-EINVAL);Btw, why not
-EOVERFLOW?
Good question, actually.
To be honest I wasn't quite sure which code to pick (-E2BIG was also once I candidate).
-EINVAL was picked because the idea was that a request overflowing a size_t could surely be expected to contain an invalid parameter, because no one would ever request an array _that_ large
?
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to [email protected]Quoted 20 lines · On Wed, Aug 30, 2023 at 5:19 PM <[email protected]> wrote:
Quoted 10 lines · Andy Shevchenko
include/linux/string.h
Quoted 2 lines · Philipp Stanner
include/linux/string.h +0
-0I'm wondering if this has no side-effects as
string.h/string.cIIRC is
used also for early stages where some of the APIs are not available.Quoted 8 lines
include/linux/string.h line 10
Quoted 6 lines
include/linux/string.h +2
-0@@ -6,6 +6,8 @@#include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */ +#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */ Can we preserve order (to some extent)?
Quoted 2 lines
Sure. I just put it there so the comments build a congruent block. Which order would you prefer?
Alphabetical.
compiler.herr.hoverflow.h
...the rest that is a bit unordered...
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
include/linux/string.h +0
-0#include <linux/stdarg.h> #include <uapi/linux/string.h>
...
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
+/**
+ *memdup_array_user- duplicate array from user space+ *
Do we need this blank line?
I more or less directly copied the docstring format from the original functions (v)memdup_user() in
mm/util.c
I guess this is common style?
I think it's not. But you may grep kernel source tree and tell which one occurs more often with or without this (unneeded) blank line.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result is physically
+ * contiguous, to be freed bykfree().
+ */
...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+/**
+ *vmemdup_array_user- duplicate array from user space+ *
Quoted 8 lines
Quoted 1 line
Redundant?
No, there are two functions:
*memdup_array_user()
*vmemdup_array_user()On the deeper layers they utilize
kmalloc()orkvmalloc(), respectively.
I guess you misunderstood my comment. I was talking about kernel doc (as in the previous function).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result may be not
+ * physically contiguous. Usekvfree()to free.
+ */
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
Quoted 34 lines · Andy Shevchenko
Quoted 23 lines · On Wed, Aug 30, 2023 at 5:19 PM <[email protected]> wrote:
Quoted 13 lines · Andy Shevchenko
include/linux/string.h
Quoted 2 lines · Philipp Stanner
include/linux/string.h +0
-0I'm wondering if this has no side-effects as
string.h/string.cIIRC
is
used also for early stages where some of the APIs are not available.Quoted 8 lines
include/linux/string.h line 10
Quoted 6 lines
include/linux/string.h +2
-0@@ -6,6 +6,8 @@ #include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */ +#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */Can we preserve order (to some extent)?
Quoted 2 lines
Sure. I just put it there so the comments build a congruent block. Which order would you prefer?
Alphabetical.
compiler.herr.hoverflow.h
...the rest that is a bit unordered...
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
include/linux/string.h +0
-0#include <linux/stdarg.h> #include <uapi/linux/string.h>...
I mean I could include my own in a sorted manner – but the existing ones are not sorted:
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_STRING_H_
#define _LINUX_STRING_H_
#include <linux/compiler.h> /* for inline */
#include <linux/types.h> /* for size_t */
#include <linux/stddef.h> /* for NULL */
#include <linux/errno.h> /* for E2BIG */
#include <linux/stdarg.h>
#include <uapi/linux/string.h>
extern char *strndup_user(const char __user *, long);
We could sort them all, but I'd prefer to do that in a separate patch so that this commit does not make the impression of doing anything else than including the two new headers
Such a separate patch could also unify the docstring style, see below
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
+/**
+ *memdup_array_user- duplicate array from user space+ *
Do we need this blank line?
Quoted 7 lines
Quoted 4 lines
I more or less directly copied the docstring format from the original
functions (v)memdup_user() inmm/util.c
I guess this is common style?I think it's not. But you may grep kernel source tree and tell which one occurs more often with or without this (unneeded) blank line.
It seems to be very much mixed. string.h itself is mixed. When you look at the bottom of string.h, you'll find functions such as kbasename() that have the extra line.
That's not really a super decisive point for me, though. We can remove the line I guess
P.
Quoted 37 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result is physically
+ * contiguous, to be freed bykfree().
+ */...
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
+/**
+ *vmemdup_array_user- duplicate array from user space+ *
Quoted 8 lines
Quoted 1 line
Redundant?
No, there are two functions:
*memdup_array_user()
*vmemdup_array_user()On the deeper layers they utilize
kmalloc()orkvmalloc(), respectively.I guess you misunderstood my comment. I was talking about kernel doc (as in the previous function).
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result may be not
+ * physically contiguous. Usekvfree()to free.
+ */
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
Quoted 6 lines · On Wed, Aug 30, 2023 at 10:15 PM <[email protected]> wrote:
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · On Wed, Aug 30, 2023 at 5:19 PM <[email protected]> wrote:
Quoted 3 lines · Andy Shevchenko
On Wed, Aug 30, 2023 at 4:46 PM Philipp Stanner
<[email protected]>
wrote:
...
Quoted 18 lines
Quoted 18 lines
Quoted 10 lines
Quoted 7 lines
include/linux/string.h line 10
Quoted 5 lines
#include <linux/types.h> /* for size_t */ #include <linux/stddef.h> /* for NULL */ #include <linux/errno.h> /* for E2BIG */include/linux/string.h +2
-0+#include <linux/overflow.h> /* for check_mul_overflow() */ +#include <linux/err.h> /* for ERR_PTR() */ Can we preserve order (to some extent)?
Sure. I just put it there so the comments build a congruent block. Which order would you prefer?
Alphabetical.
compiler.herr.hoverflow.h
...the rest that is a bit unordered...
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
#include <
linux/stdarg.h>
#include <uapi/linux/string.h>I mean I could include my own in a sorted manner – but the existing ones are not sorted:
I know, that's why I put "(to some extent)" in my initial comment.
Quoted 3 lines
We could sort them all, but I'd prefer to do that in a separate patch so that this commit does not make the impression of doing anything else than including the two new headers
But you can do your stuff first with better ordering than you proposed initially, so there will be less churn for any additional change (either that simply unifies the thing or something else).
Quoted 1 line
Such a separate patch could also unify the docstring style, see below
Sure, patches are welcome!
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
+/**
+ *memdup_array_user- duplicate array from user space+ *
Do we need this blank line?
Quoted 7 lines
Quoted 4 lines
I more or less directly copied the docstring format from the original
functions (v)memdup_user() inmm/util.c
I guess this is common style?I think it's not. But you may grep kernel source tree and tell which one occurs more often with or without this (unneeded) blank line.
Quoted 6 lines
It seems to be very much mixed.
string.hitself is mixed. When you look at the bottom ofstring.h, you'll find functions such askbasename()that have the extra line.That's not really a super decisive point for me, though. We can remove the line I guess
I think the less LoCs the better generally speaking. So, if we don't need that line and it doesn't make the readability worse, why to keep it?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
+ * @src: source address in user space
+ * @n: number of array members to copy
+ * @size: size of one array member
+ *
+ * Return: anERR_PTR()on failure. Result is physically
+ * contiguous, to be freed bykfree().
+ */
--
With Best Regards,
Andy Shevchenko
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
Quoted 27 lines · Andy Shevchenko
Quoted 12 lines · On Wed, Aug 30, 2023 at 10:15 PM <[email protected]> wrote:
Quoted 11 lines · Andy Shevchenko
Quoted 3 lines · On Wed, Aug 30, 2023 at 5:19 PM <[email protected]> wrote:
Quoted 2 lines · Andy Shevchenko
On Wed, Aug 30, 2023 at 4:46 PM Philipp Stanner
<[email protected]>Alphabetical.
compiler.herr.hoverflow.h
...the rest that is a bit unordered...Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
#include <
linux/stdarg.h>
#include <uapi/linux/string.h>I mean I could include my own in a sorted manner – but the existing ones are not sorted:
I know, that's why I put "(to some extent)" in my initial comment.
Quoted 5 lines
We could sort them all, but I'd prefer to do that in a separate patch
so that this commit does not make the impression of doing anything else
than including the two new headers
Quoted 6 lines
But you can do your stuff first with better ordering than you proposed
initially, so there will be less churn for any additional change (either that simply unifies the thing or something else).
I'll take care of those points in a v2 once I gathered some more feedback from the other parties.
P.
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
In reply to Andy ShevchenkoQuoted 19 lines · Andy Shevchenko
Quoted 8 lines · Philipp Stanner
Currently, user array duplications are sometimes done without an overflow check. Sometimes the checks are done manually; sometimes the
array size is calculated witharray_size()and sometimes by calculating
n * size directly in code.Quoted 8 lines
Introduce wrappers for arrays for
memdup_user()andvmemdup_user()to
provide a standardized and safe way for duplicating user arrays.This is both for new code as well as replacing usage of (v)memdup_user()
in existing code that uses, e.g., n * size to calculate array sizes.
Quoted 9 lines
...
include/linux/string.h
Quoted 2 lines
include/linux/string.h +0
-0I'm wondering if this has no side-effects as
string.h/string.cIIRC is
used also for early stages where some of the APIs are not available.
I forgot to address this point in my previous reply.
Who's going to decide whether this is a problem or not?
My personal guess is that this is unlikely to be a problem because
A. either (v)memdup_user() is available, in which case
(v)memdup_array_user() will always work –
B. or (v)memdup_user() is not available, which would cause the code
that currently uses (v)memdup_user() for copying arrays to fail anyways.
P.
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
Quoted 3 lines · Philipp Stanner
Quoted 2 lines · Andy Shevchenko
On Wed, Aug 30, 2023 at 4:46 PM Philipp Stanner <[email protected]> wrote:
...
Quoted 7 lines
Quoted 2 lines
I'm wondering if this has no side-effects as
string.h/string.cIIRC is used also for early stages where some of the APIs are not available.I forgot to address this point in my previous reply.
Who's going to decide whether this is a problem or not?
Quoted 7 lines
My personal guess is that this is unlikely to be a problem because
A. either (v)memdup_user() is available, in which case
(v)memdup_array_user() will always work –
B. or (v)memdup_user() is not available, which would cause the code
that currently uses (v)memdup_user() for copying arrays to fail anyways.
It also uses something from overflow.h. I don't remember if that header was ever been used in early stage modules (like boot/decompressor).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 1/5] string.h: add array-wrappers for (v)memdup_user()
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Philipp Stanner
Quoted 2 lines · Andy Shevchenko
On Wed, Aug 30, 2023 at 4:46 PM Philipp Stanner <[email protected]> wrote:
...
Quoted 15 lines
Quoted 7 lines
Quoted 2 lines
I'm wondering if this has no side-effects as
string.h/string.cIIRC is used also for early stages where some of the APIs are not available.I forgot to address this point in my previous reply.
Who's going to decide whether this is a problem or not?
Quoted 7 lines
My personal guess is that this is unlikely to be a problem because
A. either (v)memdup_user() is available, in which case
(v)memdup_array_user() will always work –
B. or (v)memdup_user() is not available, which would cause the code
that currently uses (v)memdup_user() for copying arrays to fail anyways.
Quoted 3 lines
It also uses something from
overflow.h. I don't remember if that header was ever been used in early stage modules (like boot/decompressor).
Also we need to be sure UML is still buildable. Dunno if they are using anything from this, but it appeared to me recently that someone tried to optimize something using (internal) kernel headers and broke the build in some cases.
Signature · 2 lines
With Best Regards, Andy Shevchenko