From patchwork Mon Oct 24 11:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp443071wru; Mon, 24 Oct 2022 06:08:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hy2iLx3tUrIBthL12BojhYieIlpDdCkdseGyYUCpneWUr4SVZ2c907ebuKmscNyc4zcgQ X-Received: by 2002:a17:902:f28b:b0:186:b069:63fc with SMTP id k11-20020a170902f28b00b00186b06963fcmr3083681plc.38.1666616924167; Mon, 24 Oct 2022 06:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666616924; cv=none; d=google.com; s=arc-20160816; b=O7onlaaQjimrEtVqPNWvGr0DHc0Qdt8AOTpSzMnt27a/ld3nD+L0cTiWlOosT3/PwX 2b8M2Xp5xyEe9nx3gatrAbQmhJkT727UU8j/L83zMnhFOVxRww/yyxy0qFF1U1EWuYDq A417ljwurmC1jRf3VtvOIKBrF18cUGWGRiTHll/I61quM0GGD9Hmw/byQmDoBSJweHKM fiW0y3e50v5BIFTdPTHB/xkiGH+MmcO+hLHxSHu4Mq9+bC38Cn/eVXWia3ginPsXOO67 9RcRcWQch7nHfVlOrmsLRbYOLYh03MPs7h3JESbGw5y5N//1IcAYbZysLB0DUw3G0JNd 35Ww== 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=jijqDHg8N3J5fs0sn+F9hYGAHbBUwAfq1sQwLtj29bE+36BSp/W0tKGO719F5v1SgO iEmRy4HrjwS2FE03KZNJT38XHGkPT55lEeJE+pfErSpEdlzc8A6HRYdHMUTjn0SDoJl/ WjKzS8U7X7iOz/5vYPeB6ENiiTnfpXDyYDoxEEIpGFtl7xLX09dT1mXxYWVcdYmbeP3Q kWqnSXwGHvOGGWgq+ghuHJ3B2/ov0cTF+SOb0DocY2wpVrGY85Z6AU/+63SzbfSnzvnw nVCVFGtWpbXOTwG/0eBB45Q4JYVg7YXpHyQ3uM9eCYaHmVMQJqZ7URmACocP0n8Kpy/K 6Zig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bjNoZrnB; 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 d19-20020a621d13000000b0056ba7a9182asi5975176pfd.250.2022.10.24.06.08.25; Mon, 24 Oct 2022 06:08:44 -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=bjNoZrnB; 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 S235464AbiJXNHB (ORCPT + 99 others); Mon, 24 Oct 2022 09:07:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234960AbiJXNE5 (ORCPT ); Mon, 24 Oct 2022 09:04:57 -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 5FECA27FDB; Mon, 24 Oct 2022 05:20:38 -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 926A9B81619; Mon, 24 Oct 2022 12:15:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4EF6C433C1; Mon, 24 Oct 2022 12:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613708; bh=HvREvjpTGd2nnADgQQw/gRZ+w1eD5zoouABPrVUj1hQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bjNoZrnBXCJghhlkddr9a4hAszZTF4uEXqAbOptsjhMBzi8P9DMF6tpda0W86RDb5 D1t9JMQRERyoxUqYegMqe84oT3vas/wBiomPwuJmrlbic9PKZEcJOPu881gxn8GKMw IyVdnlbthFlyYogKcHoymeq2jYZGN9LFrBQr9HBA= 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.4 239/255] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:32:29 +0200 Message-Id: <20221024113011.161452156@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@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?1747574507504463282?= X-GMAIL-MSGID: =?utf-8?q?1747574507504463282?= 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;