Skip to contentSkip to conversation

userfaultfd: allow registration of ranges below mmap_min_addr

PATCH Applied Denis M. Karpov 6 participants 9 messages Apr 9 – Apr 10

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")

---
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
index bdc84e521..4b53dc4a3 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Denis M. Karpov

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.

Quoted 8 lines

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.

Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")

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
index bdc84e521..4b53dc4a3 100644
@@ -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

Acked-by on v2 1/1
#2 lore raw
In reply to Denis M. Karpov
Quoted 13 lines · Denis M. Karpov

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.

Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")
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
Reviewed-by on v2 1/1
#3 lore raw
In reply to Denis M. Karpov
Quoted 5 lines · Denis M. Karpov

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.

Quoted 8 lines

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.

Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")

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
#4 lore raw
Quoted 12 lines · Pedro Falcato
Quoted 11 lines · Denis M. Karpov

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.

Quoted 7 lines
Quoted 2 lines
Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")

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.
#5 lore raw
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.

Reviewed-by
#6 lore raw
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.

#7 lore raw

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 on v2 1/1
#8 lore raw
In reply to Denis M. Karpov
Quoted 5 lines · Denis M. Karpov

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.

Quoted 8 lines

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.

Fixes 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")
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
index bdc84e521..4b53dc4a3 100644
@@ -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.