Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7360320rwi; Mon, 24 Oct 2022 13:31:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xT7TvsxK63BkVMY7hjxmpE4nOZkbZlm+cvI/PH3wg/3h58/gEet3z9x/N1lHtGIgEmlDM X-Received: by 2002:a17:907:1623:b0:78d:9e8b:171d with SMTP id hb35-20020a170907162300b0078d9e8b171dmr29117377ejc.309.1666643466044; Mon, 24 Oct 2022 13:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643466; cv=none; d=google.com; s=arc-20160816; b=Jk+3Sj0lFoq47ns+FaIKkkDMD+fdFAFZc16+ntRFdBKa6M0EQufZ7dvGfG3gwIf63T qF5uMbA2jpJVSCFubR88Ah3S//H8jAAxc4++ksxSNR7/K4ZZNv4QGUXAhRrE5JGw0C6C lM3h8r1E07reV5ICYk9fzIiZoJdLBE9imqaQ+1pRz5QpTziMUqmPdZm6gz6bs6Hgc6Cm 5LxTSkftQC1Cr5mgnQjWZlM69FpHAV0e2mjk8vdn8QeNqa/pFKciWGBQ1mflS7r85Hrd E6KevVtaTdWmNvqAQB4EwFqqFZtVegelDmRWZ4VuIcJFctQhQit4i9KjPCgKRLNTg+hx 0nUw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk8-20020a1709077f8800b0073d8659db5csi658664ejc.966.2022.10.24.13.30.40; Mon, 24 Oct 2022 13:31:06 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; -- 2.35.1