Skip to contentSkip to conversation

drm: not to read outside the boundary for CRC source name.

PATCH In review Dingchen Zhang 6 participants 9 messages Jun 5, 2019 – Jul 26, 2019

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

PATCH 1/2 drm: not to read outside the boundary for CRC source name.

'n-1' is the index to access the last character of CRC source name.

---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_debugfs_crc.c +2 -2
index 585169f0dcc5..e20adef9d623 100644
@@ -131,8 +131,8 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 	if (IS_ERR(source))
 		return PTR_ERR(source);
 
-	if (source[len] == '\n')
-		source[len] = '\0';
+	if (source[len-1] == '\n')
+		source[len-1] = '\0';
 
 	ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
 	if (ret)
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm: Set crc->opened = false before setting crc source to NULL.

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

---
 drivers/gpu/drm/drm_debugfs_crc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs_crc.c +7 -0
index e20adef9d623..0e8bcc130383 100644
@@ -249,6 +249,13 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
 	struct drm_crtc *crtc = filep->f_inode->i_private;
 	struct drm_crtc_crc *crc = &crtc->crc;
 
+	/* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */
+	if (crc->opened) {
+		spin_lock_irq(&crc->lock);
+		crc->opened = false;
+		spin_unlock_irq(&crc->lock);
+	}
+
 	crtc->funcs->set_crc_source(crtc, NULL);
 
 	spin_lock_irq(&crc->lock);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 2/2] drm: Set crc->opened = false before setting crc source to NULL.

Hi Dingchen

I do not know this code, so please await feedback from others on the patch itself.

Quoted 4 lines · Dingchen Zhang

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

Only one pair of name/email per line.
And try to use the full name as reported by scripts/get_maintainer.pl

Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] drm: Set crc->opened = false before setting crc source to NULL.

In reply to Dingchen Zhang
Quoted 5 lines · Dingchen Zhang

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

I wonder how this isn't creating problems for Rockchip with the Analogix bridge.

Harry

Quoted 13 lines
---
 drivers/gpu/drm/drm_debugfs_crc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index e20adef9d623..0e8bcc130383 100644
@@ -249,6 +249,13 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
 	struct drm_crtc *crtc = filep->f_inode->i_private;
 	struct drm_crtc_crc *crc = &crtc->crc;
 

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 261

Quoted 10 lines
drivers/gpu/drm/drm_debugfs_crc.c +7 -0
+	/* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */
+	if (crc->opened) {
+		spin_lock_irq(&crc->lock);
+		crc->opened = false;
+		spin_unlock_irq(&crc->lock);
+	}
+
 	crtc->funcs->set_crc_source(crtc, NULL);
 
 	spin_lock_irq(&crc->lock);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH 2/2] drm: Set crc->opened = false before setting crc source to NULL.

Quoted 26 lines · Harry Wentland
Quoted 5 lines · Dingchen Zhang

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

I wonder how this isn't creating problems for Rockchip with the Analogix bridge.

Harry

Quoted 12 lines
---
 drivers/gpu/drm/drm_debugfs_crc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index e20adef9d623..0e8bcc130383 100644
@@ -249,6 +249,13 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
 	struct drm_crtc *crtc = filep->f_inode->i_private;
 	struct drm_crtc_crc *crc = &crtc->crc;
 
Quoted 6 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 257

Quoted 6 lines
drivers/gpu/drm/drm_debugfs_crc.c +6 -0
+	/* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */
+	if (crc->opened) {
+		spin_lock_irq(&crc->lock);
+		crc->opened = false;
+		spin_unlock_irq(&crc->lock);
+	}

Either you don't need a lock to look at ->opened, or you need it. Not both. Too lazy check which way this is, it's practically w/e here :-) -Daniel

Quoted 9 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 261

Quoted 5 lines
drivers/gpu/drm/drm_debugfs_crc.c +1 -0
+
 	crtc->funcs->set_crc_source(crtc, NULL);
 
 	spin_lock_irq(&crc->lock);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [PATCH 2/2] drm: Set crc->opened = false before setting crc source to NULL.

Quoted 6 lines · Daniel Vetter
Quoted 5 lines · Harry Wentland
Quoted 4 lines · Dingchen Zhang

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

The Cc: need to be cleaned up before merge like you did with your other patch.

Quoted 21 lines
Quoted 21 lines
Quoted 1 line

I wonder how this isn't creating problems for Rockchip with the Analogix bridge.

Harry

Quoted 12 lines
---
  drivers/gpu/drm/drm_debugfs_crc.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index e20adef9d623..0e8bcc130383 100644
@@ -249,6 +249,13 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
  	struct drm_crtc *crtc = filep->f_inode->i_private;
  	struct drm_crtc_crc *crc = &crtc->crc;
 
Quoted 10 lines
Quoted 6 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 257

Quoted 6 lines
drivers/gpu/drm/drm_debugfs_crc.c +6 -0
+	/* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */
+	if (crc->opened) {
+		spin_lock_irq(&crc->lock);
+		crc->opened = false;
+		spin_unlock_irq(&crc->lock);
+	}

Either you don't need a lock to look at ->opened, or you need it. Not both. Too lazy check which way this is, it's practically w/e here :-) -Daniel

The check on crc->opened should probably just be dropped since it's not actually doing anything here.

With those fixed, this patch is:

Nicholas Kazlauskas

Quoted 11 lines
Quoted 10 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 261

Quoted 6 lines
drivers/gpu/drm/drm_debugfs_crc.c +1 -0
+
  	crtc->funcs->set_crc_source(crtc, NULL);
 
  	spin_lock_irq(&crc->lock);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [PATCH 2/2] drm: Set crc->opened = false before setting crc source to NULL.

In reply to Daniel Vetter
Quoted 27 lines · Daniel Vetter
Quoted 26 lines · Harry Wentland
Quoted 5 lines · Dingchen Zhang

to terminate the while-loop in drm_dp_aux_crc_work when drm_dp_start/stop_crc are called in the hook to set crc source.

I wonder how this isn't creating problems for Rockchip with the Analogix bridge.

Harry

Quoted 12 lines
---
  drivers/gpu/drm/drm_debugfs_crc.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index e20adef9d623..0e8bcc130383 100644
@@ -249,6 +249,13 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
  	struct drm_crtc *crtc = filep->f_inode->i_private;
  	struct drm_crtc_crc *crc = &crtc->crc;
 
Quoted 11 lines
Quoted 6 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 257

Quoted 6 lines
drivers/gpu/drm/drm_debugfs_crc.c +6 -0
+	/* terminate the infinite while loop if 'drm_dp_aux_crc_work' running */
+	if (crc->opened) {
+		spin_lock_irq(&crc->lock);
+		crc->opened = false;
+		spin_unlock_irq(&crc->lock);
+	}

Either you don't need a lock to look at ->opened, or you need it. Not both. Too lazy check which way this is, it's practically w/e here :-) -Daniel

Hi Daniel,

Thanks for pointing out and sorry for late reply. Will create the new patch for that.

-Dingchen

Quoted 10 lines
Quoted 9 lines

drivers/gpu/drm/drm_debugfs_crc.c static int crtc_crc_release(struct inode *inode, struct file *filep) · line 261

Quoted 5 lines
drivers/gpu/drm/drm_debugfs_crc.c +1 -0
+
  	crtc->funcs->set_crc_source(crtc, NULL);
 
  	spin_lock_irq(&crc->lock);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw
In reply to Dingchen Zhang

Hi Dingchen.

Thanks for the patch!

Quoted 3 lines · Dingchen Zhang

'n-1' is the index to access the last character of CRC source name.

Cc Leo Li <[email protected]>, Harry Wentland<[email protected]>

Please add only one person (mail address) per Cc: line

I dunno if this is a hard rule, but this is what we always do.

Quoted 10 lines
---
 drivers/gpu/drm/drm_debugfs_crc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index 585169f0dcc5..e20adef9d623 100644

drivers/gpu/drm/drm_debugfs_crc.c static ssize_t crc_control_write(struct file *file, const char __user *ubuf, · line 135

Quoted 7 lines
drivers/gpu/drm/drm_debugfs_crc.c +2 -2
@@ -131,8 +131,8 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
 	if (IS_ERR(source))
 		return PTR_ERR(source);
 
-	if (source[len] == '\n')
-		source[len] = '\0';
+	if (source[len-1] == '\n')
+		source[len-1] = '\0';

In the kernel code we add spaces around operators. So the above should be: source[len - 1]

Details aside.
memdup_user_nul() which is called gurantee that the buffer is null terminated. The buffer allocated is len + 1 and the last byte in the buffer is set to '\0' in memdup_user_nul().

So the right fix is to kill the two lines since they have no effect. Could you please verify my analysis, and if you agree submit a new patch.

Thanks,
Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Thanks for the reply, Sam.

Quoted 37 lines · Sam Ravnborg

Hi Dingchen.

Thanks for the patch!

Quoted 3 lines · Dingchen Zhang

'n-1' is the index to access the last character of CRC source name.

Cc Leo Li <[email protected]>, Harry Wentland<[email protected]>

Please add only one person (mail address) per Cc: line

I dunno if this is a hard rule, but this is what we always do.

Quoted 10 lines
---
  drivers/gpu/drm/drm_debugfs_crc.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_debugfs_crc.c +0 -0
index 585169f0dcc5..e20adef9d623 100644

drivers/gpu/drm/drm_debugfs_crc.c static ssize_t crc_control_write(struct file *file, const char __user *ubuf, · line 135

Quoted 7 lines
drivers/gpu/drm/drm_debugfs_crc.c +2 -2
@@ -131,8 +131,8 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
  	if (IS_ERR(source))
  		return PTR_ERR(source);
 
-	if (source[len] == '\n')
-		source[len] = '\0';
+	if (source[len-1] == '\n')
+		source[len-1] = '\0';

In the kernel code we add spaces around operators. So the above should be: source[len - 1]

Details aside.
memdup_user_nul() which is called gurantee that the buffer is null terminated. The buffer allocated is len + 1 and the last byte in the buffer is set to '\0' in memdup_user_nul().

Quoted 6 lines

So the right fix is to kill the two lines since they have no effect. Could you please verify my analysis, and if you agree submit a new patch.

Thanks,
Sam

You are right the buffer is null terminated at 'len+1'th. However, the patch is to actually remove the new line character. For example, if you type 'echo "abcd" > /sys/kernel/debugfs/dri/0/crtc-x/crc/control' in debugfs, the 'len' here is 5, where the 5th is the new line.

I will submit a new patch with a clear title and modify the format.

Thanks,

Dingchen

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel