userfaultfd: allow registration of ranges below mmap_min_addr
Subsystems (2)
PATCH v2 1/1 userfaultfd: allow registration of ranges below mmap_min_addr
The current implementation of validate_range() in fs/userfaultfd.c performs a hard check against mmap_min_addr. This is redundant because UFFDIO_REGISTER operates on memory ranges that must already be backed by a VMA.
Enforcing mmap_min_addr or capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.
Remove the redundant check for mmap_min_addr.
---
v2:
- Remove the check entirely rather than replacing it, as suggested by Harry Yoo and Lorenzo Stoakes.
- Added Fixes tag.
- Link to v1: https://lore.kernel.org/r/[email protected]
--- fs/userfaultfd.c | 2 -- 1 file changed, 2 deletions(-)
fs/userfaultfd.c +0 -2
@@ -1238,8 +1238,6 @@ static __always_inline int validate_unaligned_range(return -EINVAL ;if (!len)return -EINVAL ; -if (start < mmap_min_addr) -return -EINVAL ;if (start >= task_size)return -EINVAL ;if (len > task_size - start)
Signature · 1 line
2.43.0
Quoted 5 lines · Denis M. Karpov
The current implementation of
validate_range()infs/userfaultfd.cperforms a hard check againstmmap_min_addr. This is redundant becauseUFFDIO_REGISTERoperates on memory ranges that must already be backed by a VMA.
Quoted 8 lines
Enforcing
mmap_min_addror capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.Remove the redundant check for
mmap_min_addr.Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Denis M. Karpov <[email protected]>
LGTM, so:
Quoted 26 lines
---
v2:
- Remove the check entirely rather than replacing it, as suggested by Harry Yoo and Lorenzo Stoakes.
- Added Fixes tag.
- Link to v1: https://lore.kernel.org/r/[email protected]--- fs/userfaultfd.c | 2 -- 1 file changed, 2 deletions(-)fs/userfaultfd.c +0
-3@@ -1238,8 +1238,6 @@ static __always_inline int validate_unaligned_range(return -EINVAL ;if (!len)return -EINVAL ; -if (start < mmap_min_addr) -return -EINVAL ;if (start >= task_size)return -EINVAL ;if (len > task_size - start) --2.43.0
Quoted 13 lines · Denis M. Karpov
The current implementation of
validate_range()infs/userfaultfd.cperforms a hard check againstmmap_min_addr. This is redundant becauseUFFDIO_REGISTERoperates on memory ranges that must already be backed by a VMA.Enforcing
mmap_min_addror capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.Remove the redundant check for
mmap_min_addr.Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Denis M. Karpov <[email protected]>
Quoted 7 lines
---
v2:
- Remove the check entirely rather than replacing it, as suggested by Harry Yoo and Lorenzo Stoakes.
- Added Fixes tag.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Looks good to me,
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 5 lines · Denis M. Karpov
The current implementation of
validate_range()infs/userfaultfd.cperforms a hard check againstmmap_min_addr. This is redundant becauseUFFDIO_REGISTERoperates on memory ranges that must already be backed by a VMA.
Quoted 8 lines
Enforcing
mmap_min_addror capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.Remove the redundant check for
mmap_min_addr.Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Denis M. Karpov <[email protected]>
This looks relatively safe. However, I'm not sure if we want this in stable. This has been broken for 11 years now, with no complaints.
Signature · 1 line
Pedro
Quoted 12 lines · Pedro Falcato
Quoted 11 lines · Denis M. Karpov
The current implementation of
validate_range()infs/userfaultfd.cperforms a hard check againstmmap_min_addr. This is redundant becauseUFFDIO_REGISTERoperates on memory ranges that must already be backed by a VMA.Enforcing
mmap_min_addror capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.Remove the redundant check for
mmap_min_addr.
Quoted 7 lines
Quoted 2 lines
Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Denis M. Karpov <[email protected]>Reviewed-by Pedro Falcato <[email protected]>This looks relatively safe. However, I'm not sure if we want this in stable. This has been broken for 11 years now, with no complaints.
I believe Denis has a new usecase that wasn't there for those 11 years :)
Denis, can you share more details about your usecase for us to better understand importance of backporting this to stable?
Quoted 2 lines
Signature · 1 line
Pedro
Signature · 2 lines
Sincerely yours, Mike.
Quoted 8 lines · Mike Rapoport
Quoted 2 lines · Pedro Falcato
This looks relatively safe. However, I'm not sure if we want this in stable. This has been broken for 11 years now, with no complaints.
I believe Denis has a new usecase that wasn't there for those 11 years :)
Denis, can you share more details about your usecase for us to better understand importance of backporting this to stable?
Hello Mike.
Actually, there is nothing new about the use case. We simply started using UFFD instead of the classic mprotect approach in the binary translator to track application writes. During development, we encountered this bug. The translator cannot control where the translated application chooses to map its
memory and if the app requires a low-address area, UFFD fails, whereas mprotect would work just fine. I believe this is a genuine logic bug rather than an improvement, and I would appreciate including the fix in stable.
Liam R. Howlett
Reviewed-byQuoted 9 lines · Denis M. Karpov
Quoted 8 lines · Mike Rapoport
Quoted 2 lines · Pedro Falcato
This looks relatively safe. However, I'm not sure if we want this in stable. This has been broken for 11 years now, with no complaints.
I believe Denis has a new usecase that wasn't there for those 11 years :)
Denis, can you share more details about your usecase for us to better understand importance of backporting this to stable?
Quoted 9 lines
Hello Mike.
Actually, there is nothing new about the use case. We simply started using UFFD instead of the classic mprotect approach in the binary translator to track application writes. During development, we encountered this bug. The translator cannot control where the translated application chooses to map its
memory and if the app requires a low-address area, UFFD fails, whereas mprotect would work just fine. I believe this is a genuine logic bug rather than an improvement, and I would appreciate including the fix in stable.
Then you should have cc'ed stable (with the tag too).
I'm fine with it backported or not.
Thanks, Liam. Andrew has already picked up the patch and added the stable tag. I'll make sure to include it from the start next time.
Quoted 27 lines · Liam R. Howlett
Quoted 9 lines · Denis M. Karpov
Quoted 8 lines · Mike Rapoport
Quoted 2 lines · Pedro Falcato
This looks relatively safe. However, I'm not sure if we want this in stable. This has been broken for 11 years now, with no complaints.
I believe Denis has a new usecase that wasn't there for those 11 years :)
Denis, can you share more details about your usecase for us to better understand importance of backporting this to stable?
Quoted 9 lines
Hello Mike.
Actually, there is nothing new about the use case. We simply started using UFFD instead of the classic mprotect approach in the binary translator to track application writes. During development, we encountered this bug. The translator cannot control where the translated application chooses to map its
memory and if the app requires a low-address area, UFFD fails, whereas mprotect would work just fine. I believe this is a genuine logic bug rather than an improvement, and I would appreciate including the fix in stable.Then you should have cc'ed stable (with the tag too).
I'm fine with it backported or not.
Reviewed-by Liam R. Howlett <[email protected]>
Quoted 5 lines · Denis M. Karpov
The current implementation of
validate_range()infs/userfaultfd.cperforms a hard check againstmmap_min_addr. This is redundant becauseUFFDIO_REGISTERoperates on memory ranges that must already be backed by a VMA.
Quoted 8 lines
Enforcing
mmap_min_addror capability checks again in userfaultfd is unnecessary and prevents applications like binary compilers from using UFFD for valid memory regions mapped by application.Remove the redundant check for
mmap_min_addr.Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")Signed-off-by Denis M. Karpov <[email protected]>
Quoted 26 lines
---
v2:
- Remove the check entirely rather than replacing it, as suggested by Harry Yoo and Lorenzo Stoakes.
- Added Fixes tag.
- Link to v1: https://lore.kernel.org/r/[email protected]--- fs/userfaultfd.c | 2 -- 1 file changed, 2 deletions(-)fs/userfaultfd.c +0
-2@@ -1238,8 +1238,6 @@ static __always_inline int validate_unaligned_range(return -EINVAL ;if (!len)return -EINVAL ; -if (start < mmap_min_addr) -return -EINVAL ;if (start >= task_size)return -EINVAL ;if (len > task_size - start)Signature · 1 line
2.43.0
Signature · 2 lines
Sincerely yours, Mike.