Skip to contentSkip to conversation

drm/qxl: remove double page-size scaling in kmap fallback paths

PATCH In review Aldo Ariel Panzardo 2 participants 4 messages Sep 23 – Oct 24

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

PATCH 1/1 drm/qxl: remove double page-size scaling in kmap fallback paths

qxl_bo_kmap_atomic_page() takes a page_offset parameter that callers compute as a byte offset aligned to a page boundary:

    reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo,
                                         info->dst_offset & PAGE_MASK);

The VRAM/PRIV path adds it directly to the mapping base (both in bytes), which is correct:

    offset = bo->tbo.resource->start << PAGE_SHIFT;
    return io_mapping_map_atomic_wc(map, offset + page_offset);

But the two system-memory fallback paths multiply it by PAGE_SIZE again:

    rptr = bo->kptr + (page_offset * PAGE_SIZE);

For page_offset = 0x5000 (page 5), this computes 0x5000 * 0x1000 = 0x5000000, a 80 MiB offset instead of 20 KiB, producing a massive out-of-bounds access into kernel memory.

Remove the spurious multiplication so the fallback paths use the same byte-offset semantics as the io_mapping path.

Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")
---
 drivers/gpu/drm/qxl/qxl_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/qxl/qxl_object.c +2 -2
index XXXXXXX..YYYYYYY 100644
@@ -223,7 +223,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
 	return io_mapping_map_atomic_wc(map, offset + page_offset);
 fallback:
 	if (bo->kptr) {
-		rptr = bo->kptr + (page_offset * PAGE_SIZE);
+		rptr = bo->kptr + page_offset;
 		return rptr;
 	}
 
@@ -232,7 +232,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
 		return NULL;
 	rptr = bo_map.vaddr; /* TODO: Use mapping abstraction properly */
 
-	rptr += page_offset * PAGE_SIZE;
+	rptr += page_offset;
 	return rptr;
 }
 

--
2.43.0

#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 21 lines

qxl_bo_kmap_atomic_page() takes a page_offset parameter that callers compute as a byte offset aligned to a page boundary:

    reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo,
                                         info->dst_offset & PAGE_MASK);

The VRAM/PRIV path adds it directly to the mapping base (both in bytes), which is correct:

    offset = bo->tbo.resource->start << PAGE_SHIFT;
    return io_mapping_map_atomic_wc(map, offset + page_offset);

But the two system-memory fallback paths multiply it by PAGE_SIZE again:

    rptr = bo->kptr + (page_offset * PAGE_SIZE);

For page_offset = 0x5000 (page 5), this computes 0x5000 * 0x1000 = 0x5000000, a 80 MiB offset instead of 20 KiB, producing a massive out-of-bounds access into kernel memory.

Quoted 7 lines

Remove the spurious multiplication so the fallback paths use the same byte-offset semantics as the io_mapping path.

Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#2 lore raw
In reply to Aldo Ariel Panzardo

Gentle ping — any feedback on this patch?

thanks,
Aldo

Quoted 58 lines · Aldo Ariel Panzardo

qxl_bo_kmap_atomic_page() takes a page_offset parameter that callers compute as a byte offset aligned to a page boundary:

    reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo,
                                         info->dst_offset & PAGE_MASK);

The VRAM/PRIV path adds it directly to the mapping base (both in bytes), which is correct:

    offset = bo->tbo.resource->start << PAGE_SHIFT;
    return io_mapping_map_atomic_wc(map, offset + page_offset);

But the two system-memory fallback paths multiply it by PAGE_SIZE again:

    rptr = bo->kptr + (page_offset * PAGE_SIZE);

For page_offset = 0x5000 (page 5), this computes 0x5000 * 0x1000 = 0x5000000, a 80 MiB offset instead of 20 KiB, producing a massive out-of-bounds access into kernel memory.

Remove the spurious multiplication so the fallback paths use the same byte-offset semantics as the io_mapping path.

Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")
---
 drivers/gpu/drm/qxl/qxl_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/qxl/qxl_object.c +2 -3
index XXXXXXX..YYYYYYY 100644
@@ -223,7 +223,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
        return io_mapping_map_atomic_wc(map, offset + page_offset);
 fallback:
        if (bo->kptr) {
-               rptr = bo->kptr + (page_offset * PAGE_SIZE);
+               rptr = bo->kptr + page_offset;
                return rptr;
        }
 
@@ -232,7 +232,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
                return NULL;
        rptr = bo_map.vaddr; /* TODO: Use mapping abstraction properly */
 
-       rptr += page_offset * PAGE_SIZE;
+       rptr += page_offset;
        return rptr;
 }
 
--

2.43.0

author
#3 lore raw
In reply to Aldo Ariel Panzardo

Hi Dave, Gerd,

Following up on this fix. Some list copies of my previous follow-up were rejected because they contained HTML, so I'm following up in plain text.

Is there any additional validation or any change that would help move the review forward? I'm happy to help.

Thanks,
Aldo

Quoted 28 lines · Aldo Ariel Panzardo

qxl_bo_kmap_atomic_page() takes a page_offset parameter that callers compute as a byte offset aligned to a page boundary:

    reloc_page = qxl_bo_kmap_atomic_page(qdev, info->dst_bo,
                                         info->dst_offset & PAGE_MASK);

The VRAM/PRIV path adds it directly to the mapping base (both in bytes), which is correct:

    offset = bo->tbo.resource->start << PAGE_SHIFT;
    return io_mapping_map_atomic_wc(map, offset + page_offset);

But the two system-memory fallback paths multiply it by PAGE_SIZE again:

    rptr = bo->kptr + (page_offset * PAGE_SIZE);

For page_offset = 0x5000 (page 5), this computes 0x5000 * 0x1000 = 0x5000000, a 80 MiB offset instead of 20 KiB, producing a massive out-of-bounds access into kernel memory.

Remove the spurious multiplication so the fallback paths use the same byte-offset semantics as the io_mapping path.

Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")

Review

Quoted 5 lines
---
 drivers/gpu/drm/qxl/qxl_object.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/qxl/qxl_object.c

Quoted 23 lines

index XXXXXXX..YYYYYYY 100644

drivers/gpu/drm/qxl/qxl_object.c +2 -3
@@ -223,7 +223,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
      return io_mapping_map_atomic_wc(map, offset + page_offset);
 fallback:
      if (bo->kptr) {
-             rptr = bo->kptr + (page_offset * PAGE_SIZE);
+             rptr = bo->kptr + page_offset;
              return rptr;
      }
 
@@ -232,7 +232,7 @@ void *qxl_bo_kmap_atomic_page(struct qxl_device *qdev,
              return NULL;
      rptr = bo_map.vaddr; /* TODO: Use mapping abstraction properly */
 
-     rptr += page_offset * PAGE_SIZE;
+     rptr += page_offset;
      return rptr;
 }
 
--

2.43.0