Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1061733rwi; Wed, 19 Oct 2022 06:20:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Mg7cKbInAUHyRjMUi4pZPuMMnrasYziF9fLlZe4jiu8VVRfRMst3P/TSQ2Dih/s3I8pc7 X-Received: by 2002:a05:6402:1555:b0:458:ed89:24e9 with SMTP id p21-20020a056402155500b00458ed8924e9mr7610250edx.55.1666185649765; Wed, 19 Oct 2022 06:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666185649; cv=none; d=google.com; s=arc-20160816; b=A9VmdwPx64Y1S5V+RmBbyU9bfTApMXrIBrkyNm0LRSlh6aym77t4pzjEHXUVqySUQP coiFeZmLlynb//bofnXfBg+IIzZqt/YhaKmLhmepgTTJNfUcXJSqq+j88kKuiWEpH5xu m8MB7YfypRe6HEVmtKwXUHwSWPSFZv1HzW8rx4dGxsEG7NA7I5zG7z3f8itGUFb9bZjj zR3wruWf1VOgtb0Bq+4etoPLdOCRv/sPAm4HytPOKlzLExXXpd64dlL00HX8o35zagWv ExQ30qFhO1n5BNN3bHozLEZd1kbD3fg3LoY5ueOIrqM+sYpuHXTWwSDHM5YNW9IMCucq NS1A== 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=pF2QpH++cQdHRepIMk45AciEjDxTON3yQuSr7Niwv0M=; b=pcnqNf26TG+b4m9uamYJVbmyVEY1KZD1+xo5DJM5Ks5W+KS1ZVi+mprldCIQjLdAlq w6RhNNjLqVtsx3Dus6Pz9PcobbkspBtQVmGTAZdYKOWzfQz6KcwxANnDHLo3Zg+bLVwu WScsu6ughnwQb6lzHF/r6Rw62UItIuxchQAnG59BathovFst40wgBTROEq1dZKgVl2i+ VgCJBejddTL29OP1oJ/dQ4MzB+lGnNHdj5lx+w6aJUtczZLnAaHawGhNLBZNWAQEQWZW uJby4medWvsfc1VBF4Ua+iFLfzRo4Z5nr5B+tAGnQYHsXewdX8+BKbfByPH7MlCzAfEt kFjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uOJjkhEX; 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 js4-20020a17090797c400b0078db70cc9b8si15491382ejc.606.2022.10.19.06.20.23; Wed, 19 Oct 2022 06:20:49 -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=uOJjkhEX; 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 S231633AbiJSM6X (ORCPT + 99 others); Wed, 19 Oct 2022 08:58:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbiJSM6L (ORCPT ); Wed, 19 Oct 2022 08:58:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD48F2408F; Wed, 19 Oct 2022 05:41:15 -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 sin.source.kernel.org (Postfix) with ESMTPS id 57213CE2167; Wed, 19 Oct 2022 09:15:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D9EEC433D7; Wed, 19 Oct 2022 09:15:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170943; bh=2fdLn/QEe5cJvzhuHn+H7MqMQb9Zx1z0xrlir9w8xYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOJjkhEX59WzL8hd+xffoA+Se9tUJOE5uHto+l8krl/umeOCjamRgHAFbunhR/wQx hQOWWhpJzXZGFK3cRUztp704LwHjcg0e0nQYkXFelMNqc/XPSljR/1KdeadRskIzr+ k4psaQzFUMk0oNl0jntJMFZIr9yZfDLNIV52uqb8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Guo , Sasha Levin Subject: [PATCH 6.0 818/862] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Wed, 19 Oct 2022 10:35:05 +0200 Message-Id: <20221019083326.051998588@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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.4 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 daada4b66a92..6704a62a1665 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