From patchwork Wed Oct 19 08:35:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp316052wrs; Wed, 19 Oct 2022 06:07:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5YHZle4mffhJIQSZJeNuOSNVvcJsA70zUgEypmeyZbWRfeFBbd+1/TUu1nC2dplBGIkm7P X-Received: by 2002:a17:90b:110c:b0:205:cfeb:cfb with SMTP id gi12-20020a17090b110c00b00205cfeb0cfbmr9825784pjb.75.1666184830725; Wed, 19 Oct 2022 06:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666184830; cv=none; d=google.com; s=arc-20160816; b=n26nCWQwGTlY6NIMZNjroSVM3w9J+KVbgVf7UKSKRiOSe997nevwBRaGvPA317vYZ+ 0FycAZxnnYKFY67HZd3/q7Xq12ql0OL1j5LB7W9dunR45mpy3EKjtCiPkfyi8W8t5HiL KWU6XV242LdNFKxinBkVuNiKIRfVa+pEoQ7wjmnA+KGaXd1HZzDmMmjhMDHcexEpuKtz o13X2FuG1Ex4rigEt2YzITPSsYwvKQT3Z8HR/Gx+zEbgPjARt7pT8GdFHz6HLlr4Xd9N j13dg2XHK2Vwl/Xof5Db+hibIS93gpys190F/9zJQvq4ltR187kigdsOyMQ2+7pkD7ld EMgw== 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=pF2QpH++cQdHRepIMk45AciEjDxTON3yQuSr7Niwv0M=; b=pcnqNf26TG+b4m9uamYJVbmyVEY1KZD1+xo5DJM5Ks5W+KS1ZVi+mprldCIQjLdAlq w6RhNNjLqVtsx3Dus6Pz9PcobbkspBtQVmGTAZdYKOWzfQz6KcwxANnDHLo3Zg+bLVwu WScsu6ughnwQb6lzHF/r6Rw62UItIuxchQAnG59BathovFst40wgBTROEq1dZKgVl2i+ VgCJBejddTL29OP1oJ/dQ4MzB+lGnNHdj5lx+w6aJUtczZLnAaHawGhNLBZNWAQEQWZW uJby4medWvsfc1VBF4Ua+iFLfzRo4Z5nr5B+tAGnQYHsXewdX8+BKbfByPH7MlCzAfEt kFjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uOJjkhEX; 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 b13-20020a056a000ccd00b00536fa6bbb11si18628190pfv.344.2022.10.19.06.06.48; Wed, 19 Oct 2022 06:07:10 -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=uOJjkhEX; 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 S231633AbiJSM6X (ORCPT + 99 others); Wed, 19 Oct 2022 08:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbiJSM6L (ORCPT ); Wed, 19 Oct 2022 08:58:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD48F2408F; Wed, 19 Oct 2022 05:41:15 -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 sin.source.kernel.org (Postfix) with ESMTPS id 57213CE2167; Wed, 19 Oct 2022 09:15:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D9EEC433D7; Wed, 19 Oct 2022 09:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170943; bh=2fdLn/QEe5cJvzhuHn+H7MqMQb9Zx1z0xrlir9w8xYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOJjkhEX59WzL8hd+xffoA+Se9tUJOE5uHto+l8krl/umeOCjamRgHAFbunhR/wQx hQOWWhpJzXZGFK3cRUztp704LwHjcg0e0nQYkXFelMNqc/XPSljR/1KdeadRskIzr+ k4psaQzFUMk0oNl0jntJMFZIr9yZfDLNIV52uqb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Guo , Sasha Levin Subject: [PATCH 6.0 818/862] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Wed, 19 Oct 2022 10:35:05 +0200 Message-Id: <20221019083326.051998588@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747121425316881698?= X-GMAIL-MSGID: =?utf-8?q?1747121425316881698?= From: Robin Guo [ Upstream commit eea4c860c3b366369eff0489d94ee4f0571d467d ] The usb function device call musb_gadget_queue() adds the passed request to musb_ep::req_list,If the (request->length > musb_ep->packet_sz) and (is_buffer_mapped(req) return false),the rxstate() will copy all data in fifo to request->buf which may cause request->buf out of bounds. Fix it by add the length check : fifocnt = min_t(unsigned, request->length - request->actual, fifocnt); Signed-off-by: Robin Guo Link: https://lore.kernel.org/r/20220906102119.1b071d07a8391ff115e6d1ef@inspur.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/musb/musb_gadget.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index daada4b66a92..6704a62a1665 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -760,6 +760,9 @@ static void rxstate(struct musb *musb, struct musb_request *req) musb_writew(epio, MUSB_RXCSR, csr); buffer_aint_mapped: + fifo_count = min_t(unsigned int, + request->length - request->actual, + (unsigned int)fifo_count); musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *) (request->buf + request->actual)); request->actual += fifo_count;