Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp41056pxj; Thu, 10 Jun 2021 14:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYRXdvAdkKwzkGFFzrQr5hhV00kA+SHKJyRtJYHGxNaJ8nf8LoNoefLHCmkadZlrvDAyhv X-Received: by 2002:a05:6402:40c3:: with SMTP id z3mr390695edb.187.1623359531928; Thu, 10 Jun 2021 14:12:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623359531; cv=none; d=google.com; s=arc-20160816; b=MUcPH/BLNcGGQQiQNhts2IOTmYYzM0XRx0E1c4ymS8cywKTbfOOXNKOuDXDqEYBCTU rr4QK5WVN6nOvfXd8cQapNQ0apM6udYKIU9hI++azkCWMFfPc99QhIJ+u2KUn19LewTi lg0AAdL3j6+xRucTRdk4v0yOyCbW585CEzHkwr41ZWwUuS2u0zmvbXe5GGomr9cDatCI cvDR+N+QRnLXv3gZGyNYsMzVm+GLPFN2rLBjsBym3+AwWEKLl51aqM/bS5Gzl9yeO+HH YQ6Srajqe84dbArsaTou4vm79qWfUx0ZLMLy0BXP98xT2B/m4H9qsALuZuEL9Ku0I/gT m8AA== 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=uVgZoRO1aKnahUqyjDPzyphebgzUacysdZ2smy7vuKE=; b=qxlrB2Tp5da3fOwVK3m8ANWH4m2ajBrrxtNrkt6mfjdv1Fa/sF32zmKNJZpwf9n2Ta syIGYWMQ+kVzNTSfa8lp+U9wRTygqdyXBBIb9S/DrvD1dRq8b01VlSr1xvMFZ7xlcZpY oIoo7Co/72l80LVyg+NNCMJBOnGFCgWUsXOUSQGKXX30q2ffUcnSIP/MLcUgdkIs9RUZ J1k/mEzlpLOxgiW4wk/05+20bYVbyCk/24nzQw27U+4TBNqsvtHQpPDwiFFlYNFPooV3 cemD6EQWe1hoV0VuGJD0K7WbtKk70VIRogj7/4jubyrFEnJTVYy8mudgEYK/aaqfVuPT nBkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=fjX04TsC; 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 kl9si3225417ejc.603.2021.06.10.14.11.48; Thu, 10 Jun 2021 14:12:11 -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=fjX04TsC; 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 S231151AbhFJVLr (ORCPT + 99 others); Thu, 10 Jun 2021 17:11:47 -0400 Received: from linux.microsoft.com ([13.77.154.182]:60418 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230468AbhFJVLl (ORCPT ); Thu, 10 Jun 2021 17:11:41 -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 A6E9120B7178; Thu, 10 Jun 2021 14:09:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A6E9120B7178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1623359384; bh=uVgZoRO1aKnahUqyjDPzyphebgzUacysdZ2smy7vuKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fjX04TsCT6Z9+aOGs0t4/zJ6XPuhW1muqh2cI/PW8VrAvXURzeTSoIjMpnqhrzZOb E/K1XPRxBdhyQ+MDJE8KarvEvA8PQXdzCF8br/WB8fC7tWqbxBgowaSehYqchn4aA2 UPoZgcynC2lD2eVK3tfgc34Xt50jzEitiV1mfx0k= 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 v4 1/8] optee: Fix memory leak when failing to register shm pages Date: Thu, 10 Jun 2021 16:09:06 -0500 Message-Id: <20210610210913.536081-2-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210610210913.536081-1-tyhicks@linux.microsoft.com> References: <20210610210913.536081-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") Signed-off-by: Tyler Hicks --- 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