Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6833553rwi; Mon, 24 Oct 2022 06:42:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ULgUVLFRH10b+uCp13xUOcBlRNPVFIadXd6gUseMr+t31R3nenRc0Gau6fruDrKQZjKkX X-Received: by 2002:a17:90a:4d04:b0:212:ee1c:b0ec with SMTP id c4-20020a17090a4d0400b00212ee1cb0ecmr11975668pjg.66.1666618942958; Mon, 24 Oct 2022 06:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618942; cv=none; d=google.com; s=arc-20160816; b=G7XEmTDx8xP8PtsUETY7WwjBPWwKESUWrOs9OqsiHGRpKqmFYNMOCffPTv57NeYgk4 z7v7Wou6tCzcWoNJ0JyLth05KKDMQU9HxNNVyyvzFWu0g1LDrWxdEiEhewr4uDYNH9o7 DoI4eTXnXT638SEiw5VnF+/OxOqdc8nGd0CLuk59lEJeZ90srmFxmwfRXUSnQTiN4gG/ x5eL5KKu7jhaQa9qzRZD5IlwpUU5jJ4F8RB1SwbHQScSl9JEDi8Q1yerfXQhXeR87Zl6 4uKErM2OKj75susNNJvuaqEyijztyj5g92cn6n8GN/6J/1mNpgf8QpdAYWBxkbr57Le4 Jzlw== 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 Return-Path: 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.42.00; Mon, 24 Oct 2022 06:42:22 -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 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 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; -- 2.35.1