Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1133556rwb; Wed, 28 Sep 2022 13:46:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM57PxezjGIY3vk3Dt8HlIcDdTGM8pzE5xdkvBBB4eWtXQoZlRxEx+o8GPlYUD9UhYzPnPG/ X-Received: by 2002:a17:907:1c09:b0:783:80f2:5d38 with SMTP id nc9-20020a1709071c0900b0078380f25d38mr15799838ejc.189.1664397971639; Wed, 28 Sep 2022 13:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664397971; cv=none; d=google.com; s=arc-20160816; b=GGOeaIFHIgis9qginhplir80tMH3a75I1ePEs41DDKWH8vFTS+grEPoIDILyAjAzKP nm0MTIkMqZxf/VX/pmh2eWwCEQj8Uy5KnF+oYi5fQW1eMPvfVatXJa4a7vb6qiy/AHPZ XRt286izLogmzOW+QwnBbgb9qTzFhGIUPErSPf9ketl6FzvM5PbH4PpZLtQ5LAj4Lwhi mJxMmJ9vkSeqD8XRC+NiDU8prtDbxYNHtTjHSoYRXeWYaA/6HxT2umeSShCjXLx4UYBX hqTDTeB8xOzLl+SEuZye35g+2GSdTMyOFpcdvMLUIpBy3xY3PSehHn2GGlRzc/wcLL8X U+Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=R5wsssFCiLXjtusXVdkW52y937O1XQf8Lvgp7tW5rC0=; b=NHetEIaNJnn1tGktzw3bgWEiwtrD9TubN6e7ZqFkO1Tp073G1ay9m95Ru/vi3VNsz0 iiUugxrXQH9icKv0Y19hV3SnFDdyUlq+bLxV6Q5gvQpcX0HR7R/eSxGKEQQsbL2Xo3EQ dN7Dk0dnRDvxmJWlWmwIO+Xz8IVL3Ss2tFRAB110Rfw8sDXZk8VNSG9PIrWScQAIFB9l j38mXELLKHAGWN2L5lvDKE3jy6ia/KkIIix+BEpZfnQ7kU9/mQCup3FzjegoU6aphJCJ P2BPibJC2ceYz17cqQduCdGKX3vJ6UcreRHEAMoq4G9MRSbNzhcZU9GWbjtaS5JGKU0E OvkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DoHRgmj3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss5-20020a170907038500b0077087c45329si5487448ejb.968.2022.09.28.13.45.46; Wed, 28 Sep 2022 13:46:11 -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 header.i=@kernel.org header.s=k20201202 header.b=DoHRgmj3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234527AbiI1UUD (ORCPT + 99 others); Wed, 28 Sep 2022 16:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234345AbiI1UTr (ORCPT ); Wed, 28 Sep 2022 16:19:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 460162DD7; Wed, 28 Sep 2022 13:19:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D6439B821BC; Wed, 28 Sep 2022 20:19:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08D5FC433C1; Wed, 28 Sep 2022 20:19:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664396373; bh=ebQnjLYFYN8w5ZtbeBDwH2D+lWjENaVVH7SS/7ucfec=; h=From:To:Cc:Subject:Date:From; b=DoHRgmj3cGoFFCjxMVKp/SOAkLuEBfXoidm6NHmbibMeRFS94utwF9nJ9gMvIO8gv fZU5/d3PX7WHyBKr6YKWXaYHVZnqgNHT9Rqt3NByzlp6vv8OS9APEx3JuFKmg8LhW7 uW+v12iCkMvAfjzukPwC8WLfvPzLjn3huBIT+nXizLehulHxch+K9Ek0DlKpHLOZAA GtpLgBM5C96uQkkbnt4H8465IGXX8xU7ZjU9eGHWPbtj5J/s9B9rJJzqXrHL/pr8js 9/nn9G5L+BBWDqren5qKMXpourbCo6I8bMzBzeC+9In6HPOQBK19dztfkTR6vb6u2T vrgWOB7jGOfRg== From: Nathan Chancellor To: Laurent Pinchart , Michael Grzeschik , Felipe Balbi , Greg Kroah-Hartman Cc: Kees Cook , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor , stable@vger.kernel.org Subject: [PATCH] usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video() Date: Wed, 28 Sep 2022 13:19:21 -0700 Message-Id: <20220928201921.3152163-1-nathan@kernel.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 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 --- 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 -- 2.37.3