From: Karol Przybylski <karprzy7@gmail.com>
To: gregkh@linuxfoundation.org, paul@crapouillou.net,
tudor.ambarus@linaro.org, Chris.Wulff@biamp.com,
david.sands@biamp.com, viro@zeniv.linux.org.uk,
m.grzeschik@pengutronix.de, peter@korsgaard.com,
karprzy7@gmail.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
skhan@linuxfoundation.org
Subject: [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns
Date: Wed, 6 Nov 2024 19:30:32 +0100 [thread overview]
Message-ID: <20241106183032.80155-1-karprzy7@gmail.com> (raw)
In case of faulty copy_from_user call inside ffs_epfile_ioctl, error code is
saved in a variable. However, this variable is later overwritten in every possible
path, which overshadows initial assignment.
This patch fixes it by returning the error code immediately and exiting the function.
Error discovered in coverity scan - CID 1583682
Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
---
drivers/usb/gadget/function/f_fs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 2920f8000bbd..00f52c9bb716 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1735,8 +1735,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
int fd;
if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) {
- ret = -EFAULT;
- break;
+ return -EFAULT;
}
return ffs_dmabuf_attach(file, fd);
@@ -1746,8 +1745,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
int fd;
if (copy_from_user(&fd, (void __user *)value, sizeof(fd))) {
- ret = -EFAULT;
- break;
+ return -EFAULT;
}
return ffs_dmabuf_detach(file, fd);
@@ -1757,8 +1755,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
struct usb_ffs_dmabuf_transfer_req req;
if (copy_from_user(&req, (void __user *)value, sizeof(req))) {
- ret = -EFAULT;
- break;
+ return -EFAULT;
}
return ffs_dmabuf_transfer(file, &req);
--
2.34.1
next reply other threads:[~2024-11-06 18:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 18:30 Karol Przybylski [this message]
2024-11-07 5:15 ` [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns Greg KH
2024-12-15 11:41 ` Karol P
2024-12-15 11:52 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241106183032.80155-1-karprzy7@gmail.com \
--to=karprzy7@gmail.com \
--cc=Chris.Wulff@biamp.com \
--cc=david.sands@biamp.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m.grzeschik@pengutronix.de \
--cc=paul@crapouillou.net \
--cc=peter@korsgaard.com \
--cc=skhan@linuxfoundation.org \
--cc=tudor.ambarus@linaro.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox