From patchwork Wed Oct 19 08:35:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp250887wrs; Wed, 19 Oct 2022 03:50:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7njVIwa7NIR+zebHGHze8eCJdG7flNlUwRmSFv1rQO9c0bWFPNBgMK+Gj8zlof91VLjND2 X-Received: by 2002:a17:906:ee88:b0:78d:1a9a:b2db with SMTP id wt8-20020a170906ee8800b0078d1a9ab2dbmr6005195ejb.225.1666176617520; Wed, 19 Oct 2022 03:50:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666176617; cv=none; d=google.com; s=arc-20160816; b=RidozJVL/z8A8r4H4CoWXACDhqoiGs7RaafrIjMTFU2pdahkduHRq7S8WKGfNPou45 UGhUdl3GQ8tiLgBzzuxzYN1zm/70DBPuJAnUCKMDd7e6MhGmTXKDVsO00Eme0zzMZPcj sWTjq9tnoF0O5O23C0Lfhkz9SBxehK0QuGqHw2Vh0s3JUnXRF3emjxucHK5BZi+aUsVm qm1gttssaEKtW0v49lVjJG/q8mANekAVpM0uD8bAeDyj6JNs75mt2r5McAnphVwQxsK+ tDRlbfrPpzpxJVs0/jXqD8pgCDbgEbYh/YdMPi0TauW0iqGr2xlEks8LsbSHtKyv7BwE 3mcg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di8-20020a170906730800b00783de095de7si14724826ejc.847.2022.10.19.03.49.52; Wed, 19 Oct 2022 03:50:17 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747112813157015151?= X-GMAIL-MSGID: =?utf-8?q?1747112813157015151?= 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);