drm/qxl: use correct offset when stamping drawable mm_time
Subsystems (4)
PATCH 1/1 drm/qxl: use correct offset when stamping drawable mm_time
qxl_process_single_command() maps the page containing the current release slot and copies the userspace command into it at the release_offset within the page:
fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo,
(release->release_offset & PAGE_MASK));
copy_from_user(fb_cmd + sizeof(union qxl_release_info) +
(release->release_offset & ~PAGE_MASK), ...);
However, the subsequent mm_time stamp casts the page-start pointer directly:
struct qxl_drawable *draw = fb_cmd;
draw->mm_time = qdev->rom->mm_clock;This writes mm_time into the release_info header or whatever sits at the page start rather than into the drawable that was just copied. Apply the same offset so mm_time lands in the right place.
---
drivers/gpu/drm/qxl/qxl_ioctl.c +3 -1
@@ -188,7 +188,9 @@ static int qxl_process_single_command(struct qxl_device *qdev, u64_to_user_ptr(cmd->command), cmd->command_size); { -struct qxl_drawable *draw = fb_cmd; +struct qxl_drawable *draw = fb_cmd + +sizeof (union qxl_release_info ) + + (release->release_offset & ~PAGE_MASK ); draw->mm_time = qdev->rom->mm_clock; }
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] drm/qxl: memory corruption in command ring due to incorrect pointer arithmetic --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/qxl: memory corruption in command ring due to incorrect pointer arithmetic --
commit 4eafd1ab56e831f8f5645009fd6d47df82921e0f
Author: Aldo Ariel Panzardo <[email protected]>
drm/qxl: use correct offset when stamping drawable mm_time
This commit attempts to fix the mm_time stamping offset by applying the release_offset and a sizeof() offset when mapping the page pointer to the drawable structure.
drivers/gpu/drm/qxl/qxl_ioctl.c static int qxl_process_single_command(struct qxl_device *qdev, · line 193
Quoted 12 lines
drivers/gpu/drm/qxl/qxl_ioctl.c +3
-1@@ -188,7 +188,9 @@ static int qxl_process_single_command(struct qxl_device *qdev, u64_to_user_ptr(cmd->command), cmd->command_size); { -struct qxl_drawable *draw = fb_cmd; +struct qxl_drawable *draw = fb_cmd + +sizeof (union qxl_release_info ) + + (release->release_offset & ~PAGE_MASK );
[Severity: High]
Does this pointer arithmetic shift the base pointer past the release_info header, causing memory corruption?
In struct qxl_drawable, union qxl_release_info is the first member. The user payload is copied to fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_MASK) exactly because the payload starts after the header.
If the struct pointer itself is initialized with that extra 8-byte sizeof(union qxl_release_info) shift, won't draw->mm_time end up writing 8 bytes past the intended location in the command ring, overwriting fields like the surfaces_dest array and leaving the actual mm_time uninitialized?
Quoted 3 lines
drivers/gpu/drm/qxl/qxl_ioctl.c +0
-0draw->mm_time = qdev->rom->mm_clock; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 1/1 drm/qxl: use correct offset when stamping drawable mm_time
In reply to Aldo Ariel Panzardoqxl_process_single_command() maps the page containing the current release slot and copies the userspace command into it at the release_offset within the page:
fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo,
(release->release_offset & PAGE_MASK));
copy_from_user(..., fb_cmd + sizeof(union qxl_release_info) +
(release->release_offset & ~PAGE_MASK), ...);
However, the subsequent mm_time stamp casts the page-start pointer directly:
struct qxl_drawable *draw = fb_cmd;
This writes mm_time at the page start rather than into the drawable that was just copied. The drawable begins at the page-relative release_offset (struct qxl_drawable embeds the release_info header as its first member, so no additional sizeof skip is needed for the struct pointer).
Apply the page-relative offset so mm_time lands in the right place.
---
v2: drop the sizeof(union qxl_release_info) term — qxl_drawable
embeds release_info as its first member, so the struct pointer only needs the page-relative offset (found by Sashiko AI review).
drivers/gpu/drm/qxl/qxl_ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/qxl/qxl_ioctl.c +2 -1
@@ -188,7 +188,8 @@ static int qxl_process_single_command(struct qxl_device *qdev, u64_to_user_ptr(cmd->command), cmd->command_size); { -struct qxl_drawable *draw = fb_cmd; +struct qxl_drawable *draw = (void *)fb_cmd + + (release->release_offset & ~PAGE_MASK ); draw->mm_time = qdev->rom->mm_clock; }
Signature · 1 line
2.43.0
Gentle ping — any feedback on this patch?
thanks,
Aldo
Quoted 53 lines · Aldo Ariel Panzardo
qxl_process_single_command()maps the page containing the current release slot and copies the userspace command into it at therelease_offsetwithin the page:
fb_cmd= qxl_bo_kmap_atomic_page(qdev,cmd_bo,
(release->release_offset&PAGE_MASK));
copy_from_user(...,fb_cmd+sizeof(union qxl_release_info)+
(release->release_offset& ~PAGE_MASK), ...);However, the subsequent
mm_timestamp casts the page-start pointer directly:struct qxl_drawable *draw = fb_cmd;This writes
mm_timeat the page start rather than into the drawable that was just copied. The drawable begins at the page-relativerelease_offset(structqxl_drawableembeds therelease_infoheader as its first member, so no additional sizeof skip is needed for the struct pointer).Apply the page-relative offset so
mm_timelands in the right place.Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")Reported-by Sashiko <[email protected]>Signed-off-by Aldo Ariel Panzardo <[email protected]>---
v2: drop thesizeof(union qxl_release_info)term —qxl_drawable
embedsrelease_infoas its first member, so the struct pointer only needs the page-relative offset (found by Sashiko AI review).drivers/gpu/drm/qxl/qxl_ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/qxl/qxl_ioctl.c +2
-1@@ -188,7 +188,8 @@ static int qxl_process_single_command(struct qxl_device *qdev, u64_to_user_ptr(cmd->command), cmd->command_size); { -struct qxl_drawable *draw = fb_cmd; +struct qxl_drawable *draw = (void *)fb_cmd + + (release->release_offset & ~PAGE_MASK ); draw->mm_time = qdev->rom->mm_clock;}--
2.43.0
Hi guys,
Following up on this v2. Some list copies of my previous follow-up were rejected because they contained HTML, so I'm following up in plain text.
Would any additional testing or changes help with the review? I'm happy to address any remaining concerns.
Thanks,
Aldo
Quoted 31 lines · Aldo Ariel Panzardo
qxl_process_single_command()maps the page containing the current release slot and copies the userspace command into it at therelease_offsetwithin the page:
fb_cmd= qxl_bo_kmap_atomic_page(qdev,cmd_bo,
(release->release_offset&PAGE_MASK));
copy_from_user(...,fb_cmd+sizeof(union qxl_release_info)+
(release->release_offset& ~PAGE_MASK), ...);However, the subsequent
mm_timestamp casts the page-start pointer directly:struct qxl_drawable *draw = fb_cmd;This writes
mm_timeat the page start rather than into the drawable that was just copied. The drawable begins at the page-relativerelease_offset(structqxl_drawableembeds therelease_infoheader as its first member, so no additional sizeof skip is needed for the struct pointer).Apply the page-relative offset so
mm_timelands in the right place.Fixes f64122c1f6ad ("drm: add new QXL driver. (v1.4)")Reported-by Sashiko <[email protected]>Signed-off-by Aldo Ariel Panzardo <[email protected]>---
v2: drop thesizeof(union qxl_release_info)term —qxl_drawable
embedsrelease_infoas its first member, so the struct pointer only needs the page-relative offset (found by Sashiko AI review).
Review
Quoted 4 lines
drivers/gpu/drm/qxl/qxl_ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/drivers/gpu/drm/qxl/qxl_ioctl.c
drivers/gpu/drm/qxl/qxl_ioctl.c static int qxl_process_single_command(struct
Quoted 4 lines
index 591b026..65e9bfd 100644
drivers/gpu/drm/qxl/qxl_ioctl.c +0
-0@@ -188,7 +188,8 @@ static int qxl_process_single_command(struct
qxl_device *qdev,
Quoted 11 lines
drivers/gpu/drm/qxl/qxl_ioctl.c +2
-2u64_to_user_ptr(cmd->command), cmd->command_size); { -struct qxl_drawable *draw = fb_cmd; +struct qxl_drawable *draw = (void *)fb_cmd + + (release->release_offset & ~PAGE_MASK ); draw->mm_time = qdev->rom->mm_clock; } --2.43.0