From patchwork Mon Oct 24 11:31:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp624435wru; Mon, 24 Oct 2022 12:51:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6t5Xebqp+lovPCWuD/JeSb5yI/I9Tha2L2L6UayUcn/T2aWtiWE53dOYO44GWZ12pC+Ljz X-Received: by 2002:a63:d34c:0:b0:462:589b:b27e with SMTP id u12-20020a63d34c000000b00462589bb27emr30086275pgi.418.1666641073697; Mon, 24 Oct 2022 12:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666641073; cv=none; d=google.com; s=arc-20160816; b=totJY3vqDcGaApSupILyujp9E+/IuvyQKcvyneYTDiYXARHNnqOWjfJZ5p3zr0ZyPU DFPFcy7ijLoY9tnK9+Li63ngkJwxIooOzaz+qOE4dSPQCYDXIL9+lmDt2mW7zs5J/shO LVlbg6ClD6K12PwnKJ4TlhFyFICxMQWluBLHbrgClSRRGkLaOxyVVisJznm/8gwOtrUG K4OnqsFVJj+wGZn0pQRTYlUI88YnzxzC5w+ZrdsBdYlQ4JNMFJFNBNElFtqBbfu3rYYL FCey/trcnXp0fyi3UuMGAQSyJrVEZAbukPWmUOOig4ftjCVWaVDH8t9cV/oBjPE7ah5h TsTQ== 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=fkHs7PTGNsKuWn8jddUa2j0js2ZLEdlS1d0IzAl8lRg=; b=eACLAPtI36kIVvrzHdzAX8992409F98ALCUkd8nBvM+xCXDi8fQdT62B0yqKPPr5go L9s7qZFQHEfoEIG28GnxPQxUrnWVRIikM+SEauF9ITUhrr4lSRTunz7dLIzVBUazfJwi f1tuU9IhHaZWRJU0Dp+VtKdcRV0nNRC/EHDKESoDD5mQvVqA+OqS1n3O4T3K9K0TbuMP LQ2Zavpcp3/ZxhSXbcBYdPL8eGjh+1Apc1KaQuWfkn9Rl1PORw2jOU+k/NtombEh+nDd GMwCUsGUxfgrakQoTe1/nwffA4caE1vEK2gxSzYcun7i3Xhv8HBN1D5jRxqVaBNw2rAz JZ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y9nM0RJU; 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 e20-20020a63f554000000b0046b2ec0de65si347938pgk.789.2022.10.24.12.50.59; Mon, 24 Oct 2022 12:51:13 -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=y9nM0RJU; 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 S233512AbiJXTqa (ORCPT + 99 others); Mon, 24 Oct 2022 15:46:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233591AbiJXToJ (ORCPT ); Mon, 24 Oct 2022 15:44:09 -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 62012196B63; Mon, 24 Oct 2022 11:12:28 -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 CEC6CB811CB; Mon, 24 Oct 2022 11:54:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 301B5C4314B; Mon, 24 Oct 2022 11:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612470; bh=f6PvnzB2NTuAawVlsGsqh/PREkZdKYRgw4IKCn33zoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9nM0RJULq/ER9Y7EVfF5ymqOtesz2jMHh9KSN1Xkve5fojNCELpqqLvp+RusxaFh 1lcRzUTQleLfIN6FIZG0d4aJJeVUhvdwM/ZyvWlzsOTycYMyuEHqJv/3RoTTZ6FZU2 sVIA1Hqfp/hdZM5u0Jgr10iyIWOD+uofeJXcFPF4= 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.14 200/210] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:31:57 +0200 Message-Id: <20221024113003.474849741@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747599830570122332?= X-GMAIL-MSGID: =?utf-8?q?1747599830570122332?= 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 319c5a1b4a6a..8fd68f45a8df 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;