From patchwork Sat Oct 22 07:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1087710wrr; Sat, 22 Oct 2022 00:37:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lJjNeNOpeslY4q8bInO2MIflNvJcdQLpFRziaKwdAXjLrmu03zzAyB1HTgTn+Wb3xrUzf X-Received: by 2002:a17:907:75d2:b0:7a0:72b8:236a with SMTP id jl18-20020a17090775d200b007a072b8236amr2132267ejc.47.1666424245870; Sat, 22 Oct 2022 00:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424245; cv=none; d=google.com; s=arc-20160816; b=ZU0HnFdXAQPxGpnn12jJo3V91o+6nWO7uQOo9exBf/UccXWkNSqaFmIh5Fb/94IQa/ /KaeMz9730JWOeqMfioUK37MVsPro2o46mHxeVP0kzqdjDuoHcE41i5bwumryDV3tkGL 4EN8g8RZB1wqQhzL68/XuNmLYPg9uYwt2CxDlLNtlBwIXvfOdCeDX1D+/kDj3rQT0vbn ZZ+aEZolzhflsmUs+qSUsBtdDV5oPn4rhkUw+3a5UYah9KL73HcOxemKw0q+yiHoOKri fWnlyK21Aw+VtrGHwbrsfEm/VomItm0VlclVbWd6QR4+n757U4vFlp3HKvIUXoCOxlf0 IX6A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0ey07O3mw8bK6McbG2I2Q+4vEP2gq6ox0PK/zyk3hys=; b=gXwqXfGuMovOFfsSMzssZeH7JFrhpGwC5uoECh/WMoWXUWGdRVzfYxSZGdI97JV2EI h6Jt0G9r5LzNL1YB59Gfv1v51BOVEqO0c/VuKzHtwzNsEDMPoNQJ8epU5Okb81o3xGrN +7tT/sGr26luRWyfW3mIM3t7KWM5OZj0W36eRbQShqYIUtpKMA7CF56+lrfpNfUC5cUR pJTkiR6BWvO3VLjgTSAG6TLBE4cYqErsC0ndKy10Fv0TSAMRXN1xWbzM4Muerki3c+gH 3qB8zeIMh1zABTMwaWt6ccOEwOSI7/6XDnkUWJAzm+cfqghbbK0zoH7C74E9q0sxWinn vOvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="KRRQLXm/"; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v10-20020a056402348a00b0045901aa2468si26308857edc.333.2022.10.22.00.37.01; Sat, 22 Oct 2022 00:37:25 -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=@linuxfoundation.org header.s=korg header.b="KRRQLXm/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230335AbiJVHgK (ORCPT + 99 others); Sat, 22 Oct 2022 03:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiJVHfc (ORCPT ); Sat, 22 Oct 2022 03:35:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E81BCDFF5; Sat, 22 Oct 2022 00:34:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id AC43160AED; Sat, 22 Oct 2022 07:34:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97B5FC43149; Sat, 22 Oct 2022 07:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424093; bh=r6sndrCPLnTm7kILdqqn2LD7psgBrGdbjQMZY6nBT90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KRRQLXm/BWdudsjdLwshK5efecblsa6et4n+/1lmLIBV+E8i1egpUyDvIvahAPb0m xaOLljlEFURSILb9M1QmU47IT6s5MU4KFQmVfgz/vl5mEsnWYNQF3xV7341JbSV0tu U63hlSpfAjwaKzk2aTj9lnksc63LL/77RI5mEAlw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Laurent Pinchart , Kees Cook Subject: [PATCH 5.19 025/717] usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video() Date: Sat, 22 Oct 2022 09:18:24 +0200 Message-Id: <20221022072419.538904799@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747372470008063923?= X-GMAIL-MSGID: =?utf-8?q?1747372470008063923?= From: Nathan Chancellor commit a15e17acce5aaae54243f55a7349c2225450b9bc upstream. 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 Reviewed-by: Laurent Pinchart Reviewed-by: Kees Cook Link: https://lore.kernel.org/r/20220928201921.3152163-1-nathan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_uvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- 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 *uv 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;