Linux USB
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Avichal Rakesh <arakesh@google.com>
Cc: dan.scally@ideasonboard.com, laurent.pinchart@ideasonboard.com,
	etalvala@google.com, jchowdhary@google.com,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH 1/2] usb: gadget: uvc: Fix use are free during STREAMOFF
Date: Thu, 4 Jan 2024 15:19:08 +0100	[thread overview]
Message-ID: <2024010450-humming-bullion-1af4@gregkh> (raw)
In-Reply-To: <20231215210746.821494-1-arakesh@google.com>

On Fri, Dec 15, 2023 at 01:07:44PM -0800, Avichal Rakesh wrote:
> There is a path that may lead to freed memory being referenced,
> and causing kernel panics.
> 
> The kernel panic has the following stack trace:
> 
> Workqueue: uvcgadget uvcg_video_pump.c51fb85fece46625450f86adbf92c56c.cfi_jt
> pstate: 60c00085 (nZCv daIf +PAN +UAO -TCO BTYPE=--)
> pc : __list_del_entry_valid+0xc0/0xd4
> lr : __list_del_entry_valid+0xc0/0xd4
> Call trace:
>   __list_del_entry_valid+0xc0/0xd4
>   uvc_video_free_request+0x60/0x98
>   uvcg_video_pump+0x1cc/0x204
>   process_one_work+0x21c/0x4b8
>   worker_thread+0x29c/0x574
>   kthread+0x158/0x1b0
>   ret_from_fork+0x10/0x30
> 
> The root cause is that uvcg_video_usb_req_queue frees the uvc_request
> if is_enabled is false and returns an error status. video_pump also
> frees the associated request if uvcg_video_usb_req_queue returns an e
> rror status, leading to double free and accessing garbage memory.

Odd line wrapping :(

> 
> To fix the issue, this patch removes freeing logic from
> uvcg_video_usb_req_queue, and lets the callers to the function handle
> queueing errors as they see fit.
> 
> Signed-off-by: Avichal Rakesh <arakesh@google.com>
> ---
>  drivers/usb/gadget/function/uvc_video.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)

What commit id does this fix?


> 
> diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c
> index 98ba524c27f5..e5db1be14ca3 100644
> --- a/drivers/usb/gadget/function/uvc_video.c
> +++ b/drivers/usb/gadget/function/uvc_video.c
> @@ -277,8 +277,7 @@ static int uvcg_video_usb_req_queue(struct uvc_video *video,
>  	struct list_head *list = NULL;
>  
>  	if (!video->is_enabled) {
> -		uvc_video_free_request(req->context, video->ep);
> -		return -ENODEV;
> +		return -EINVAL;

Isn't this a separate change?  And does it actually matter?

thanks,

greg k-h

  parent reply	other threads:[~2024-01-04 14:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15 21:07 [PATCH 1/2] usb: gadget: uvc: Fix use are free during STREAMOFF Avichal Rakesh
2023-12-15 21:07 ` [PATCH 2/2] usb: gadget: uvc: Remove nested locking Avichal Rakesh
2024-01-04 14:19   ` Greg KH
2024-01-04 14:19 ` Greg KH [this message]
2024-01-04 21:56   ` [PATCH 1/2] usb: gadget: uvc: Fix use are free during STREAMOFF Avichal Rakesh
2024-01-04 21:50 ` [PATCH v2 " Avichal Rakesh
2024-01-04 21:50   ` [PATCH v2 2/2] usb: gadget: uvc: Remove nested locking Avichal Rakesh

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=2024010450-humming-bullion-1af4@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=arakesh@google.com \
    --cc=dan.scally@ideasonboard.com \
    --cc=etalvala@google.com \
    --cc=jchowdhary@google.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /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