From patchwork Mon Oct 24 11:32:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9207 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp459122wru; Mon, 24 Oct 2022 06:38:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6PGR9HqSUYntDj7tV3I8bgloSWYrhF42nEQWVDwwJITum3j3Xturt4kOkFCSz7p32/sErF X-Received: by 2002:a17:90b:4b0b:b0:213:227d:149e with SMTP id lx11-20020a17090b4b0b00b00213227d149emr2822109pjb.145.1666618734407; Mon, 24 Oct 2022 06:38:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618734; cv=none; d=google.com; s=arc-20160816; b=AsbQ3McN/QjgIF7SZHJfD2Db//SuDNo5ZVs5gycqPn1wdLFo62x4Y3QehmSU28C1ax cO5OvDB2dLBhS8KRBZaZ3gM5kLvpi4PXje5tE/4vzJ4PE9zHDaQdyz/HOXmhXj1ob+KE mSGe+zjmkCIzKrHNFvw//yMmA6JOMEZKtJCG3MJxE8ySGK1eVw2UzSrRTsJ7gX5PWmR0 b8kHpuK+GVTuK7K8XFJauqCUo1JYMkIAX9o+07M1alZtGE+26GDBwFJu/2+iELS6+qPu KvGusPBCQME0npgsKL2E6v4MPZjeWWSWe7Ia7IrIbGCmyOm7CQFTiLMkcfLDySf5TWzr v7KA== 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=WuxO5I/Q0IGJ5mS5tvLxOPcVP0ypG8rnZIY664CTwhY=; b=bVCDsbU7wC1ylXzT5ufh+vRJT1NvObqvUKvctJG9BAwzfP8RkMijApCVhFTqz0OUVX /Veq8v/PC+Jb0wQyJhbg5wWVRr8jKF5qJvc9yXzGnL5V6jruD4QEfzoCC33Kg+ZlaD5b W4W4Z3FXBO5G90XxXWGTzhQmJw8bk8MBYFrNgsGB7etogrdlmpX3xZyjfihtz9S0/yZh 5TDfx3gLZji9iewlGtUuLvD3WwpcY/UpPcbgUrU68Qq5DQSgBmzxZzRXTyxywfmiCf6C MzMFjqY9biAowa6toseXRfooOFyJZZqWkigvc9yWOpSr/ChjhTo0yV1AonzH2M6G9iD/ v5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nWkcUXVp; 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 t206-20020a635fd7000000b00454a7fa276asi35468032pgb.181.2022.10.24.06.38.39; Mon, 24 Oct 2022 06:38:54 -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=nWkcUXVp; 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 S233988AbiJXNdu (ORCPT + 99 others); Mon, 24 Oct 2022 09:33:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236179AbiJXN34 (ORCPT ); Mon, 24 Oct 2022 09:29:56 -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 71A14AC39F; Mon, 24 Oct 2022 05:33:03 -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 94534B811AB; Mon, 24 Oct 2022 12:04:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3469C433C1; Mon, 24 Oct 2022 12:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613098; bh=HvREvjpTGd2nnADgQQw/gRZ+w1eD5zoouABPrVUj1hQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWkcUXVp1JEMReNU1Tdbl/pWfvo9lsOXhtAnigkvYoOt2kv9VdhXWV7WvDUPOvYxz wxf5igFRBl6CijWWl/gc8khxoD/lLJHDNMFugCy9PqrepQBb3qDVsAPRe5+BgYwOLZ PyXwoJe456vewZcexBO9wyLjKStylmJjUwwMnPG4= 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.19 216/229] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:32:15 +0200 Message-Id: <20221024113006.217091685@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747576406104885347?= X-GMAIL-MSGID: =?utf-8?q?1747576406104885347?= 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 4622400ba4dd..8e83995fc3bd 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;