Linux-mtd Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mtd: unlock on error in ioctl
@ 2020-07-27 11:20 Dan Carpenter
  2020-07-27 13:35 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2020-07-27 11:20 UTC (permalink / raw)
  To: Miquel Raynal, Greg Kroah-Hartman
  Cc: Richard Weinberger, kernel-janitors, linux-mtd,
	Vignesh Raghavendra, linux-kernel

We need to unlock before returning on this error path.

Fixes: 210bec567936 ("mtd: properly check all write ioctls for permissions")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/mtd/mtdchar.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 52c120f9fb0d..05f9218592df 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -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;
-- 
2.27.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: unlock on error in ioctl
  2020-07-27 11:20 [PATCH] mtd: unlock on error in ioctl Dan Carpenter
@ 2020-07-27 13:35 ` Greg Kroah-Hartman
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2020-07-27 13:35 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Vignesh Raghavendra, Richard Weinberger, kernel-janitors,
	linux-kernel, linux-mtd, Miquel Raynal

On Mon, Jul 27, 2020 at 02:20:50PM +0300, Dan Carpenter wrote:
> We need to unlock before returning on this error path.
> 
> Fixes: 210bec567936 ("mtd: properly check all write ioctls for permissions")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  drivers/mtd/mtdchar.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
> index 52c120f9fb0d..05f9218592df 100644
> --- a/drivers/mtd/mtdchar.c
> +++ b/drivers/mtd/mtdchar.c
> @@ -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;
> -- 
> 2.27.0
> 

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

thanks,

greg k-h

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-27 11:20 [PATCH] mtd: unlock on error in ioctl Dan Carpenter
2020-07-27 13:35 ` Greg Kroah-Hartman

Linux-mtd Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mtd/0 linux-mtd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mtd linux-mtd/ https://lore.kernel.org/linux-mtd \
		linux-mtd@lists.infradead.org
	public-inbox-index linux-mtd

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-mtd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git