Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp865645rwi; Wed, 19 Oct 2022 04:04:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7s9oc2yY2s/3gxnsT30WJs/Ag3kxiacAV3rBfi4uS5r5QQFVB1k6+Ob1lh2jAZMQ8xsK+p X-Received: by 2002:a05:6402:5024:b0:440:e4ad:f7b6 with SMTP id p36-20020a056402502400b00440e4adf7b6mr6960109eda.358.1666177490387; Wed, 19 Oct 2022 04:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177490; cv=none; d=google.com; s=arc-20160816; b=1DXDCTwnyR50/lz4Z6uEybQ4I1dWscdq9vIGP1xbLtgkCER0eGFu0dd6D84rIwcTMY GtkT7TtW5CT46b7Eu3RwGU09hIjBgjEaQnj7TTAwD8l1kaO4p0etHStmGV0Wr1l7jbaf 0osSFucL8AI1oLuSbi/1Jkh3a4+C4WcSk1CCdFSV9g/c/CT9MiiANS1CqSnRbZZOig7+ soVzvJ1e1TJq3xNq9Zx4uNHhrxYQlRDctHSqHZMaLWd0LAQOiX3+du9L5wh+YdDS3Hba vLdx3Ayd6GesDiYGT5OGDe47bdKjvDUbqABiWswY6/u3AYIldLNVZkx5II3IxugXjXIB LI1A== 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=uyr7uFQITT7cUiRiakbXxfBQAjTfnvRmynMmmSOTFiU=; b=Fv57MBrvfAu1jBK92WLovo3UvBNT4vPxijznFTC9OBYXM2HsUZ5R4/0aM0DzCLc4rF ScsZvGwF2YcLt0NDGyeC/hlP1AS50P4yumPw4f+0QCZ01DjdW1HRwHaXdv6L4eIbM2l7 WHdwuHUtrqaDfLY4JWjCr+kwQGxce/cc4dx2Qs/Yl4rrsNvD5Lo+tcXPkwKAR7oUbFMn n4MKYXYEZq5YJ3vlfMsTrIEm3SVM0oa8SXagRu0+HN1hxWj6qQRhMlWIYO9gVc72GOm6 wxuYABq8TF2nIXRm2jPVQSund5/NurDL5VV3ShXkET+adFGigwC0VJ7QBV0JtK0Iux7r vOQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B3E8gg24; 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 j9-20020a05640211c900b0045db850a506si6259675edw.46.2022.10.19.04.04.06; Wed, 19 Oct 2022 04:04:50 -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=B3E8gg24; 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 S234212AbiJSKsU (ORCPT + 99 others); Wed, 19 Oct 2022 06:48:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233196AbiJSKqY (ORCPT ); Wed, 19 Oct 2022 06:46:24 -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 BB8DE159D50; Wed, 19 Oct 2022 03:21:29 -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 ECC83B824E4; Wed, 19 Oct 2022 09:15:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DB47C433C1; Wed, 19 Oct 2022 09:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170913; bh=QmYPBt2tuHklhPv5OYIPoGItdJBIj0Kc3kuoPwcl3Q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3E8gg24wI/3rhy4VjLyNLJCPhBLI/7iptm3Hh9bxpbGYqjwpMzJ54UvhrAdzE9Oh AzQf5nEwT6zya9V6xUhpqKcrHTT73Gkd/tZUsFOHrKQxdSiVz8hRYP4i7Byv3v6nlG LJvxzOnuTvpq00fojvh7iD5aoCqv5z5N0H/b7MVk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , Mathias Nyman , Sasha Levin Subject: [PATCH 6.0 817/862] usb: host: xhci: Fix potential memory leak in xhci_alloc_stream_info() Date: Wed, 19 Oct 2022 10:35:04 +0200 Message-Id: <20221019083326.011394372@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: Jianglei Nie [ Upstream commit 7e271f42a5cc3768cd2622b929ba66859ae21f97 ] xhci_alloc_stream_info() allocates stream context array for stream_info ->stream_ctx_array with xhci_alloc_stream_ctx(). When some error occurs, stream_info->stream_ctx_array is not released, which will lead to a memory leak. We can fix it by releasing the stream_info->stream_ctx_array with xhci_free_stream_ctx() on the error path to avoid the potential memory leak. Signed-off-by: Jianglei Nie Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220921123450.671459-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/host/xhci-mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 8c19e151a945..9e56aa28efcd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -641,7 +641,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, num_stream_ctxs, &stream_info->ctx_array_dma, mem_flags); if (!stream_info->stream_ctx_array) - goto cleanup_ctx; + goto cleanup_ring_array; memset(stream_info->stream_ctx_array, 0, sizeof(struct xhci_stream_ctx)*num_stream_ctxs); @@ -702,6 +702,11 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, } xhci_free_command(xhci, stream_info->free_streams_command); cleanup_ctx: + xhci_free_stream_ctx(xhci, + stream_info->num_stream_ctxs, + stream_info->stream_ctx_array, + stream_info->ctx_array_dma); +cleanup_ring_array: kfree(stream_info->stream_rings); cleanup_info: kfree(stream_info); -- 2.35.1