mm: userfaultfd: check for start + len overflow in validate_range: fix
Subsystems (4)
PATCH 1/1 mm: userfaultfd: check for start + len overflow in validate_range: fix
A previous fixup to this commit fixed one issue, but introduced another:
we're now overly strict when validating the src address for UFFDIO_COPY.
Most of the validation in validate_range is useful to apply to src as well as dst, but page alignment is only a requirement for dst, not src. So, split the function up so src can use an "unaligned" variant, while still allowing us to share the majority of the code between the different cases.
--- fs/userfaultfd.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
fs/userfaultfd.c +13 -5
@@ -1287,13 +1287,11 @@ static __always_inline void wake_userfault(struct userfaultfd_ctx *ctx,__wake_userfault (ctx, range); } -static __always_inline int validate_range(struct mm_struct *mm, -__u64 start,__u64 len) +static __always_inline int validate_unaligned_range( +struct mm_struct *mm,__u64 start,__u64 len) {__u64 task_size = mm->task_size; -if (start & ~PAGE_MASK ) -return -EINVAL ;if (len & ~PAGE_MASK )return -EINVAL ;if (!len)
@@ -1309,6 +1307,15 @@ static __always_inline int validate_range(struct mm_struct *mm,return 0 ; } +static __always_inline int validate_range(struct mm_struct *mm, +__u64 start,__u64 len) +{ +if (start & ~PAGE_MASK ) +return -EINVAL ; + +return validate_unaligned_range (mm, start, len); +} +static int userfaultfd_register (struct userfaultfd_ctx *ctx,unsigned long arg) {
@@ -1759,7 +1766,8 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx, sizeof(uffdio_copy)-sizeof(__s64))) goto out; - ret =validate_range (ctx->mm, uffdio_copy.src, uffdio_copy.len); + ret =validate_unaligned_range (ctx->mm, uffdio_copy.src, + uffdio_copy.len);if (ret) goto out; ret =validate_range (ctx->mm, uffdio_copy.dst, uffdio_copy.len);
--
2.41.0.640.ga95def55d0-goog
Quoted 10 lines · Axel Rasmussen
A previous fixup to this commit fixed one issue, but introduced another:
we're now overly strict when validating the src address forUFFDIO_COPY.Most of the validation in
validate_rangeis useful to apply to src as well as dst, but page alignment is only a requirement for dst, not src. So, split the function up so src can use an "unaligned" variant, while still allowing us to share the majority of the code between the different cases.
Quoted 3 lines
Reported-by Ryan Roberts <[email protected]>Signed-off-by Axel Rasmussen <[email protected]>
Quoted 9 lines · Axel Rasmussen
A previous fixup to this commit fixed one issue, but introduced another:
we're now overly strict when validating the src address forUFFDIO_COPY.Most of the validation in
validate_rangeis useful to apply to src as well as dst, but page alignment is only a requirement for dst, not src. So, split the function up so src can use an "unaligned" variant, while still allowing us to share the majority of the code between the different cases.
Quoted 3 lines
Reported-by Ryan Roberts <[email protected]>Signed-off-by Axel Rasmussen <[email protected]>
Signature · 1 line
Peter Xu