From nobody Mon Apr 13 12:02:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3717FC3F6B0 for ; Fri, 12 Aug 2022 13:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238578AbiHLNXd (ORCPT ); Fri, 12 Aug 2022 09:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbiHLNX3 (ORCPT ); Fri, 12 Aug 2022 09:23:29 -0400 Received: from hust.edu.cn (mail.hust.edu.cn [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0165390C68 for ; Fri, 12 Aug 2022 06:23:26 -0700 (PDT) Received: from localhost.localdomain ([222.20.126.44]) (user=dzm91@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 27CDLQdu023627-27CDLQdx023627 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 12 Aug 2022 21:21:32 +0800 From: Dongliang Mu To: Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Kees Cook Cc: Dongliang Mu , syzkaller , linux-kernel@vger.kernel.org Subject: [PATCH] drivers: binderfs: fix memory leak in binderfs_fill_super Date: Fri, 12 Aug 2022 21:21:24 +0800 Message-Id: <20220812132124.2053673-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: dzm91@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dongliang Mu In binderfs_fill_super, if s_root is not successfully initialized by d_make_root, the previous allocated s_sb_info will not be freed since generic_shutdown_super first checks if sb->s_root and then does put_super operation. The put_super operation calls binderfs_put_super to deallocate s_sb_info and put ipc_ns. This will lead to memory leak in binderfs_fill_super. Fix this by invoking binderfs_put_super at error sites before s_root is successfully initialized. Fixes: 095cf502b31e ("binderfs: port to new mount api") Reported-by: syzkaller Signed-off-by: Dongliang Mu Reviewed-by: Christian Brauner (Microsoft) --- drivers/android/binderfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 588d753a7a19..20f5bc77495f 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -710,8 +710,10 @@ static int binderfs_fill_super(struct super_block *sb,= struct fs_context *fc) info->mount_opts.stats_mode =3D ctx->stats_mode; =20 inode =3D new_inode(sb); - if (!inode) + if (!inode) { + binderfs_put_super(sb); return -ENOMEM; + } =20 inode->i_ino =3D FIRST_INODE; inode->i_fop =3D &simple_dir_operations; @@ -721,8 +723,10 @@ static int binderfs_fill_super(struct super_block *sb,= struct fs_context *fc) set_nlink(inode, 2); =20 sb->s_root =3D d_make_root(inode); - if (!sb->s_root) + if (!sb->s_root) { + binderfs_put_super(sb); return -ENOMEM; + } =20 ret =3D binderfs_binder_ctl_create(sb); if (ret) --=20 2.25.1