Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp197973rwi; Wed, 12 Oct 2022 18:33:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5HCy2g/R0fELxhMycIcrEn9o1ZYLnBeQSNsy2xLB8265nA+LH/VsO8qkF5kfeAQKdRHZVc X-Received: by 2002:a05:6a00:1487:b0:563:6367:8a17 with SMTP id v7-20020a056a00148700b0056363678a17mr19223463pfu.85.1665624810940; Wed, 12 Oct 2022 18:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665624810; cv=none; d=google.com; s=arc-20160816; b=NWnPrDd5K8nPEleO/ktoYy9sC5ML3jJ0ZLUmf8qMXW1CqGgpcn/26rYqqSm25SqZVS EUdnybsoYuC3gnc9kX8fABw+FjhMM+ynqwe6rt3/efeepXolAr+GB34YRJIlrLQaDJvJ aMDoEb5L8PJQT9t59c5TrXxiERK+cnfg5HEYhu20Z8PODzcwlSUiKwugesQv0XrydU+M clNRkSoiWngmO/dlX4O5R/v18NNnzb0ZVdObBxPa9TZCExuy1ucmjjx8ZUwhx8iFaDaW 8/kQomo/CKv6qM5Is1L9bf5qpxKfdcIYTTCbctl53LfSDi5XA5zPuteHbGTUTlFws8/o pKKQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pF2QpH++cQdHRepIMk45AciEjDxTON3yQuSr7Niwv0M=; b=zzW5rtYh+F2C+0whnN4XrMuP8FlS6eDosv/408F9EWESLZNdSyn3fQ3iBEesBjoPl8 Toq6IHjkSyeieJRBzToS6whMpo6wpqxY/8DLH3C8eZdjihtDotjFgEi2IlTVdd63R33s to7qjQcPxoEgZ1UNh+zYYfjlHaRmN8dmGol9yMjyXL9z4qwABAmcVEa2Ff90EY0uRpU6 KKch/1r09k6008S9LT2GWPaVv3Z5SDcYNi9dXJxZIFtDznrCptY5sKvtez1sFiab2kiI MZfVNN9fJQSxFTku9TTUp1ck9rNoFb1lDprYjXvWYRQqCQBdNMX1Cb5zIiNiQsXi7ljH lj8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KWUrhJhJ; 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 i10-20020a170902cf0a00b00172db9d9a01si20607808plg.616.2022.10.12.18.33.19; Wed, 12 Oct 2022 18:33:30 -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=KWUrhJhJ; 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 S230016AbiJMAUj (ORCPT + 99 others); Wed, 12 Oct 2022 20:20:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbiJMATZ (ORCPT ); Wed, 12 Oct 2022 20:19:25 -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 048F8E6F74; Wed, 12 Oct 2022 17:17:29 -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 25CF0B81C48; Thu, 13 Oct 2022 00:17:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 261DBC433C1; Thu, 13 Oct 2022 00:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620244; bh=2fdLn/QEe5cJvzhuHn+H7MqMQb9Zx1z0xrlir9w8xYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KWUrhJhJzn2w68A4hJxL18eLOdt2+OcWb0ph7p33aqrcLMydlfJXRHSIWXJ2EXCZl PnQAV8qjS2ucrEdj3y6BEhNAOdPQmYsOCPlkD07PuKqBGgQQGQBckwe93xoA+nqq2r ofjW3KurxkKGd516qsmPcmA59qIpvAMBGbdX3u8g+jF3+x3rLuFYUQgh1+CnkqsYNp 3XBujaVZof4d2qtrc43ffVMD8gdncYCThEL93rTRnQrZsFAnE8lYY4+CYDaEfibzEV Nfr5gHsS5yE7C+xevB8tvTi3rJBrmtkJV+lp2WBbFgWCW5TSI8ju8CqQNYl5VjmzYB vEHgqxI8B7XDw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Robin Guo , Greg Kroah-Hartman , Sasha Levin , b-liu@ti.com, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 38/67] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Wed, 12 Oct 2022 20:15:19 -0400 Message-Id: <20221013001554.1892206-38-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013001554.1892206-1-sashal@kernel.org> References: <20221013001554.1892206-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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: 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; -- 2.35.1