Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3137920pxj; Mon, 14 Jun 2021 15:35:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCXqXneNfWtyu7+u1WJro5dh8y6gS51b+D41Q72NoNeWutjqdjug2V83eJEVqkUaGVh716 X-Received: by 2002:aa7:ce86:: with SMTP id y6mr19619684edv.309.1623710151690; Mon, 14 Jun 2021 15:35:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623710151; cv=none; d=google.com; s=arc-20160816; b=tUH9h2F4pUlMwYQU19w04Ukhsadh9XmhsGSwf0mWuCYKfuoFTpV7C/8Pz3ukAAOb34 S5CCb2NhXLNdfrLsnBUyA9arpLWYc/SvKjDlxRoOHzLCEZZy10QrP8gySE9xXkvzW5Qj FEG39yTpiqw2RrNKTCix2D844s6hyhfWy10R31Xj+yeznubaU7nNwPJF2a68GCnFWlJG ppojvWpBr9bpGYic4cN2W7lgHy2ewgAGctu7gfmPFyHEy7iIhMsJQqYcTsUfPWLG9nF+ usTm874rtINg4S3hSxyfEnCVrQGF6P+tKz4KxOJ1IoPEO6FDLrRoGCvhl0vOEQnSu0nN AijA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=TtskdlC/k6y5Vyid0xhjgxmw7Heu/eFwKKkdtwh+B8Y=; b=rYFPxRw7vOFuSZfoNp6hpr3IyeWARH7cl2qslY4/HSJRkZy5SvCO6S48qXeVtltN6t xIBeOaTU8f6qzAznKGkAyRnzbET+AWYH7PoBhLEbXEIrvHiaF23O6aubqNeraqqrjCiF qmYpJhNlW/s0qlvPyKlAscqLt7nYnY3dg4cO2QbrA+BuJUpty39KDB9PiHCvj8a50f/s cQrVe8tTBornmREcpEFasVXf3M2pNnI4XpJt5zFdh692i1qJn+7QhM7z3gNSdLEqOOQz YJEKpldhNyKiWpnfuOEfXsvvKwD8XMiTuS/7xc5xB7yHkdT9eHtNG3p+BqZKP7DX6OYY TnnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=NVcwLnps; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si7597453ejg.385.2021.06.14.15.35.29; Mon, 14 Jun 2021 15:35:51 -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=@linux.microsoft.com header.s=default header.b=NVcwLnps; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231621AbhFNWfh (ORCPT + 99 others); Mon, 14 Jun 2021 18:35:37 -0400 Received: from linux.microsoft.com ([13.77.154.182]:56042 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbhFNWfg (ORCPT ); Mon, 14 Jun 2021 18:35:36 -0400 Received: from sequoia.work.tihix.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 08DFD20B83C2; Mon, 14 Jun 2021 15:33:31 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 08DFD20B83C2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1623710013; bh=TtskdlC/k6y5Vyid0xhjgxmw7Heu/eFwKKkdtwh+B8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NVcwLnpsuKMJrJB6G2KuR2KKcVT64dD6KObJcLSWj/py40GSGqmDklFWp4Uz0axWt b4MfCAybIk/9dGQgz0o3iTCcFEAZvb7fmR16AfazlRYqDZgXx1iRHO2pQtmXZ1DnAM l9YoSvCKVyXC9jg5A5nM6I0v+QuupuxNMP8b3qh4= From: Tyler Hicks To: Jens Wiklander , Allen Pais , Sumit Garg , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Vikas Gupta Cc: Thirupathaiah Annapureddy , Pavel Tatashin , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , op-tee@lists.trustedfirmware.org, linux-integrity@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/8] optee: Fix memory leak when failing to register shm pages Date: Mon, 14 Jun 2021 17:33:10 -0500 Message-Id: <20210614223317.999867-2-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210614223317.999867-1-tyhicks@linux.microsoft.com> References: <20210614223317.999867-1-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/tee/optee/shm_pool.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c index d767eebf30bd..da06ce9b9313 100644 --- 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_pool_mgr *poolm, 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_pool_mgr *poolm, 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; } -- 2.25.1