drm/i915: Fix copy_to_user usage for pipe_crc
Subsystems (2)
Rodrigo Vivi
maintainerPATCH 1/2 drm/i915: Fix copy_to_user usage for pipe_crc
Copy to user return the number of bytes it couldn't write and zero on success. So any number different than 0 should be considered a fault, not only when it doesn't write the full size.
--- drivers/gpu/drm/i915/i915_debugfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -3
@@ -3632,7 +3632,6 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,while (n_entries >0 ) {struct intel_pipe_crc_entry *entry = &pipe_crc->entries[pipe_crc->tail]; -int ret;if (CIRC_CNT (pipe_crc->head, pipe_crc->tail,INTEL_PIPE_CRC_ENTRIES_NR ) <1 )
@@ -3649,8 +3648,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); - ret =copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ); -if (ret ==PIPE_CRC_LINE_LEN ) +if (!copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ))return -EFAULT ; user_buf +=PIPE_CRC_LINE_LEN ;
Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Rodrigo Vivi
maintainerPATCH 2/2 drm/i915: Fix the return value of pipe crc read function.
A read(fd, buf, len) function should return the number of bytes read. In our case we need to return the number of bytes we copy to user, instead of returning the number of bytes we read internally.
It was really strange when I saw i-g-t test case using len '54' but getting '56' as return. First thought was how do we read more than we asked? But also I checked and there was really only 54. Until I realized it was all our fault. EFAULT!
--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_debugfs.c +1 -1
@@ -3659,7 +3659,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); -return bytes_read; +return PIPE_CRC_LINE_LEN ; }static const struct file_operations i915_pipe_crc_fops = {
Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: Fix the return value of pipe crc read function.
Quoted 21 lines · Rodrigo Vivi
A
read(fd, buf, len)function should return the number of bytes read. In our case we need to return the number of bytes we copy to user, instead of returning the number of bytes we read internally.It was really strange when I saw i-g-t test case using len '54' but getting '56' as return. First thought was how do we read more than we asked? But also I checked and there was really only 54. Until I realized it was all our fault. EFAULT!
Signed-off-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/i915_debugfs.c +0
-0
drivers/gpu/drm/i915/i915_debugfs.c i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count, · line 3662
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1@@ -3659,7 +3659,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); -return bytes_read; +return PIPE_CRC_LINE_LEN ;
Nope. We can read multiple entries in one go.
bytes_read += snprintf()
so it's mostly good. The only case where it fails if we don't have enough space for the snprintf(), as snprintf() will then return the number of bytes it would have written. That can actually happen on account of the hex vs. decimal mess with the frame counter.
Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0}static const struct file_operations i915_pipe_crc_fops = {Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Vivi, Rodrigo
maintainerRe: [PATCH 2/2] drm/i915: Fix the return value of pipe crc read function.
Quoted 32 lines · Ville Syrjälä
Quoted 27 lines · Rodrigo Vivi
A
read(fd, buf, len)function should return the number of bytes read. In our case we need to return the number of bytes we copy to user, instead of returning the number of bytes we read internally.It was really strange when I saw i-g-t test case using len '54' but getting '56' as return. First thought was how do we read more than we asked? But also I checked and there was really only 54. Until I realized it was all our fault. EFAULT!
Signed-off-by Rodrigo Vivi <[email protected]>---
drivers/gpu/drm/i915/i915_debugfs.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/i915_debugfs.c +0
-0@@ -3659,7 +3659,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
spin_unlock_irq(&pipe_crc->lock);drivers/gpu/drm/i915/i915_debugfs.c i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count, · line 3662
Quoted 2 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1-return bytes_read; +return PIPE_CRC_LINE_LEN ;Nope. We can read multiple entries in one go.
Quoted 6 lines
bytes_read+=snprintf()so it's mostly good. The only case where it fails if we don't have enough space for the
snprintf(), assnprintf()will then return the number of bytes it would have written. That can actually happen on account of the hex vs. decimal mess with the frame counter.
Oh, I see.
So what about:
if (bytes_read > count)
return -E-something?
Quoted 8 lines
Quoted 8 lines
}
static const structfile_operationsi915_pipe_crc_fops= { --
2.5.5
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: Fix the return value of pipe crc read function.
Quoted 40 lines · Rodrigo
Quoted 32 lines · Ville Syrjälä
Quoted 23 lines · Rodrigo Vivi
A
read(fd, buf, len)function should return the number of bytes read. In our case we need to return the number of bytes we copy to user, instead of returning the number of bytes we read internally.It was really strange when I saw i-g-t test case using len '54' but getting '56' as return. First thought was how do we read more than we asked? But also I checked and there was really only 54. Until I realized it was all our fault. EFAULT!
Signed-off-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/i915_debugfs.c +0
-0drivers/gpu/drm/i915/i915_debugfs.c i915_pipe_crc_read(struct file *filep, char · line 3663
Quoted 6 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1@@ -3659,7 +3659,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); -return bytes_read; +return PIPE_CRC_LINE_LEN ;Nope. We can read multiple entries in one go.
Quoted 6 lines
bytes_read+=snprintf()so it's mostly good. The only case where it fails if we don't have enough space for the
snprintf(), assnprintf()will then return the number of bytes it would have written. That can actually happen on account of the hex vs. decimal mess with the frame counter.
Quoted 5 lines
Oh, I see.
So what about:
if (bytes_read> count)
return -E-something?
We could just return from snprintf() when it does not return PIPE_CRC_LINE_LEN instead of reading all entries.
Anyway, shouldn't we fix hex to decimal conv.? Or is the value incorrect when entry->frame in decimal exceeds 8 chars?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0}static const struct
file_operationsi915_pipe_crc_fops= {Signature · 1 line
2.5.5
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/2] drm/i915: Fix the return value of pipe crc read function.
In reply to Rodrigo ViviQuoted 21 lines · Rodrigo Vivi
A
read(fd, buf, len)function should return the number of bytes read. In our case we need to return the number of bytes we copy to user, instead of returning the number of bytes we read internally.It was really strange when I saw i-g-t test case using len '54' but getting '56' as return. First thought was how do we read more than we asked? But also I checked and there was really only 54. Until I realized it was all our fault. EFAULT!
Signed-off-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/i915_debugfs.c +0
-0
drivers/gpu/drm/i915/i915_debugfs.c i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count, · line 3662
Quoted 5 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-1@@ -3659,7 +3659,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); -return bytes_read; +return PIPE_CRC_LINE_LEN ;
This will no loose entries if you have more than 1 crc ready to be read. I think better to WARN_ON if snprintf doesn't give us the expected length, and then correct bytes_read to match.
-Daniel
Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0}static const struct file_operations i915_pipe_crc_fops = {Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Patchwork
CI✗ Ro.CI.BAT: failure for series starting with [1/2] drm/i915: Fix copy_to_user usage for pipe_crc
In reply to Rodrigo Vivi== Series Details ==
== Series Details ==
Series: series starting with [1/2] drm/i915: Fix copy_to_user usage for pipe_crc
URL : https://patchwork.freedesktop.org/series/10573/
State : failure
== Summary ==
Series 10573v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/10573/revisions/1/mbox
Test kms_cursor_legacy:
Subgroup basic-cursor-vs-flip-legacy:
pass -> FAIL (ro-byt-n2820)
Subgroup basic-flip-vs-cursor-legacy:
pass -> FAIL (fi-skl-i7-6700k)
Test kms_frontbuffer_tracking:
Subgroup basic:
pass -> DMESG-FAIL (ro-bdw-i7-5557U)
skip -> FAIL (ro-ilk1-i5-650)
pass -> DMESG-FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> DMESG-FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-snb-i7-2620M)
pass -> DMESG-FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (fi-hsw-i7-4770k)
pass -> FAIL (fi-snb-i7-2600)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-byt-n2820)
pass -> FAIL (fi-skl-i7-6700k)
pass -> FAIL (ro-skl3-i5-6260u)
Test kms_pipe_crc_basic:
Subgroup hang-read-crc-pipe-a:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-ilk1-i5-650)
pass -> FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-snb-i7-2620M)
pass -> FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (fi-snb-i7-2600)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-byt-n2820)
pass -> FAIL (ro-skl3-i5-6260u)
Subgroup hang-read-crc-pipe-b:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-ilk1-i5-650)
pass -> FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-snb-i7-2620M)
pass -> FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (fi-snb-i7-2600)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-byt-n2820)
pass -> FAIL (ro-skl3-i5-6260u)
Subgroup hang-read-crc-pipe-c:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-skl3-i5-6260u)
Subgroup nonblocking-crc-pipe-a:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-ilk1-i5-650)
pass -> FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-snb-i7-2620M)
pass -> FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (fi-hsw-i7-4770k)
pass -> FAIL (fi-snb-i7-2600)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-byt-n2820)
pass -> FAIL (fi-skl-i7-6700k)
pass -> FAIL (ro-skl3-i5-6260u)
Subgroup nonblocking-crc-pipe-a-frame-sequence:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-ilk1-i5-650)
pass -> FAIL (ro-hsw-i3-4010u)
pass -> FAIL (fi-skl-i5-6260u)
pass -> FAIL (ro-bdw-i7-5600u)
pass -> FAIL (ro-snb-i7-2620M)
pass -> FAIL (ro-bdw-i5-5250u)
pass -> FAIL (ro-hsw-i7-4770r)
pass -> FAIL (fi-hsw-i7-4770k)
pass -> FAIL (fi-snb-i7-2600)
pass -> FAIL (ro-ivb-i7-3770)
pass -> FAIL (ro-ivb2-i7-3770)
pass -> FAIL (ro-byt-n2820)
pass -> FAIL (fi-skl-i7-6700k)
pass -> FAIL (ro-skl3-i5-6260u)
Subgroup nonblocking-crc-pipe-b:
pass -> FAIL (ro-bdw-i7-5557U)
pass -> FAIL (ro-ilk1-i5-650)
pass -> FAIL (ro-hsw-i3-4010u)WARNING: Long output truncated
Results at /archive/results/CI_IGT_test/RO_Patchwork_1673/
aa8628c drm-intel-nightly: 2016y-08m-02d-14h-10m-12s UTC integration manifest be0abf9 drm/i915: Fix the return value of pipe crc read function. e9fa366 drm/i915: Fix copy_to_user usage for pipe_crc
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 23 lines · Rodrigo Vivi
Copy to user return the number of bytes it couldn't write and zero on success. So any number different than 0 should be considered a fault, not only when it doesn't write the full size.
Signed-off-by Rodrigo Vivi <[email protected]>--- drivers/gpu/drm/i915/i915_debugfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpu/drm/i915/i915_debugfs.c +0
-1@@ -3632,7 +3632,6 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,while (n_entries >0 ) {struct intel_pipe_crc_entry *entry = &pipe_crc->entries[pipe_crc->tail]; -int ret;if (CIRC_CNT (pipe_crc->head, pipe_crc->tail,INTEL_PIPE_CRC_ENTRIES_NR ) <1 )
drivers/gpu/drm/i915/i915_debugfs.c i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count, · line 3651
Quoted 6 lines
drivers/gpu/drm/i915/i915_debugfs.c +1
-2@@ -3649,8 +3648,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); - ret =copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ); -if (ret ==PIPE_CRC_LINE_LEN ) +if (!copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ))
A bad '!' snuck in.
Quoted 10 lines
drivers/gpu/drm/i915/i915_debugfs.c +0
-0return -EFAULT ; user_buf +=PIPE_CRC_LINE_LEN ;Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Quoted 6 lines · Rodrigo Vivi
Copy to user return the number of bytes it couldn't write and zero on success. So any number different than 0 should be considered a fault, not only when it doesn't write the full size.
Signed-off-by Rodrigo Vivi <[email protected]>
I audited all the other places we use copy_*_user. We have a bit a mess between negative errno and unwritten bytes for our own copy functions, but seems consistent (except this one here).
Quoted 33 lines
--- drivers/gpu/drm/i915/i915_debugfs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/gpu/drm/i915/i915_debugfs.c +1
-3@@ -3632,7 +3632,6 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,while (n_entries >0 ) {struct intel_pipe_crc_entry *entry = &pipe_crc->entries[pipe_crc->tail]; -int ret;if (CIRC_CNT (pipe_crc->head, pipe_crc->tail,INTEL_PIPE_CRC_ENTRIES_NR ) <1 )@@ -3649,8 +3648,7 @@ i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,spin_unlock_irq (&pipe_crc->lock); - ret =copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ); -if (ret ==PIPE_CRC_LINE_LEN ) +if (!copy_to_user (user_buf, buf,PIPE_CRC_LINE_LEN ))return -EFAULT ; user_buf +=PIPE_CRC_LINE_LEN ;Signature · 6 lines
2.5.5 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx