Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3767582pxt; Tue, 10 Aug 2021 10:51:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3Q1H8A64PZX7Ji1jk0uOIOk9J28R4pt0OOtmfa0WeMS7zpqEwCMxdnrK5VSXuKkb/+3L/ X-Received: by 2002:a05:6402:220d:: with SMTP id cq13mr6440530edb.318.1628617884859; Tue, 10 Aug 2021 10:51:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617884; cv=none; d=google.com; s=arc-20160816; b=HE0XxRF8z+x2MRKvVpxT1aEdpoQiLzUlHtEgs//UnLVto4AiW7Hh8NZGv8X+uyr5Cd BvYwv3qpfdAYOB0Nin+j6uXV1sLjk0D9V4RHZBQjCezb99HcSLih+sELIyBCqkM7BHzD t7ODlTXivenjMQF6i84jBKwHXctajiPibunKSD9/1c2soL0ARfEvAjW0H4/uRxypwOqR fj2yN25iE2ppnUESl0O5LY+GFktrYPDHHRWCV19gkacJlyTBe/RmMMV9vx57Ta4oI8lU dmU1vFYg7BfwFj38pUCduR2jVBrAyRkFNz/b6ieD4LDJQduOR/vsrhuHj1YO2gxEpYMa pCAg== 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=Hmvb4PJTJy5ZTaIDMGnf8oZmelqygbxKpXlk7gmaT6k=; b=K4H9PREstPd7grdrJobd0XgqIIqfzLxK85I5bwgooyYUtgDstNa7PzynkhQ+/HuRuM CqlarmE4tvrHQzzhFjXWnfpWNRTMy4WkZ4B6Dml6ePp71Z6+x0mNdAHuPhF6mHdRDGC6 TotKmrOjgzSR6yQ1iwtGtSlWLbtK/shdFe364/dmNVfvaZyD+gjw88RT0jfX2nueXbl2 kaWs4515BPAi8xTDe3WbVry/gNlJV62yEOx0tYrnXrAk9KcIThz/u+nOJXbaBjG5OsCG X7RRXmMAUKp4sXLhQtpopl3xgU1mcgl/QnYknrFeXS5LGGiKidCeQmdYS3ddES8tLOt7 fhzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B58lSdED; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h8si22943574ejj.422.2021.08.10.10.51.01; Tue, 10 Aug 2021 10:51:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B58lSdED; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S235255AbhHJRr5 (ORCPT + 99 others); Tue, 10 Aug 2021 13:47:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236398AbhHJRoq (ORCPT ); Tue, 10 Aug 2021 13:44:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 776EC6113A; Tue, 10 Aug 2021 17:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617184; bh=kMfrfxBLEc9gl+fcwjaNXU9MD349NhzmfzVKwN6TlnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B58lSdEDXBQUYkUp2nSP8C71lL9N8QWGC9Vqg6QOQ1vdFJg5oxfR18lUp5vj4VBrY kaZ4RsPbj/nUyn22nZwYBczd8sYDMh454anSnqszA0GevS6tEKFrgtOGICcPTPG8Gi zmP+IVstJ8e+xe+oEiRYYLm7DRfpQ4SYQ3qK9GUU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tyler Hicks , Jens Wiklander , Sumit Garg Subject: [PATCH 5.10 083/135] optee: Fix memory leak when failing to register shm pages Date: Tue, 10 Aug 2021 19:30:17 +0200 Message-Id: <20210810172958.566373568@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tyler Hicks commit ec185dd3ab257dc2a60953fdf1b6622f524cc5b7 upstream. Free the previously allocated pages when we encounter an error condition while attempting to register the pages with the secure world. Fixes: a249dd200d03 ("tee: optee: Fix dynamic shm pool allocations") Fixes: 5a769f6ff439 ("optee: Fix multi page dynamic shm pool alloc") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks Reviewed-by: Jens Wiklander Reviewed-by: Sumit Garg Signed-off-by: Jens Wiklander Signed-off-by: Greg Kroah-Hartman --- drivers/tee/optee/shm_pool.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/tee/optee/shm_pool.c +++ b/drivers/tee/optee/shm_pool.c @@ -32,8 +32,10 @@ static int pool_op_alloc(struct tee_shm_ struct page **pages; pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL); - if (!pages) - return -ENOMEM; + if (!pages) { + rc = -ENOMEM; + goto err; + } for (i = 0; i < nr_pages; i++) { pages[i] = page; @@ -44,8 +46,14 @@ static int pool_op_alloc(struct tee_shm_ rc = optee_shm_register(shm->ctx, shm, pages, nr_pages, (unsigned long)shm->kaddr); kfree(pages); + if (rc) + goto err; } + return 0; + +err: + __free_pages(page, order); return rc; }