From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E87339446 for ; Sun, 13 Aug 2023 21:48:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 443BDC433C8; Sun, 13 Aug 2023 21:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1691963294; bh=eJIGWN3tjneuP36zsd0VF25VoMxas/P2/Gg0YEBUJnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=II/NEdPhA40+CwXkg8XfOx3vZuOWOYQzmc1xdHUBmWFoj/EJZORHCV11R+EUEmm6b ZCs/SjhQLesqB2tq4BAQO/tvjL2HmVm7LDVsmFg6N1g0C9fj7P1AtupG9bWhiCbiMJ PK08Yu/UdzwZQwfgFOeKjCIVA1jfClHAjmjnW8tg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qi Zheng , Carlos Llamas , stable Subject: [PATCH 5.4 09/39] binder: fix memory leak in binder_init() Date: Sun, 13 Aug 2023 23:20:00 +0200 Message-ID: <20230813211705.151097946@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230813211704.796906808@linuxfoundation.org> References: <20230813211704.796906808@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Qi Zheng commit adb9743d6a08778b78d62d16b4230346d3508986 upstream. In binder_init(), the destruction of binder_alloc_shrinker_init() is not performed in the wrong path, which will cause memory leaks. So this commit introduces binder_alloc_shrinker_exit() and calls it in the wrong path to fix that. Signed-off-by: Qi Zheng Acked-by: Carlos Llamas Fixes: f2517eb76f1f ("android: binder: Add global lru shrinker to binder") Cc: stable Link: https://lore.kernel.org/r/20230625154937.64316-1-qi.zheng@linux.dev Signed-off-by: Greg Kroah-Hartman --- drivers/android/binder.c | 1 + drivers/android/binder_alloc.c | 6 ++++++ drivers/android/binder_alloc.h | 1 + 3 files changed, 8 insertions(+) --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -6555,6 +6555,7 @@ err_init_binder_device_failed: err_alloc_device_names_failed: debugfs_remove_recursive(binder_debugfs_dir_entry_root); + binder_alloc_shrinker_exit(); return ret; } --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1037,6 +1037,12 @@ int binder_alloc_shrinker_init(void) return ret; } +void binder_alloc_shrinker_exit(void) +{ + unregister_shrinker(&binder_shrinker); + list_lru_destroy(&binder_alloc_lru); +} + /** * check_buffer() - verify that buffer/offset is safe to access * @alloc: binder_alloc for this proc --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -122,6 +122,7 @@ extern struct binder_buffer *binder_allo int is_async); extern void binder_alloc_init(struct binder_alloc *alloc); extern int binder_alloc_shrinker_init(void); +extern void binder_alloc_shrinker_exit(void); extern void binder_alloc_vma_close(struct binder_alloc *alloc); extern struct binder_buffer * binder_alloc_prepare_to_free(struct binder_alloc *alloc,