From patchwork Sat Oct 22 07:29: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: 7714 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1109584wrr; Sat, 22 Oct 2022 01:49:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM63vavpWvYXE/z9iUfUm2OOqvMM39ASn1Inz2SDmfAnxYVnYpLd7TG9HYkY2DZS19jJ+ep+ X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr21332062edi.121.1666428548533; Sat, 22 Oct 2022 01:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666428548; cv=none; d=google.com; s=arc-20160816; b=BjKh9NmctFsm+BgEC3KiVuY7Z4B/i2pnFDrWEx8I+Qa1SmwkWWBbXBd617Vct7hVcS MaP0tCvTQ/2cEmnPOCUTS2GXOLkZvlOD5s1ykUThVxZc1Vt84/Go0/Ob5M3iBmD5TcoR 0K4MHo0+g6+sVhUbEhSMnu/ARhemTquvfmBxM04/iAn58U573kyhPJIiPv6ukbCi6KRq G94PD5rv3tDpn/wELfEBJy8LC7h65y28HEHpZ9XoQx4LtQxuLRzh7S9edlfDLL80Uvf5 +3D6e4BYIZ+ISgusq8XAqDW4gm8EKZ1Sfg9bdna/vmI2C03ycUxcSMEKt1AxtLSFvnu+ Uvgw== 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=RKTDUWkUciSeeq3A6RkM37kx17U/KmXem/jIRO4xbng=; b=MyyRcOBrBK04Wzu/Ecu6E/aBijVetuuuFGCu6VoSmlgicuDXkeVqYFNHWT4Nqd12UA Kn1zf3O3jAqtgrAnoAm9PjnGFY70d4B9koJRmTyQ7oOVvpgVW8sKx9RyY2mI4BcLHI3I XH13pJvCvslPpEWScAPvG1n0hP0+BUCI39He5qOW9kiTxJFWlo+kQQR3b1UuUjEosNEU eF8MZEhXcSHXnlDMIRFxlJjJFrZD4GYrYBK9ctD02sU4LdMiAfZPIgUfL+O06ZZk96xR NCoOZySLjK0tzV6B0C1fcc0dpxQQIgrIdNgDRoMg5+SAZXeJwWHXBQwdOP5gGj51ZnGk hFaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=C9nbywEU; 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 b13-20020a0564021f0d00b0046054d6b3a8si6385455edb.302.2022.10.22.01.48.44; Sat, 22 Oct 2022 01:49:08 -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=C9nbywEU; 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 S234544AbiJVIsK (ORCPT + 99 others); Sat, 22 Oct 2022 04:48:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235280AbiJVIpH (ORCPT ); Sat, 22 Oct 2022 04:45:07 -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 4F0522ECF66; Sat, 22 Oct 2022 01:09:09 -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 10BD1B82E22; Sat, 22 Oct 2022 08:06:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58A72C433C1; Sat, 22 Oct 2022 08:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425973; bh=yy1LzY/k4eWn7O3Bo53AqA6dt4/zM2XYo6Qw9qUfJl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C9nbywEUmqS7lUmpqM91fNNcnSNbnBNzk56FtIpaC0gm5BeO/eIKPHLEq6Yiz8Eo+ J50M/AgmWxwyTDDINMkhppV5g+HhWJ31TATPQkgpSfpBpEw+H14gWiq8P35EvIQU/w hqYstFFuwx7R9xeBS0bcq0k2B65Yr43bXu+xZ+Lw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Guo , Sasha Levin Subject: [PATCH 5.19 676/717] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Sat, 22 Oct 2022 09:29:15 +0200 Message-Id: <20221022072528.347982177@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747376981308620543?= X-GMAIL-MSGID: =?utf-8?q?1747376981308620543?= 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 51274b87f46c..dc67fff8e941 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;