All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Linkai Gong <gonglinkai@kylinos.cn>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Michael Zimmermann <sigmaepsilon92@gmail.com>,
	Peter Korsgaard <peter@korsgaard.com>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	John Keeping <jkeeping@inmusicbrands.com>,
	William Wu <william.wu@rock-chips.com>,
	Marco Crivellari <marco.crivellari@suse.com>,
	Ethan Tidmore <ethantidmore06@gmail.com>,
	Kees Cook <kees@kernel.org>, Chris Wulff <Chris.Wulff@biamp.com>,
	David Sands <david.sands@biamp.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: f_hid: do not copy_from_user() under a spinlock
Date: Mon, 17 Aug 2026 15:46:04 +0100	[thread overview]
Message-ID: <20260817154604.70427ed1@pumpkin> (raw)
In-Reply-To: <20260817061141.82597-1-gonglinkai@kylinos.cn>

On Mon, 17 Aug 2026 14:11:41 +0800
Linkai Gong <gonglinkai@kylinos.cn> wrote:

> f_hidg_get_report() already copied the report from userspace into a
> new entry, then called copy_from_user() again under
> get_report_spinlock. That can fault and sleep in atomic context.
> 
> Update the existing entry with memcpy() from the copy already taken.
> 
> Fixes: a139c98f760e ("USB: gadget: f_hid: Add GET_REPORT via userspace IOCTL")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linkai Gong <gonglinkai@kylinos.cn>
> ---
>  drivers/usb/gadget/function/f_hid.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
> index 3c6b43d06a6d..e4621e5a0b69 100644
> --- a/drivers/usb/gadget/function/f_hid.c
> +++ b/drivers/usb/gadget/function/f_hid.c
> @@ -667,14 +667,9 @@ static int f_hidg_get_report(struct file *file, struct usb_hidg_report __user *b
>  	ptr = f_hidg_search_for_report(hidg, report_id);
>  
>  	if (ptr) {
> -		/* Report already exists in list - update it */
> -		if (copy_from_user(&ptr->report_data, buffer,
> -				sizeof(struct usb_hidg_report))) {
> -			spin_unlock_irqrestore(&hidg->get_report_spinlock, flags);
> -			ERROR(cdev, "copy_from_user error\n");

How about a patch to remove the ERROR() from the earlier copy_from_user()
error path?

	David

> -			kfree(entry);
> -			return -EINVAL;
> -		}
> +		/* Report already exists; data was copied before taking the lock. */
> +		memcpy(&ptr->report_data, &entry->report_data,
> +		       sizeof(struct usb_hidg_report));
>  		kfree(entry);
>  	} else {
>  		/* Report does not exist in list - add it */


  parent reply	other threads:[~2026-08-17 14:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  6:11 [PATCH] usb: gadget: f_hid: do not copy_from_user() under a spinlock Linkai Gong
2026-08-17  8:39 ` Peter Korsgaard
2026-08-17 14:46 ` David Laight [this message]
2026-08-18  1:17   ` Linkai Gong
2026-08-18  1:21   ` [PATCH] usb: gadget: f_hid: drop ERROR() on copy_from_user() failure Linkai Gong
2026-08-18  6:32     ` Peter Korsgaard
2026-08-18  8:07     ` David Laight
2026-08-18  8:42     ` [PATCH v2] " Linkai Gong

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=20260817154604.70427ed1@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=Chris.Wulff@biamp.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=david.sands@biamp.com \
    --cc=ethantidmore06@gmail.com \
    --cc=gonglinkai@kylinos.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkeeping@inmusicbrands.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=marco.crivellari@suse.com \
    --cc=peter@korsgaard.com \
    --cc=sigmaepsilon92@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=william.wu@rock-chips.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.