Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4651037iob; Sun, 8 May 2022 20:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw59mwvU56vN1AE8wUCa8PtWplvkLPwCRv7zbUUNeESAW2lTKkhqnTI0BnU2Xw6f1SCUeH+ X-Received: by 2002:a17:903:286:b0:15e:b2f3:56e5 with SMTP id j6-20020a170903028600b0015eb2f356e5mr14274939plr.79.1652067455653; Sun, 08 May 2022 20:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652067455; cv=none; d=google.com; s=arc-20160816; b=OTF6CkxxLONakZz4RFQd6fpLxUrvXbLRQVXJPCQEmydjWg2lX+736bur+vv5FoqGMK TgDc4XLb00lfFJSPpaa7r8+vmjisGzULghk9+ApWoFx1EuLo+iPOT0W41xLydMLGg3tW 46bpyK4yTOiD5jwTBKLRwcZtxc8uBuGpxITzKgpUel+JyAAl2KGcFwQD3w3Wx+Tfhg+y uo3Iq45l3uVn3fg4KzNBd3lONoCIG385T3alK8DdLdLd+oZD/grzK7GdGWBeI1hgeuQu u+MlGhtPFZWsqlAHT7tikrmfPABlfQJyS1NhikbSIQLoAolMScyWCbTwbV/RPb9rKT4q VXLQ== 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=LyaT0Q6zkElmB0SK/vhZ5+qQeyv7qjaP8ATe3tROy+c=; b=k9AYWsrU8cJlWL8tqPbegy8eTTSmAIIaNRtS8XI3EUeTgYrfq5vCe5lzDwe3bbWYtm PcIeIE51D6J+b9sY0DuCWOqNv3gPIXFme8uWdPHf6PWthSjbydSoMe0q6pYBCyptwFRQ Pl5qxkvfV8KeEm70gPGnMHav5rDQrEvuRY/QHTiIPpfFAio+dyXyVVto+5qkMB9liwVQ Oax/LXd1DHGQPe9UvXiKQiE/D0XHtGMOTG4JhLJQnXUUjaNOymFvOdNXXLlRxdgWLAoc M+PDjWpovbrkBfEkgH7fmACNPpdjvdNXDEoxb4S7Dwva/JZ5UavlzZsUrkVdU4p9g+HO V5tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b+t+srUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bh2-20020a170902a98200b00156f362e9ecsi9852754plb.105.2022.05.08.20.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:37:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b+t+srUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F88EA0BEB; Sun, 8 May 2022 20:36:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356559AbiEDRN5 (ORCPT + 99 others); Wed, 4 May 2022 13:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354933AbiEDRDT (ORCPT ); Wed, 4 May 2022 13:03:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826D24CD76; Wed, 4 May 2022 09:52: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 2A53AB827AB; Wed, 4 May 2022 16:52:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D342BC385A5; Wed, 4 May 2022 16:52:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683155; bh=x0NSc7MEHG10LK5hjOAWgWyyKxJaPB0om7Wljiw3vkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b+t+srUDh5Lh4ZEBnWN3oQfeKPilnwF3K9Gkp73mNf5BCy/xX70E8RYZS0U0BDqtL o5bqhLslKelpnCh9hjSCb1GZvLX176wMXE+XKdrKUh8YNYYEbMCeci5wgDFgO8qzo+ pmuC7vci61Yq8OwNg7TZg+oxVeUHdNxJihmaHnGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Vacura Subject: [PATCH 5.15 020/177] usb: gadget: uvc: Fix crash when encoding data for usb request Date: Wed, 4 May 2022 18:43:33 +0200 Message-Id: <20220504153055.110882915@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153053.873100034@linuxfoundation.org> References: <20220504153053.873100034@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Dan Vacura commit 71d471e3faf90c9674cadc7605ac719e82cb7fac upstream. During the uvcg_video_pump() process, if an error occurs and uvcg_queue_cancel() is called, the buffer queue will be cleared out, but the current marker (queue->buf_used) of the active buffer (no longer active) is not reset. On the next iteration of uvcg_video_pump() the stale buf_used count will be used and the logic of min((unsigned int)len, buf->bytesused - queue->buf_used) may incorrectly calculate a nbytes size, causing an invalid memory access. [80802.185460][ T315] configfs-gadget gadget: uvc: VS request completed with status -18. [80802.185519][ T315] configfs-gadget gadget: uvc: VS request completed with status -18. ... uvcg_queue_cancel() is called and the queue is cleared out, but the marker queue->buf_used is not reset. ... [80802.262328][ T8682] Unable to handle kernel paging request at virtual address ffffffc03af9f000 ... ... [80802.263138][ T8682] Call trace: [80802.263146][ T8682] __memcpy+0x12c/0x180 [80802.263155][ T8682] uvcg_video_pump+0xcc/0x1e0 [80802.263165][ T8682] process_one_work+0x2cc/0x568 [80802.263173][ T8682] worker_thread+0x28c/0x518 [80802.263181][ T8682] kthread+0x160/0x170 [80802.263188][ T8682] ret_from_fork+0x10/0x18 [80802.263198][ T8682] Code: a8c12829 a88130cb a8c130 Fixes: d692522577c0 ("usb: gadget/uvc: Port UVC webcam gadget to use videobuf2 framework") Cc: Signed-off-by: Dan Vacura Link: https://lore.kernel.org/r/20220331184024.23918-1-w36195@motorola.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/uvc_queue.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/usb/gadget/function/uvc_queue.c +++ b/drivers/usb/gadget/function/uvc_queue.c @@ -264,6 +264,8 @@ void uvcg_queue_cancel(struct uvc_video_ buf->state = UVC_BUF_STATE_ERROR; vb2_buffer_done(&buf->buf.vb2_buf, VB2_BUF_STATE_ERROR); } + queue->buf_used = 0; + /* This must be protected by the irqlock spinlock to avoid race * conditions between uvc_queue_buffer and the disconnection event that * could result in an interruptible wait in uvc_dequeue_buffer. Do not