Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3929951rwi; Sat, 22 Oct 2022 02:24:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4nZe5o0ySr+B20atg+chLz5HAIVZC5DadSBpKqQFZqXB4+4FsEQDZKskPzakyctNFa5WLR X-Received: by 2002:a17:906:4a09:b0:78d:b6bb:ff5f with SMTP id w9-20020a1709064a0900b0078db6bbff5fmr18492925eju.538.1666430658734; Sat, 22 Oct 2022 02:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430658; cv=none; d=google.com; s=arc-20160816; b=dvc8xDK6kBFS2MzvKLelN1XL4Ma8fsnNHzaU3i8ojns48abDzNI3DJSAFjEDwTwn5t 2lGrCg1Fd4Y0J6v/iODPbqcL5nomF0gPL5pWXz2vZoEx/fBNvAB2O8dZocXySHuppIE6 9BTuSYomUDTZoIS44Y81zqDs6t9tPRyCLNGs+oHACl4i8B6OyAaK33pUQJWMLPGcbSUd YWmY066WKmznVZWHz2v/4PmdpJfsWtwvx5670RwceqRidnBEexsx+oFsrsVNZaBbGlNj e61H1n0ezaGeDh6Njmb4V+2rZsB+RVOrNy/0cUd2JMpENWy8zfc9Agg5w2Dd9ufE1Qe1 alQQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a056402270a00b0045dc9b4c034si15180765edd.582.2022.10.22.02.23.54; Sat, 22 Oct 2022 02:24:18 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; -- 2.35.1