kselftests: dmabuf-heaps: Ensure the driver name is null-terminated
Subsystems (3)
PATCH v2 1/1 kselftests: dmabuf-heaps: Ensure the driver name is null-terminated
Even if a vgem device is configured in, we will skip the import_vgem_fd() test almost every time.
TAP version 13
1..11
# Testing heap: system
# =======================================
# Testing allocation and importing:
ok 1 # SKIP Could not open vgem -1
The problem is that we use the DRM_IOCTL_VERSION ioctl to query the driver version information but leave the name field a non-null-terminated string. Terminate it properly to actually test against the vgem device.
While at it, let's check the length of the driver name is exactly 4 bytes and return early otherwise (in case there is a name like "vgemfoo" that gets converted to "vgem\0" unexpectedly).
---
* From v1 [1]:
- Check version.name_len is exactly 4 bytes and return early otherwise
[1] https://lore.kernel.org/r/[email protected]
P.S., Maybe worth including the kselftests file into "DMA-BUF HEAPS FRAMEWORK" MAINTAINERS entry?
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +3 -1
@@ -29,9 +29,11 @@ static int check_vgem(int fd) version.name = name; ret =ioctl (fd,DRM_IOCTL_VERSION , &version); -if (ret) +if (ret || version.name_len !=4 )return 0 ; + name[4 ] ='\0' ; +return !strcmp (name,"vgem" ); }
Signature · 1 line
2.33.0
Quoted 18 lines · Zenghui Yu
Even if a vgem device is configured in, we will skip the
import_vgem_fd()test almost every time.TAP version 13
1..11
# Testing heap: system
# =======================================
# Testing allocation and importing:
ok 1 # SKIP Could not open vgem -1The problem is that we use the
DRM_IOCTL_VERSIONioctl to query the driver version information but leave the name field a non-null-terminated string. Terminate it properly to actually test against the vgem device.While at it, let's check the length of the driver name is exactly 4 bytes and return early otherwise (in case there is a name like "vgemfoo" that gets converted to "vgem\0" unexpectedly).
Quoted 6 lines
Signed-off-by Zenghui Yu <[email protected]>---
* From v1 [1]:
- Check version.name_len is exactly 4 bytes and return early otherwise
Thanks for your patch, I'll push it to drm-misc-next-fixes.
Quoted 2 lines
P.S., Maybe worth including the kselftests file into "DMA-BUF HEAPS FRAMEWORK"MAINTAINERSentry?
Good idea, want to do the patch for that too?
Cheers, Sima
Quoted 24 lines
tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +3
-1@@ -29,9 +29,11 @@ static int check_vgem(int fd) version.name = name; ret =ioctl (fd,DRM_IOCTL_VERSION , &version); -if (ret) +if (ret || version.name_len !=4 )return 0 ; + name[4 ] ='\0' ; +return !strcmp (name,"vgem" ); }Signature · 1 line
2.33.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 24 lines · Daniel Vetter
Quoted 23 lines · Zenghui Yu
Even if a vgem device is configured in, we will skip the
import_vgem_fd()test almost every time.TAP version 13
1..11
# Testing heap: system
# =======================================
# Testing allocation and importing:
ok 1 # SKIP Could not open vgem -1The problem is that we use the
DRM_IOCTL_VERSIONioctl to query the driver version information but leave the name field a non-null-terminated string. Terminate it properly to actually test against the vgem device.While at it, let's check the length of the driver name is exactly 4 bytes and return early otherwise (in case there is a name like "vgemfoo" that gets converted to "vgem\0" unexpectedly).
Signed-off-by Zenghui Yu <[email protected]>---
* From v1 [1]:
- Check version.name_len is exactly 4 bytes and return early otherwise
Quoted 8 lines
Quoted 1 line
Thanks for your patch, I'll push it to drm-misc-next-fixes.
Quoted 2 lines
P.S., Maybe worth including the kselftests file into "DMA-BUF HEAPS FRAMEWORK"MAINTAINERSentry?Good idea, want to do the patch for that too?
Sure, I can send a patch for that today.
Thanks,
Zenghui