* [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
@ 2026-11-23 21:10 David Hildenbrand (Arm)
2026-11-24 8:46 ` Christian König
2026-11-24 10:54 ` Lorenzo Stoakes (ARM)
0 siblings, 2 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-23 21:10 UTC (permalink / raw)
To: igt-dev
Cc: intel-gfx, David Hildenbrand (Arm), Felix Kuehling,
Christian König, Lorenzo Stoakes
The oob-read test reads 8 bytes through /proc/self/mem, assuming that
the kernel would reject the entire read with EIO.
However, we have 4 remaining bytes in the 4 KiB mapping we can read, so
it's valid for the kernel to only do a partial read that covers these 4
bytes. Allow that as well.
Otherwise, the test will fail on a kernel with upcoming vm_ops->access
fixes, whereby vm_ops->access is limited to the current VMA, so the
read would continue with the next mapping (if any).
So we have to make sure that nothing is mapped after the GEM mapping.
Let's reserve an 8 KiB memory region, map the GEM object into the first
4 KiB slot, and create a hole by unmapping the second 4 KiB slot.
With the kernel changes in place:
$ build/tests/gem_mmap_offset --run-subtest oob-read
[...]
Using IGT_SRANDOM=1795467759 for randomisation
Opened device: /dev/dri/card1
Starting subtest: oob-read
Subtest oob-read: SUCCESS (0,000s)
Link: https://lore.kernel.org/r/20261122-access_shite-v2-0-808d8d2aa700@kernel.org
Cc: Felix Kuehling <felix.kuehling@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
---
tests/intel/gem_mmap_offset.c | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/tests/intel/gem_mmap_offset.c b/tests/intel/gem_mmap_offset.c
index d3c56ab40..e4c0cfbd9 100644
--- a/tests/intel/gem_mmap_offset.c
+++ b/tests/intel/gem_mmap_offset.c
@@ -482,13 +482,29 @@ test_oob_read(int i915)
handle = gem_create(i915, 4096);
for_each_mmap_offset_type(i915, t) {
- uint32_t *ptr;
+ struct drm_i915_gem_mmap_offset arg = {
+ .handle = handle,
+ .flags = t->type,
+ };
+ void *ptr;
- ptr = __mmap_offset(i915, handle, 0, 4096,
- PROT_READ | PROT_WRITE,
- t->type);
- if (!ptr)
+ if (mmap_offset_ioctl(i915, &arg))
+ continue;
+
+ /* Reserve a region for mapping + hole to stop read(). */
+ ptr = mmap(NULL, 8192, PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ igt_assert(ptr != MAP_FAILED);
+
+ /* Place our mapping into the first slot. */
+ if (mmap(ptr, 4096, PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_FIXED, i915, arg.offset) == MAP_FAILED) {
+ munmap(ptr, 8192);
continue;
+ }
+
+ /* And our hole into the second slot. */
+ munmap(ptr + 4096, 4096);
memfd = open("/proc/self/mem", O_RDWR);
igt_require_f(memfd != -1, "/proc/self/mem\n");
@@ -497,9 +513,14 @@ test_oob_read(int i915)
ret = lseek(memfd, addr, SEEK_SET);
igt_assert_f(ret != -1, "lseek failed\n");
- /* Triggering the buf (out of bound read) */
+ /*
+ * Read across the end of the mapping. The read is either
+ * rejected entirely, or completes partially for the remaining
+ * 4 bytes in the mapping.
+ */
ret = read(memfd, read_buf, 8);
- igt_assert(ret == -1 && errno == EIO);
+ igt_assert_f((ret == -1 && errno == EIO) || ret == 4,
+ "ret=%d errno=%d\n", ret, errno);
munmap(ptr, 4096);
close(memfd);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
2026-11-23 21:10 [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read David Hildenbrand (Arm)
@ 2026-11-24 8:46 ` Christian König
2026-11-24 9:41 ` David Hildenbrand (Arm)
2026-11-24 10:54 ` Lorenzo Stoakes (ARM)
1 sibling, 1 reply; 4+ messages in thread
From: Christian König @ 2026-11-24 8:46 UTC (permalink / raw)
To: David Hildenbrand (Arm), igt-dev
Cc: intel-gfx, Felix Kuehling, Lorenzo Stoakes, Prosyak, Vitaly
On 11/23/26 22:10, David Hildenbrand (Arm) wrote:
> The oob-read test reads 8 bytes through /proc/self/mem, assuming that
> the kernel would reject the entire read with EIO.
>
> However, we have 4 remaining bytes in the 4 KiB mapping we can read, so
> it's valid for the kernel to only do a partial read that covers these 4
> bytes. Allow that as well.
If I understand it correctly what happens is that userspace tries to read over the end of one VMA into the next, right?
Mhm, allowing that makes sense from the uAPI point of view but I'm not sure if that can't cause problems apart from that test case.
> Otherwise, the test will fail on a kernel with upcoming vm_ops->access
> fixes, whereby vm_ops->access is limited to the current VMA, so the
> read would continue with the next mapping (if any).
>
> So we have to make sure that nothing is mapped after the GEM mapping.
> Let's reserve an 8 KiB memory region, map the GEM object into the first
> 4 KiB slot, and create a hole by unmapping the second 4 KiB slot.
>
> With the kernel changes in place:
>
> $ build/tests/gem_mmap_offset --run-subtest oob-read
> [...]
> Using IGT_SRANDOM=1795467759 for randomisation
> Opened device: /dev/dri/card1
> Starting subtest: oob-read
> Subtest oob-read: SUCCESS (0,000s)
>
> Link: https://lore.kernel.org/r/20261122-access_shite-v2-0-808d8d2aa700@kernel.org
> Cc: Felix Kuehling <felix.kuehling@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Adding Vitaly on CC to take a look as well and maybe double check with AMDs CI if your patch breaks anything.
Regards,
Christian.
> ---
> tests/intel/gem_mmap_offset.c | 35 ++++++++++++++++++++++++++++-------
> 1 file changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/tests/intel/gem_mmap_offset.c b/tests/intel/gem_mmap_offset.c
> index d3c56ab40..e4c0cfbd9 100644
> --- a/tests/intel/gem_mmap_offset.c
> +++ b/tests/intel/gem_mmap_offset.c
> @@ -482,13 +482,29 @@ test_oob_read(int i915)
> handle = gem_create(i915, 4096);
>
> for_each_mmap_offset_type(i915, t) {
> - uint32_t *ptr;
> + struct drm_i915_gem_mmap_offset arg = {
> + .handle = handle,
> + .flags = t->type,
> + };
> + void *ptr;
>
> - ptr = __mmap_offset(i915, handle, 0, 4096,
> - PROT_READ | PROT_WRITE,
> - t->type);
> - if (!ptr)
> + if (mmap_offset_ioctl(i915, &arg))
> + continue;
> +
> + /* Reserve a region for mapping + hole to stop read(). */
> + ptr = mmap(NULL, 8192, PROT_NONE,
> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> + igt_assert(ptr != MAP_FAILED);
> +
> + /* Place our mapping into the first slot. */
> + if (mmap(ptr, 4096, PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_FIXED, i915, arg.offset) == MAP_FAILED) {
> + munmap(ptr, 8192);
> continue;
> + }
> +
> + /* And our hole into the second slot. */
> + munmap(ptr + 4096, 4096);
>
> memfd = open("/proc/self/mem", O_RDWR);
> igt_require_f(memfd != -1, "/proc/self/mem\n");
> @@ -497,9 +513,14 @@ test_oob_read(int i915)
> ret = lseek(memfd, addr, SEEK_SET);
> igt_assert_f(ret != -1, "lseek failed\n");
>
> - /* Triggering the buf (out of bound read) */
> + /*
> + * Read across the end of the mapping. The read is either
> + * rejected entirely, or completes partially for the remaining
> + * 4 bytes in the mapping.
> + */
> ret = read(memfd, read_buf, 8);
> - igt_assert(ret == -1 && errno == EIO);
> + igt_assert_f((ret == -1 && errno == EIO) || ret == 4,
> + "ret=%d errno=%d\n", ret, errno);
>
> munmap(ptr, 4096);
> close(memfd);
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
2026-11-24 8:46 ` Christian König
@ 2026-11-24 9:41 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-24 9:41 UTC (permalink / raw)
To: Christian König, igt-dev
Cc: intel-gfx, Felix Kuehling, Lorenzo Stoakes, Prosyak, Vitaly
On 11/24/26 09:46, Christian König wrote:
> On 11/23/26 22:10, David Hildenbrand (Arm) wrote:
>> The oob-read test reads 8 bytes through /proc/self/mem, assuming that
>> the kernel would reject the entire read with EIO.
>>
>> However, we have 4 remaining bytes in the 4 KiB mapping we can read, so
>> it's valid for the kernel to only do a partial read that covers these 4
>> bytes. Allow that as well.
>
> If I understand it correctly what happens is that userspace tries to read over the end of one VMA into the next, right?
Yes. It now behaves just like any other cases where userspace would do that
(reading through ordinary GUP).
>
> Mhm, allowing that makes sense from the uAPI point of view but I'm not sure if that can't cause problems apart from that test case.
Hard to imagine :)>
>> Otherwise, the test will fail on a kernel with upcoming vm_ops->access
>> fixes, whereby vm_ops->access is limited to the current VMA, so the
>> read would continue with the next mapping (if any).
>>
>> So we have to make sure that nothing is mapped after the GEM mapping.
>> Let's reserve an 8 KiB memory region, map the GEM object into the first
>> 4 KiB slot, and create a hole by unmapping the second 4 KiB slot.
>>
>> With the kernel changes in place:
>>
>> $ build/tests/gem_mmap_offset --run-subtest oob-read
>> [...]
>> Using IGT_SRANDOM=1795467759 for randomisation
>> Opened device: /dev/dri/card1
>> Starting subtest: oob-read
>> Subtest oob-read: SUCCESS (0,000s)
>>
>> Link: https://lore.kernel.org/r/20261122-access_shite-v2-0-808d8d2aa700@kernel.org
>> Cc: Felix Kuehling <felix.kuehling@amd.com>
>> Cc: Christian König <christian.koenig@amd.com>
>> Cc: Lorenzo Stoakes <ljs@kernel.org>
>> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
>
> Adding Vitaly on CC to take a look as well and maybe double check with AMDs CI if your patch breaks anything.
Thanks for CCing the right people and for the review!
--
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read
2026-11-23 21:10 [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read David Hildenbrand (Arm)
2026-11-24 8:46 ` Christian König
@ 2026-11-24 10:54 ` Lorenzo Stoakes (ARM)
1 sibling, 0 replies; 4+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-11-24 10:54 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: igt-dev, intel-gfx, Felix Kuehling, Christian König
On Mon, Nov 23, 2026 at 10:10:18PM +0100, David Hildenbrand (Arm) wrote:
> The oob-read test reads 8 bytes through /proc/self/mem, assuming that
> the kernel would reject the entire read with EIO.
>
> However, we have 4 remaining bytes in the 4 KiB mapping we can read, so
> it's valid for the kernel to only do a partial read that covers these 4
> bytes. Allow that as well.
>
> Otherwise, the test will fail on a kernel with upcoming vm_ops->access
> fixes, whereby vm_ops->access is limited to the current VMA, so the
> read would continue with the next mapping (if any).
>
> So we have to make sure that nothing is mapped after the GEM mapping.
> Let's reserve an 8 KiB memory region, map the GEM object into the first
> 4 KiB slot, and create a hole by unmapping the second 4 KiB slot.
>
> With the kernel changes in place:
>
> $ build/tests/gem_mmap_offset --run-subtest oob-read
> [...]
> Using IGT_SRANDOM=1795467759 for randomisation
> Opened device: /dev/dri/card1
> Starting subtest: oob-read
> Subtest oob-read: SUCCESS (0,000s)
>
> Link: https://lore.kernel.org/r/20261122-access_shite-v2-0-808d8d2aa700@kernel.org
> Cc: Felix Kuehling <felix.kuehling@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
It's funny how these things can ripple out, but very much seems a correct
change!
Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> ---
> tests/intel/gem_mmap_offset.c | 35 ++++++++++++++++++++++++++++-------
> 1 file changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/tests/intel/gem_mmap_offset.c b/tests/intel/gem_mmap_offset.c
> index d3c56ab40..e4c0cfbd9 100644
> --- a/tests/intel/gem_mmap_offset.c
> +++ b/tests/intel/gem_mmap_offset.c
> @@ -482,13 +482,29 @@ test_oob_read(int i915)
> handle = gem_create(i915, 4096);
>
> for_each_mmap_offset_type(i915, t) {
> - uint32_t *ptr;
> + struct drm_i915_gem_mmap_offset arg = {
> + .handle = handle,
> + .flags = t->type,
> + };
> + void *ptr;
>
> - ptr = __mmap_offset(i915, handle, 0, 4096,
> - PROT_READ | PROT_WRITE,
> - t->type);
> - if (!ptr)
> + if (mmap_offset_ioctl(i915, &arg))
> + continue;
> +
> + /* Reserve a region for mapping + hole to stop read(). */
> + ptr = mmap(NULL, 8192, PROT_NONE,
> + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> + igt_assert(ptr != MAP_FAILED);
> +
> + /* Place our mapping into the first slot. */
> + if (mmap(ptr, 4096, PROT_READ | PROT_WRITE,
> + MAP_SHARED | MAP_FIXED, i915, arg.offset) == MAP_FAILED) {
> + munmap(ptr, 8192);
> continue;
> + }
> +
> + /* And our hole into the second slot. */
> + munmap(ptr + 4096, 4096);
>
> memfd = open("/proc/self/mem", O_RDWR);
> igt_require_f(memfd != -1, "/proc/self/mem\n");
> @@ -497,9 +513,14 @@ test_oob_read(int i915)
> ret = lseek(memfd, addr, SEEK_SET);
> igt_assert_f(ret != -1, "lseek failed\n");
>
> - /* Triggering the buf (out of bound read) */
> + /*
> + * Read across the end of the mapping. The read is either
> + * rejected entirely, or completes partially for the remaining
> + * 4 bytes in the mapping.
> + */
> ret = read(memfd, read_buf, 8);
> - igt_assert(ret == -1 && errno == EIO);
> + igt_assert_f((ret == -1 && errno == EIO) || ret == 4,
> + "ret=%d errno=%d\n", ret, errno);
>
> munmap(ptr, 4096);
> close(memfd);
> --
> 2.56.1
>
--
Cheers, Lorenzo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 10:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 21:10 [PATCH i-g-t] tests/gem_mmap_offset: Accept partial read in oob-read David Hildenbrand (Arm)
2026-11-24 8:46 ` Christian König
2026-11-24 9:41 ` David Hildenbrand (Arm)
2026-11-24 10:54 ` Lorenzo Stoakes (ARM)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox