From patchwork Mon Oct 24 11:32:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp460882wru; Mon, 24 Oct 2022 06:42:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6bPgooWw96pJrXFv/9m9sSrgAu727mhxJw1peKveO257M+T4bxvh01po7gwg+XXeEaAFSx X-Received: by 2002:a17:906:5a5f:b0:79f:9f1f:2fef with SMTP id my31-20020a1709065a5f00b0079f9f1f2fefmr11916973ejc.396.1666618959332; Mon, 24 Oct 2022 06:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618959; cv=none; d=google.com; s=arc-20160816; b=HI1lT04iuLH/o0drZHcPxVjtrJDj4OByxsrnTW1JKsPbVLZE1xU27Q4/QYTXkjrZYj mMi3bdSj0TOYGEV2J5kX/+RvL4nuD/p98lxz9Yxwu/hsMdlC3LKgBIljfQu/CKfS5aTI j7ifBi9FfBg9vOAv2yCfypeLjcvUw8ryfnlbiG2Ss6wD955H940I23MQ7wVSFIFDzbsS fMt7+YaBzaYoZQukG4dPjKBUzHfVFhSqB6F+/Vc/AcrAXO/BRMxEWrbZe6dNErqDQ6yD 0yzkKC5vEay5jiXnfFL2GXAeyyTiJGO0dUWbTydeodod18Wuf2ULa2C93dDymAzjQ/ZQ H1jg== 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=Eg70nrCqtj90NKLr+TETyrVyA2OqDmPIc0oreNgrmZY=; b=fAlqcwA03XJ2pK8pjUUJlyWOZUGbgR8yhaCO6gNprKvxSGgofkz1deUTK1ElxMjXOS VINevJvbm0tEHunmO6V3F3akQ7lo3EmpD3ThlXPFrY1TOpkHQk9pXr5Snu1v8Ok4hvsR IC9Ldvql3RMEia5Usikn06SqD8b3VOkLiJPGSfOlhaUJfpNrwASSOAZuidtE2PERsSO2 NkgysKkidPqDysJz7GvglQke3aDZqd/0bwJhjJViNLwqYrNTeuliqiyqQvy4J2+3XSoT o8GLWoA7QL42+DiY3Iz5DLAK11Gkf+HulNt1pw0HDuKteu/xTb9YOhoFBLfklmALkgr2 3e5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RaI9TUdN; 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 t4-20020a508d44000000b004574154f09asi26918097edt.529.2022.10.24.06.42.04; Mon, 24 Oct 2022 06:42:39 -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=RaI9TUdN; 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 S232166AbiJXNcn (ORCPT + 99 others); Mon, 24 Oct 2022 09:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235987AbiJXN3T (ORCPT ); Mon, 24 Oct 2022 09:29:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6339AABD78; Mon, 24 Oct 2022 05:32:23 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7EF5B6132F; Mon, 24 Oct 2022 12:32:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E413C433C1; Mon, 24 Oct 2022 12:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614722; bh=7sB32oWCb0KoLBpJX2Qr1UEhrUV8KsBVv2ewNAThFVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RaI9TUdN2fEHRi5BLXXzIRw3uIAP8Bw3HdJboKXAlFUFZbOf2Hn/deSz21W91o08O qYUL66enrNgZquVnzztcb3HeUzCUPF0QLVkT1ku8iCE5GSqKIkY3RHOLKOboTtdzm1 MkFAqLq92b+RALvSJuFZprfvc4Iy/7geCdnJ69Z0= 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.10 369/390] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:32:46 +0200 Message-Id: <20221024113038.721314356@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747576641721431191?= X-GMAIL-MSGID: =?utf-8?q?1747576641721431191?= 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 fb806b33178a..c273eee35aaa 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;