Skip to contentSkip to conversation

mtd: unlock on error in ioctl

PATCH In review Dan Carpenter 2 participants 2 messages Jul 27, 2020

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

PATCH 1/1 mtd: unlock on error in ioctl

We need to unlock before returning on this error path.

Fixes 210bec567936 ("mtd: properly check all write ioctls for permissions")
---
 drivers/mtd/mtdchar.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/mtd/mtdchar.c +5 -2
index 52c120f9fb0d..05f9218592df 100644
@@ -1064,8 +1064,10 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 		struct mtd_oob_buf32 buf;
 		struct mtd_oob_buf32 __user *buf_user = argp;
 
-		if (!(file->f_mode & FMODE_WRITE))
-			return -EPERM;
+		if (!(file->f_mode & FMODE_WRITE)) {
+			ret = -EPERM;
+			goto unlock;
+		}
 
 		if (copy_from_user(&buf, argp, sizeof(buf)))
 			ret = -EFAULT;
@@ -1117,6 +1119,7 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 		ret = mtdchar_ioctl(file, cmd, (unsigned long)argp);
 	}
 
+unlock:
 	mutex_unlock(&mtd_mutex);
 
 	return ret;
Signature · 1 line
2.27.0
#1 lore raw
Quoted 36 lines · Dan Carpenter

We need to unlock before returning on this error path.

Fixes 210bec567936 ("mtd: properly check all write ioctls for permissions")
---
 drivers/mtd/mtdchar.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/mtd/mtdchar.c +5 -2
index 52c120f9fb0d..05f9218592df 100644
@@ -1064,8 +1064,10 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 		struct mtd_oob_buf32 buf;
 		struct mtd_oob_buf32 __user *buf_user = argp;
 
-		if (!(file->f_mode & FMODE_WRITE))
-			return -EPERM;
+		if (!(file->f_mode & FMODE_WRITE)) {
+			ret = -EPERM;
+			goto unlock;
+		}
 
 		if (copy_from_user(&buf, argp, sizeof(buf)))
 			ret = -EFAULT;
@@ -1117,6 +1119,7 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 		ret = mtdchar_ioctl(file, cmd, (unsigned long)argp);
 	}
 
+unlock:
 	mutex_unlock(&mtd_mutex);
 
 	return ret;
Signature · 1 line
2.27.0

I think this is already fixed up in the mtd tree.

thanks,

greg k-h