Skip to contentSkip to conversation

accel/ivpu: prevent uninitialized data bug in debugfs

PATCH Applied Dan Carpenter 2 participants 3 messages May 25 – May 26

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

PATCH 1/1 accel/ivpu: prevent uninitialized data bug in debugfs

The simple_write_to_buffer() will only initialize data starting from the *pos offset so if it's non-zero then the first part of the buffer uninitialized. Really, if *pos is non-zero then this code won't work so just check for that at the start of the function.

Fixes 320323d2e545 ("accel/ivpu: Add debugfs interface for setting HWS priority bands")
---
 drivers/accel/ivpu/ivpu_debugfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_debugfs.c +1 -1
index 189dbe94cf14..dc20bc73c6ed 100644
@@ -450,7 +450,7 @@ priority_bands_fops_write(struct file *file, const char __user *user_buf, size_t
 	u32 band;
 	int ret;
 
-	if (size >= sizeof(buf))
+	if (*pos != 0 || size >= sizeof(buf))
 		return -EINVAL;
 
 	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, pos, user_buf, size);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Dan Carpenter

The simple_write_to_buffer() will only initialize data starting from the *pos offset so if it's non-zero then the first part of the buffer uninitialized. Really, if *pos is non-zero then this code won't work so just check for that at the start of the function.

Fixes 320323d2e545 ("accel/ivpu: Add debugfs interface for setting HWS priority bands")
---
  drivers/accel/ivpu/ivpu_debugfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_debugfs.c +0 -0
index 189dbe94cf14..dc20bc73c6ed 100644

drivers/accel/ivpu/ivpu_debugfs.c priority_bands_fops_write(struct file *file, const char __user *user_buf, size_t · line 456

Quoted 8 lines
drivers/accel/ivpu/ivpu_debugfs.c +1 -1
@@ -450,7 +450,7 @@ priority_bands_fops_write(struct file *file, const char __user *user_buf, size_t
  	u32 band;
  	int ret;
 
-	if (size >= sizeof(buf))
+	if (*pos != 0 || size >= sizeof(buf))
  		return -EINVAL;
 
  	ret = simple_write_to_buffer(buf, sizeof(buf) - 1, pos, user_buf, size);

Thanks for submission.

maintainer Applied
#2 lore raw
Quoted 27 lines · Karol
Quoted 16 lines · Dan Carpenter

The simple_write_to_buffer() will only initialize data starting from the *pos offset so if it's non-zero then the first part of the buffer uninitialized.  Really, if *pos is non-zero then this code won't work so just check for that at the start of the function.

Fixes 320323d2e545 ("accel/ivpu: Add debugfs interface for setting HWS priority bands")

---
  drivers/accel/ivpu/ivpu_debugfs.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_debugfs.c +0 -0
index 189dbe94cf14..dc20bc73c6ed 100644
@@ -450,7 +450,7 @@ priority_bands_fops_write(struct file *file, const 
Quoted 7 lines

char __user *user_buf, size_t
      u32 band;
      int ret;
-    if (size >= sizeof(buf))
+    if (*pos != 0 || size >= sizeof(buf))
          return -EINVAL;
      ret = simple_write_to_buffer(buf, sizeof(buf) - 1, pos, user_buf, size);

Thanks for submission.

Quoted 1 line

Applied to drm-misc-fixes.