Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1136701rwb; Wed, 28 Sep 2022 13:49:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6SQ4ls+uncYDY9FjmHK0vXrjSCzzifJBww64lrVcNO1sPQY9L/UPZhHeZej+87fjf6gxkG X-Received: by 2002:a17:906:2699:b0:781:a473:9791 with SMTP id t25-20020a170906269900b00781a4739791mr29433281ejc.644.1664398178402; Wed, 28 Sep 2022 13:49:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664398178; cv=none; d=google.com; s=arc-20160816; b=e6vNMgcAn+U0VMqPpifN1ocdAYnc+wU3azr9wlMx0/N3TYrjGTAF63G7DwGDvjccJZ it4/ie2mptBepJL8DVIMwGPPKujcE9gWwkk5aGoU9BZxlI6Ssfiiy8a/gMq/GGSmfcHv nyQYI1/2g67CsCRinIsp3g3LLuTGztVaoFG3eJ7X7yfXfn3mwgX3kJi0CJjXR5Ys8TAt cGKdsNg0GSfe+WyvWQydpLNmWn4otE4qCVCPhDBQ07VwKJFvgSNC81CLmMc24BLMtk0y 8GjLNGLgChyl9RUObQeTlnuXluJ9xD0SofqTYfw5w9Wc2IF73oge0YWSn/1NErctGedK 7+Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=uwTNcfoB5nWTp9FTqjPiqIDVz+HskSsQwV/A1WwWYCo=; b=WD3zqUVPz9xhrmfJBmv0utni6rBWg0f61oIVTMK3NWwWYqiyrRDIiwq/Dey+9Z1b5T p+m+x6+wLdvxMACLTe/C5tqu05WWz+OpGkZQHzqgLrQPypfOez4CwANzouz/RWdkA8IZ c7w+2TayHKqnRw4C82SWj/mjCZnaDc61+O0SjYmlXO0De5Wigf82Okoqht8nO3U4VTPM 11dJc/YZefSDZ7BmaOuzgZfsV6eCkREkaWmrxIYlzU7pUQvg4BZ8trOB00eK/GxMCe0X sXE/oYDZRSYPEnL7zG8j79+2L8qgSB14J+t0JChfArHoxgkEPOSV+Wwe6/MhKZPMX9MW 2JUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=O9cJMKfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he41-20020a1709073da900b007803b5893f2si7480859ejc.672.2022.09.28.13.49.13; Wed, 28 Sep 2022 13:49:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=O9cJMKfa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234141AbiI1UWO (ORCPT + 99 others); Wed, 28 Sep 2022 16:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233629AbiI1UWK (ORCPT ); Wed, 28 Sep 2022 16:22:10 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D0A74DFD; Wed, 28 Sep 2022 13:22:01 -0700 (PDT) Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 433796BE; Wed, 28 Sep 2022 22:21:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1664396518; bh=ZVnn371ol3lmPTrCOy0R2eVwN8pZhNwjNTXUvUfoQqM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=O9cJMKfab+8Wu7hvOGEeJzXmby9I9rmPYVjTCDIut4xl2qcGwcltJAeye5Vc0ZNXV 7oTexktRi/HHJVw0MJ+K2+aqBhXuXl8Icia68vemMqeYHEy5jQEz2ZqYO2WjZBEhrS dnSFiRMWDucfJyWIt8uYq0sVrl2tD8PVzi1Xm8LU= Date: Wed, 28 Sep 2022 23:21:56 +0300 From: Laurent Pinchart To: Nathan Chancellor Cc: Michael Grzeschik , Felipe Balbi , Greg Kroah-Hartman , Kees Cook , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, stable@vger.kernel.org Subject: Re: [PATCH] usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video() Message-ID: References: <20220928201921.3152163-1-nathan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220928201921.3152163-1-nathan@kernel.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nathan, Thank you for the patch. On Wed, Sep 28, 2022 at 01:19:21PM -0700, Nathan Chancellor wrote: > When building s390 allmodconfig after commit 9b91a6523078 ("usb: gadget: > uvc: increase worker prio to WQ_HIGHPRI"), the following error occurs: > > In file included from ../include/linux/string.h:253, > from ../include/linux/bitmap.h:11, > from ../include/linux/cpumask.h:12, > from ../include/linux/smp.h:13, > from ../include/linux/lockdep.h:14, > from ../include/linux/rcupdate.h:29, > from ../include/linux/rculist.h:11, > from ../include/linux/pid.h:5, > from ../include/linux/sched.h:14, > from ../include/linux/ratelimit.h:6, > from ../include/linux/dev_printk.h:16, > from ../include/linux/device.h:15, > from ../drivers/usb/gadget/function/f_uvc.c:9: > In function ‘fortify_memset_chk’, > inlined from ‘uvc_register_video’ at ../drivers/usb/gadget/function/f_uvc.c:424:2: > ../include/linux/fortify-string.h:301:25: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning] > 301 | __write_overflow_field(p_size_field, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > This points to the memset() in uvc_register_video(). It is clear that > the argument to sizeof() is incorrect, as uvc->vdev (a 'struct > video_device') is being zeroed out but the size of uvc->video (a 'struct > uvc_video') is being used as the third arugment to memset(). > > pahole shows that prior to commit 9b91a6523078 ("usb: gadget: uvc: > increase worker prio to WQ_HIGHPRI"), 'struct video_device' and > 'struct ucv_video' had the same size, meaning that the argument to > sizeof() is incorrect semantically but there is no visible issue: > > $ pahole -s build/drivers/usb/gadget/function/f_uvc.o | grep -E "(uvc_video|video_device)\s+" > video_device 1400 4 > uvc_video 1400 3 > > After that change, uvc_video becomes slightly larger, meaning that the > memset() will overwrite by 8 bytes: > > $ pahole -s build/drivers/usb/gadget/function/f_uvc.o | grep -E "(uvc_video|video_device)\s+" > video_device 1400 4 > uvc_video 1408 3 > > Fix the arugment to sizeof() so that there is no overwrite. > > Cc: stable@vger.kernel.org > Fixes: e4ce9ed835bc ("usb: gadget: uvc: ensure the vdev is unset") > Signed-off-by: Nathan Chancellor Good catch. Reviewed-by: Laurent Pinchart > --- > drivers/usb/gadget/function/f_uvc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c > index 71669e0e4d00..86bb0098fb66 100644 > --- a/drivers/usb/gadget/function/f_uvc.c > +++ b/drivers/usb/gadget/function/f_uvc.c > @@ -421,7 +421,7 @@ uvc_register_video(struct uvc_device *uvc) > int ret; > > /* TODO reference counting. */ > - memset(&uvc->vdev, 0, sizeof(uvc->video)); > + memset(&uvc->vdev, 0, sizeof(uvc->vdev)); > uvc->vdev.v4l2_dev = &uvc->v4l2_dev; > uvc->vdev.v4l2_dev->dev = &cdev->gadget->dev; > uvc->vdev.fops = &uvc_v4l2_fops; > > base-commit: f76349cf41451c5c42a99f18a9163377e4b364ff -- Regards, Laurent Pinchart