Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3760751pxt; Tue, 10 Aug 2021 10:41:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKIdYab+imXUlF2kLLYoxu5x2B7Z+YObKHFpNKtqlu5Kh7tgPlf4FmtGs5rEa5TWMCexiI X-Received: by 2002:a5d:858d:: with SMTP id f13mr1102799ioj.197.1628617288064; Tue, 10 Aug 2021 10:41:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617288; cv=none; d=google.com; s=arc-20160816; b=vNlJt51RsulnhbW0ZWjB/8SYf0rWxuOuP+0krDc2pSY8qFtbuMPTRxWiAWcZ+Roax0 FWBLy5JxkUM7ukO+XXqUSwZNNwtLc9Yz9rYEM9A5D5Bdj44Ax8ji2XXfVUtyoPY5j9V4 9yV6Y7nU+rbvUu0kh5/VxE/CKM9tTnAb0WjAJxB/G4Rbc6mj3UlQWIDUUpg/48GHw6oZ mb5Wj8cAswPZCrQB27OS75La51OQNgp16TGYtim6oe94DKeh+jn9nxK8+ClfgNnDJQq2 RvQhIOAkBvS2WrafMW+A7OEoSl4njttJzNFE3H5Kx8HMr+6T/9EgDtHlqpSLmOfCnOYX zGUQ== 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=SUlzY3jW9S0Zeby6m2Pe5QjDvLWfou/vnn/N4LZSaMfgGF7a56SMym4VLjLz4UQPPS 6r6vZOhOMQ4VAiHeWfhDpi5PheZGIrF2R+C1/q9dt2O09BHEJviyqrXhiSoD5q1ysqRL iFtVP1Gy2G1MeyKZ9PTHqKXtMQfwtNYOZTsdx3m9zvyfIOA/RP3rICCAExyZ4T5nsr53 PfxUGi7WuvOLeslrjI6q+KpGBxGwsIkB0/sZnaIizbXHAiB9ho/ckVvV/UArzXtUZcxx zxBcjzkD9+hag5gmn6oVlKR+JCbW+algYMZSKbDQNj6ZDMRhr+zIsVeygbusV+v0oZBd ocGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c7C7OXtS; 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 f13si23162673ils.29.2021.08.10.10.41.16; Tue, 10 Aug 2021 10:41:28 -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=c7C7OXtS; 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 S234397AbhHJRk0 (ORCPT + 99 others); Tue, 10 Aug 2021 13:40:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:57640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234990AbhHJRiw (ORCPT ); Tue, 10 Aug 2021 13:38:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F2865610CC; Tue, 10 Aug 2021 17:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617002; bh=kMfrfxBLEc9gl+fcwjaNXU9MD349NhzmfzVKwN6TlnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c7C7OXtSnaZq6W5JnfACEdsZCOdAVvBEsd93eIh4q7H/i+xWLgRBSRk3AsudEWukb BfPdPeyNFDUtIy1y5Ppcikojx8V74ia+6h3+cfGAFYOhI+Xv66BNVvg9OUJm9VcL2n NIL6iruewI6W8C4ps6HJQ1fbDWzAvz3BYnr1COIs= 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.4 54/85] optee: Fix memory leak when failing to register shm pages Date: Tue, 10 Aug 2021 19:30:27 +0200 Message-Id: <20210810172950.066383606@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172948.192298392@linuxfoundation.org> References: <20210810172948.192298392@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; }