From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 394E7C352A1 for ; Tue, 6 Dec 2022 21:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229637AbiLFVVz (ORCPT ); Tue, 6 Dec 2022 16:21:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbiLFVVx (ORCPT ); Tue, 6 Dec 2022 16:21:53 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BAB47325; Tue, 6 Dec 2022 13:21:52 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3E1933D7; Tue, 6 Dec 2022 22:21:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1670361711; bh=OrJsCJNo27Qlp3rbIbQPFuVvMQMYEBOzgkHtwGy1OdQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FwiImNRf7ALJLdu5YaC8qgkXWb8AnAiJDZIVuV9VEhI6Odi/lmjE10LQ8JHi3ru+V 4M5VR3lKZO+3vXLGdDoP6c4Hbr/GiVqDzZvox4qcbnQld9WxuvZy85p2mS1s8LfhYR x2qMpgVuMRxMzjpCvdkCd8mwF4Y4Bqn4EW5LLHTA= Date: Tue, 6 Dec 2022 23:21:48 +0200 From: Laurent Pinchart To: Szymon Heidrich Cc: dan.scally@ideasonboard.com, Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] usb: gadget: uvc: Prevent buffer overflow in setup handler Message-ID: References: <9ffc4812-ab45-d7f9-7d93-fcacf629a754@ideasonboard.com> <20221206141301.51305-1-szymon.heidrich@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221206141301.51305-1-szymon.heidrich@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Szymon, Thank you for the patch. On Tue, Dec 06, 2022 at 03:13:01PM +0100, Szymon Heidrich wrote: > Setup function uvc_function_setup permits control transfer > requests with up to 64 bytes of payload (UVC_MAX_REQUEST_SIZE), > data stage handler for OUT transfer uses memcpy to copy req->actual > bytes to uvc_event->data.data array of size 60. This may result > in an overflow of 4 bytes. > > Fixes: cdda479f15cd ("USB gadget: video class function driver") > Signed-off-by: Szymon Heidrich Good catch. Reviewed-by: Laurent Pinchart > --- > V1 -> V2: Corrected commit message and changed ?: in favor of min_t > V2 -> V3: Added fixes tag > > drivers/usb/gadget/function/f_uvc.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c > index 6e196e061..4419b7972 100644 > --- a/drivers/usb/gadget/function/f_uvc.c > +++ b/drivers/usb/gadget/function/f_uvc.c > @@ -216,8 +216,9 @@ uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req) > > memset(&v4l2_event, 0, sizeof(v4l2_event)); > v4l2_event.type = UVC_EVENT_DATA; > - uvc_event->data.length = req->actual; > - memcpy(&uvc_event->data.data, req->buf, req->actual); > + uvc_event->data.length = min_t(unsigned int, req->actual, > + sizeof(uvc_event->data.data)); > + memcpy(&uvc_event->data.data, req->buf, uvc_event->data.length); > v4l2_event_queue(&uvc->vdev, &v4l2_event); > } > } -- Regards, Laurent Pinchart