* [PATCH] rust_binderfs: fix minor number leak on binder-control creation failure
@ 2026-11-02 14:45 Adhyansh Verma
2026-11-09 19:45 ` Carlos Llamas
0 siblings, 1 reply; 2+ messages in thread
From: Adhyansh Verma @ 2026-11-02 14:45 UTC (permalink / raw)
To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
Christian Brauner, Carlos Llamas, Alice Ryhl
Cc: linux-kernel, Adhyansh Verma
In binderfs_binder_ctl_create(), a minor number is reserved using
ida_alloc_max(). If d_alloc_name() subsequently fails (e.g. under memory
pressure), the function jumps to the error path.
However, the cleanup path only calls kfree(device) and iput(inode).
Because inode->i_private has not yet been set to device, the eviction
handler binderfs_evict_inode() returns early without freeing the minor
number. Consequently, the reserved minor number is permanently leaked
from the global binderfs_minors IDA.
Fix this by introducing proper error unwind labels so that the allocated
minor number is released via ida_free() under binderfs_minors_mutex if
dentry allocation fails.
Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
Signed-off-by: Adhyansh Verma <adhyanshverma2010@gmail.com>
---
drivers/android/binder/rust_binderfs.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/android/binder/rust_binderfs.c b/drivers/android/binder/rust_binderfs.c
index 5f020226720d..3f7ff0fdbdb9 100644
--- a/drivers/android/binder/rust_binderfs.c
+++ b/drivers/android/binder/rust_binderfs.c
@@ -400,7 +400,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
ret = -ENOMEM;
inode = new_inode(sb);
if (!inode)
- goto out;
+ goto out_device;
/* Reserve a new minor number for the new device. */
mutex_lock(&binderfs_minors_mutex);
@@ -411,7 +411,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
mutex_unlock(&binderfs_minors_mutex);
if (minor < 0) {
ret = minor;
- goto out;
+ goto out_inode;
}
inode->i_ino = SECOND_INODE;
@@ -427,7 +427,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
dentry = d_alloc_name(root, "binder-control");
if (!dentry)
- goto out;
+ goto out_minor;
inode->i_private = device;
info->control_dentry = dentry;
@@ -436,9 +436,14 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
return 0;
-out:
- kfree(device);
+out_minor:
+ mutex_lock(&binderfs_minors_mutex);
+ ida_free(&binderfs_minors, minor);
+ mutex_unlock(&binderfs_minors_mutex);
+out_inode:
iput(inode);
+out_device:
+ kfree(device);
return ret;
}
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] rust_binderfs: fix minor number leak on binder-control creation failure
2026-11-02 14:45 [PATCH] rust_binderfs: fix minor number leak on binder-control creation failure Adhyansh Verma
@ 2026-11-09 19:45 ` Carlos Llamas
0 siblings, 0 replies; 2+ messages in thread
From: Carlos Llamas @ 2026-11-09 19:45 UTC (permalink / raw)
To: Adhyansh Verma
Cc: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
Christian Brauner, Alice Ryhl, linux-kernel
On Mon, Nov 02, 2026 at 08:15:32PM +0530, Adhyansh Verma wrote:
> In binderfs_binder_ctl_create(), a minor number is reserved using
> ida_alloc_max(). If d_alloc_name() subsequently fails (e.g. under memory
> pressure), the function jumps to the error path.
>
> However, the cleanup path only calls kfree(device) and iput(inode).
> Because inode->i_private has not yet been set to device, the eviction
> handler binderfs_evict_inode() returns early without freeing the minor
> number. Consequently, the reserved minor number is permanently leaked
> from the global binderfs_minors IDA.
>
> Fix this by introducing proper error unwind labels so that the allocated
> minor number is released via ida_free() under binderfs_minors_mutex if
> dentry allocation fails.
>
> Fixes: eafedbc7c050 ("rust_binder: add Rust Binder driver")
> Signed-off-by: Adhyansh Verma <adhyanshverma2010@gmail.com>
> ---
> drivers/android/binder/rust_binderfs.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/android/binder/rust_binderfs.c b/drivers/android/binder/rust_binderfs.c
> index 5f020226720d..3f7ff0fdbdb9 100644
> --- a/drivers/android/binder/rust_binderfs.c
> +++ b/drivers/android/binder/rust_binderfs.c
> @@ -400,7 +400,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
> ret = -ENOMEM;
> inode = new_inode(sb);
> if (!inode)
> - goto out;
> + goto out_device;
>
> /* Reserve a new minor number for the new device. */
> mutex_lock(&binderfs_minors_mutex);
> @@ -411,7 +411,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
> mutex_unlock(&binderfs_minors_mutex);
> if (minor < 0) {
> ret = minor;
> - goto out;
> + goto out_inode;
> }
>
> inode->i_ino = SECOND_INODE;
> @@ -427,7 +427,7 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>
> dentry = d_alloc_name(root, "binder-control");
> if (!dentry)
> - goto out;
> + goto out_minor;
>
> inode->i_private = device;
> info->control_dentry = dentry;
> @@ -436,9 +436,14 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
>
> return 0;
>
> -out:
> - kfree(device);
> +out_minor:
> + mutex_lock(&binderfs_minors_mutex);
> + ida_free(&binderfs_minors, minor);
> + mutex_unlock(&binderfs_minors_mutex);
> +out_inode:
> iput(inode);
> +out_device:
> + kfree(device);
>
> return ret;
> }
> --
> 2.56.0
>
Is this patch any different from this one? :
https://lore.kernel.org/all/tencent_8D7B76C623DA3A29EE73D38217ACB08AFB09@qq.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-09 19:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 14:45 [PATCH] rust_binderfs: fix minor number leak on binder-control creation failure Adhyansh Verma
2026-11-09 19:45 ` Carlos Llamas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®