* [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns
@ 2024-11-06 18:30 Karol Przybylski
2024-11-07 5:15 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Karol Przybylski @ 2024-11-06 18:30 UTC (permalink / raw)
To: gregkh, paul, tudor.ambarus, Chris.Wulff, david.sands, viro,
m.grzeschik, peter, karprzy7
Cc: linux-usb, linux-kernel, skhan
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns
2024-11-06 18:30 [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns Karol Przybylski
@ 2024-11-07 5:15 ` Greg KH
2024-12-15 11:41 ` Karol P
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2024-11-07 5:15 UTC (permalink / raw)
To: Karol Przybylski
Cc: paul, tudor.ambarus, Chris.Wulff, david.sands, viro, m.grzeschik,
peter, linux-usb, linux-kernel, skhan
On Wed, Nov 06, 2024 at 07:30:32PM +0100, Karol Przybylski wrote:
> 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(-)
What commit id does this fix?
How was this change tested?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns
2024-11-07 5:15 ` Greg KH
@ 2024-12-15 11:41 ` Karol P
2024-12-15 11:52 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Karol P @ 2024-12-15 11:41 UTC (permalink / raw)
To: Greg KH
Cc: paul, tudor.ambarus, Chris.Wulff, david.sands, viro, m.grzeschik,
peter, linux-usb, linux-kernel, skhan
On Thu, 7 Nov 2024 at 06:15, Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Wed, Nov 06, 2024 at 07:30:32PM +0100, Karol Przybylski wrote:
> > 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(-)
>
> What commit id does this fix?
7b07a2a7ca02a, usb: gadget: functionfs: Add DMABUF import interface
>
> How was this change tested?
I compiled the kernel and ran it on my machine.
Are there other ways to reliably test such change?
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns
2024-12-15 11:41 ` Karol P
@ 2024-12-15 11:52 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2024-12-15 11:52 UTC (permalink / raw)
To: Karol P
Cc: paul, tudor.ambarus, Chris.Wulff, david.sands, viro, m.grzeschik,
peter, linux-usb, linux-kernel, skhan
On Sun, Dec 15, 2024 at 12:41:03PM +0100, Karol P wrote:
> On Thu, 7 Nov 2024 at 06:15, Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Wed, Nov 06, 2024 at 07:30:32PM +0100, Karol Przybylski wrote:
> > > 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(-)
> >
> > What commit id does this fix?
>
> 7b07a2a7ca02a, usb: gadget: functionfs: Add DMABUF import interface
Then why not use the Fixes: tag?
> > How was this change tested?
>
> I compiled the kernel and ran it on my machine.
Did you exercise this codepath?
> Are there other ways to reliably test such change?
Exercise the codepath by using the module and passing in a value to test
your change.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-15 11:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-06 18:30 [PATCH] usb: gadget: f_fs: remove unused values and add immediate returns Karol Przybylski
2024-11-07 5:15 ` Greg KH
2024-12-15 11:41 ` Karol P
2024-12-15 11:52 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox