Skip to contentSkip to conversation

accel/amdxdna: Reject zero length user buffer entry

PATCH In review Lizhi Hou 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore

Lizhi Hou

author maintainer
#0 lore raw

PATCH 1/1 accel/amdxdna: Reject zero length user buffer entry

DRM_IOCTL_AMDXDNA_CREATE_BO with DRM_AMDXDNA_BO_SHARE_DEV_MEM takes an array of user space VA entries. Each entry is validated for page alignment only. A zero length is page aligned, thus an entry with length zero is accepted. Such an entry contributes no page to the buffer.

Reject a zero length entry in the validation loop.

Fixes bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
---
 drivers/accel/amdxdna/amdxdna_ubuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_ubuf.c +2 -1
index 0e0cd69cd1fbf..93b2b6496a0f7 100644
@@ -111,7 +111,8 @@ struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
 
 	for (i = 0, exp_info.size = 0; i < num_entries; i++) {
 		if (!IS_ALIGNED(va_ent[i].vaddr, PAGE_SIZE) ||
-		    !IS_ALIGNED(va_ent[i].len, PAGE_SIZE)) {
+		    !IS_ALIGNED(va_ent[i].len, PAGE_SIZE) ||
+		    !va_ent[i].len) {
 			XDNA_ERR(xdna, "Invalid address or len %llx, %llx",
 				 va_ent[i].vaddr, va_ent[i].len);
 			ret = -EINVAL;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Lizhi Hou

DRM_IOCTL_AMDXDNA_CREATE_BO with DRM_AMDXDNA_BO_SHARE_DEV_MEM takes an array of user space VA entries. Each entry is validated for page alignment only. A zero length is page aligned, thus an entry with length zero is accepted. Such an entry contributes no page to the buffer.

Reject a zero length entry in the validation loop.

Fixes bd72d4acda10 ("accel/amdxdna: Support user space allocated buffer")
---
  drivers/accel/amdxdna/amdxdna_ubuf.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -0
index 0e0cd69cd1fbf..93b2b6496a0f7 100644

drivers/accel/amdxdna/amdxdna_ubuf.c struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev, · line 115

Quoted 6 lines
drivers/accel/amdxdna/amdxdna_ubuf.c +2 -1
@@ -111,7 +111,8 @@ struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
 
  	for (i = 0, exp_info.size = 0; i < num_entries; i++) {
  		if (!IS_ALIGNED(va_ent[i].vaddr, PAGE_SIZE) ||
-		    !IS_ALIGNED(va_ent[i].len, PAGE_SIZE)) {
+		    !IS_ALIGNED(va_ent[i].len, PAGE_SIZE) ||
+		    !va_ent[i].len) {

/David

Quoted 3 lines
drivers/accel/amdxdna/amdxdna_ubuf.c +0 -0
  			XDNA_ERR(xdna, "Invalid address or len %llx, %llx",
  				 va_ent[i].vaddr, va_ent[i].len);
  			ret = -EINVAL;