Skip to contentSkip to conversation

cxl: Fix error path on bad ioctl

PATCH Superseded Frederic Barrat 4 participants 6 messages Jun 2, 2017 – Jun 7, 2017 Char and misc drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl: Fix error path on bad ioctl

Fix error path if we can't copy user structure on
CXL_IOCTL_START_WORK ioctl.

---
 drivers/misc/cxl/file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/misc/cxl/file.c +2 -4
index 17b433f1ce23..caa44adfa60e 100644
@@ -160,10 +160,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 	/* Do this outside the status_mutex to avoid a circular dependency with
 	 * the locking in cxl_mmap_fault() */
 	if (copy_from_user(&work, uwork,
-			   sizeof(struct cxl_ioctl_start_work))) {
-		rc = -EFAULT;
-		goto out;
-	}
+			   sizeof(struct cxl_ioctl_start_work)))
+		return -EFAULT;
 
 	mutex_lock(&ctx->status_mutex);
 	if (ctx->status != OPENED) {
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Fred,

Good catch.

Quoted 14 lines · Frederic Barrat

Fix error path if we can't copy user structure on
CXL_IOCTL_START_WORK ioctl.

---
 drivers/misc/cxl/file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/misc/cxl/file.c +0 -0
index 17b433f1ce23..caa44adfa60e 100644

drivers/misc/cxl/file.c static long afu_ioctl_start_work(struct cxl_context *ctx, · line 163

Quoted 8 lines
drivers/misc/cxl/file.c +1 -4
@@ -160,10 +160,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 	/* Do this outside the status_mutex to avoid a circular dependency with
 	 * the locking in cxl_mmap_fault() */
 	if (copy_from_user(&work, uwork,
-			   sizeof(struct cxl_ioctl_start_work))) {
-		rc = -EFAULT;
-		goto out;
-	}
+			   sizeof(struct cxl_ioctl_start_work)))

Bike-shedding a bit, but
s/sizeof(struct cxl_ioctl_start_work)))/sizeof(work)/ would look much cleaner

#3 lore raw
In reply to Frederic Barrat
Quoted 2 lines · Frederic Barrat

Fix error path if we can't copy user structure on
CXL_IOCTL_START_WORK ioctl.

To be clear the error is that returning via the out label will unlock cxl->status_mutex, which has not been locked.

Please spell it out for me :)

This should be:

Fixes 0712dc7e73e5 ("cxl: Fix issues when unmapping contexts")

Am I right?

cheers

Quoted 19 lines
drivers/misc/cxl/file.c +2 -4
index 17b433f1ce23..caa44adfa60e 100644
@@ -160,10 +160,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 	/* Do this outside the status_mutex to avoid a circular dependency with
 	 * the locking in cxl_mmap_fault() */
 	if (copy_from_user(&work, uwork,
-			   sizeof(struct cxl_ioctl_start_work))) {
-		rc = -EFAULT;
-		goto out;
-	}
+			   sizeof(struct cxl_ioctl_start_work)))
+		return -EFAULT;
 
 	mutex_lock(&ctx->status_mutex);
 	if (ctx->status != OPENED) {
Signature · 1 line
2.11.0
#4 lore raw
Quoted 8 lines · Michael Ellerman
Quoted 2 lines · Frederic Barrat

Fix error path if we can't copy user structure on
CXL_IOCTL_START_WORK ioctl.

To be clear the error is that returning via the out label will unlock cxl->status_mutex, which has not been locked.

Quoted 7 lines

Please spell it out for me :)

This should be:

Fixes 0712dc7e73e5 ("cxl: Fix issues when unmapping contexts")

Am I right?

That's correct. I'm about to send a v2 to address Vaibhav's comment and I'll fix the above as well.

Thanks,

Fred

Quoted 22 lines

cheers

Quoted 19 lines
drivers/misc/cxl/file.c +2 -4
index 17b433f1ce23..caa44adfa60e 100644
@@ -160,10 +160,8 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
  	/* Do this outside the status_mutex to avoid a circular dependency with
  	 * the locking in cxl_mmap_fault() */
  	if (copy_from_user(&work, uwork,
-			   sizeof(struct cxl_ioctl_start_work))) {
-		rc = -EFAULT;
-		goto out;
-	}
+			   sizeof(struct cxl_ioctl_start_work)))
+		return -EFAULT;
 
  	mutex_lock(&ctx->status_mutex);
  	if (ctx->status != OPENED) {
Signature · 1 line
2.11.0
#5 lore raw
Quoted 17 lines · Frederic Barrat

Le 06/06/2017 =C3=A0 11:20, Michael Ellerman a =C3=A9crit :

Quoted 12 lines

Frederic Barrat <[email protected]> writes:
=20

Quoted 2 lines

Fix error path if we can't copy user structure on
CXL_IOCTL_START_WORK ioctl.

=20
To be clear the error is that returning via the out label will unlock cxl->status_mutex, which has not been locked.
=20
Please spell it out for me :)
=20
This should be:
=20

Quoted 3 lines
Fixes 0712dc7e73e5 ("cxl: Fix issues when unmapping contexts")

=20
Am I right?

Quoted 2 lines

That's correct. I'm about to send a v2 to address Vaibhav's comment and=20 I'll fix the above as well.

Thanks.

cheers