Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3915376rwi; Sat, 22 Oct 2022 02:07:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4F7RH/CLoI7k4PyqAwPdqWjdf7RoO22z64Y5C25LguSNpA1DkFpHMCUrdS4pVCupvPK8di X-Received: by 2002:a05:6a00:301c:b0:567:6e2c:4c10 with SMTP id ay28-20020a056a00301c00b005676e2c4c10mr19780311pfb.83.1666429677440; Sat, 22 Oct 2022 02:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666429677; cv=none; d=google.com; s=arc-20160816; b=l5t/7ANQZ2HSiOcbfRDXLt824XVEDRzpI55iwZqOl8+sQpjcnBy4PUQ3tjVz47fLgP LNGsY9XIuLUoGN0Gba6qheYxZkjJAV+pVz2XAe3L2FllsBjtmYSw63qAs0v+njc/mfZD 0WZIj2YrRPBKJWJBW+Jfo/srbde5i5F2UQAZOu7t0FDg01AX2lpFKuL7vY6Axo6Yta9x /u7I3Yl0uQNzOYlOdgmrWmZhkyfi1nRXhZKGGgH1QadxSaeprKHTJ0+LYcSVIyoL5Orj eYeQkqvHxSUeJ3MFW5zcx2RPw5hdYh/JC042uuBgprEft+u+GRZZ9Ou3D7V3gvH+4DpN Y2Lw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a25-20020a631a19000000b0045166930a46si29978817pga.609.2022.10.22.02.07.45; Sat, 22 Oct 2022 02:07:57 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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;