From patchwork Mon Oct 24 11:31:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp405890wru; Mon, 24 Oct 2022 04:57:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5i2yMzJDYTuQ0TkJuVWf1bkJoCb9Wo5AlOc7zOVpnJzsktITmS15nYn4EkSptbgTugUlhS X-Received: by 2002:a17:903:247:b0:179:b5e1:54b7 with SMTP id j7-20020a170903024700b00179b5e154b7mr33023008plh.84.1666612661169; Mon, 24 Oct 2022 04:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612661; cv=none; d=google.com; s=arc-20160816; b=fsSkpi6JVPd22sPJQdZ4S73S80Qv5VbyARsxgGsQY9cw+FAlS8+dpqk/0COC5U076U tklodbPa8EEPLngiVO81w8Db2uxqGLi/ndo7eH1puJXkGZ5a1BlGLTbeNkxqUsZ/6p/1 ERuvK+y+t2N5XogSRNnMEYaHH+FBdF7jLctnn9mwNQVqD+ywR+eFTg0uV1iLcatisrM2 +iLDbl1qgsPY1Vl3fxjEJzP8tzWn2BQTSORJ7B8jMXbO/tx3bI6JZOYoCz7vLfjF51kj /qjQ7EN7ghyL/s/oN9Jrby/MPc2MHQv6UKXNmXIqn/dArX/HRWZraIJDodhtg/C0iOyd pzlA== 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=oalOrpyosbir6jPMiBqj2HaU6sqdyvuiQeVCe6HiCnI=; b=jUJUu8mRjOinU+EML8Wsxta0TXa+3A5NGGY2E/M3gcZZHJ9v8ER66h04tbbEC5kaI5 IVGL5LVSMOl1k+pv4Ud58YEOj805blPpy9FAFzwDYGi8K3eKjLHyTtl/dD0XBrgSup1b nCl6z304IZoi8BkG5I9oeRDiKVWuyjyyjL0zb2R443X/C2kbZQVdbwvZDBIzWlmJQNVI G9chttnznmQ/3waPilkk4rZfOvmDyuUp6bd6gmPza8uiSQN+LkTByOBV5H5vRh05eC6v rhvN/k6xrsucHo/SrPgAMomD+fWXLg4zQ/zoVt2djCE3rC3T606X6y2bXeTTahH0o+Vt QqIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EPqg7JzD; 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 h13-20020a170902f54d00b0017e22aeca47si36276842plf.552.2022.10.24.04.57.26; Mon, 24 Oct 2022 04:57:41 -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=EPqg7JzD; 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 S232331AbiJXL5I (ORCPT + 99 others); Mon, 24 Oct 2022 07:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbiJXLz2 (ORCPT ); Mon, 24 Oct 2022 07:55:28 -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 99BBB74CE1; Mon, 24 Oct 2022 04:46:43 -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 76A5EB810F5; Mon, 24 Oct 2022 11:45:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE5FDC43148; Mon, 24 Oct 2022 11:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611920; bh=bhDouuUflupWGGnjEU3vG613jCzS1Gy6Wbou3SeQ8uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPqg7JzDya3b98rA+aPcRkDIGMHJLRTvudZ1aMHHohvlNpAQnx6nnaFDpv98AdHct rbpEtZ3xxxjvsLwcEmhzw0cluc1p1UC1/FUz2pyN9oGSx8FKm3ToFX2qaSzR/K5u+z z3hoiWVSw6n1bROrDm/ewAo2An1WReCivcIUazi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Guo , Sasha Levin Subject: [PATCH 4.9 150/159] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:31:44 +0200 Message-Id: <20221024112954.898484057@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747570037636267445?= X-GMAIL-MSGID: =?utf-8?q?1747570037636267445?= 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 8eb3a291ca9d..02ec84ce5ab9 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -785,6 +785,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;