Skip to content

Commit

Permalink
drivers/fpga: use standard array-copy function
Browse files Browse the repository at this point in the history
dfl.c utilizes memdup_user() and array_size() to copy a userspace array.
array_size() will likely never trigger thanks to the preceding check.
Nevertheless, in the theoretical event that it would, it would return
SIZE_MAX to memdup_user(), resulting in an attempt to allocate huge
amounts of memory.

string.h from the core-api now provides memdup_array_user() which also
performs an overflow check and returns an error-pointer with -EOVERFLOW
to the caller.
As an additional advantage it standardizes how userspace-arrays are
being copied and, thus, makes it more obvious to readers that an array
is being copied.

Replace memdup_user() with memdup_array_user().

Suggested-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20231114111901.19380-2-pstanner@redhat.com
Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
  • Loading branch information
Philipp Stanner authored and Xu Yilun committed Nov 17, 2023
1 parent b85ea95 commit 5496fb8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/fpga/dfl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2008,8 +2008,8 @@ long dfl_feature_ioctl_set_irq(struct platform_device *pdev,
(hdr.start + hdr.count < hdr.start))
return -EINVAL;

fds = memdup_user((void __user *)(arg + sizeof(hdr)),
array_size(hdr.count, sizeof(s32)));
fds = memdup_array_user((void __user *)(arg + sizeof(hdr)),
hdr.count, sizeof(s32));
if (IS_ERR(fds))
return PTR_ERR(fds);

Expand Down

0 comments on commit 5496fb8

Please sign in to comment.