Skip to content

Commit da8ddba

Browse files
braunergregkh
authored andcommitted
binderfs: respect limit on binder control creation
We currently adhere to the reserved devices limit when creating new binderfs devices in binderfs instances not located in the inital ipc namespace. But it is still possible to rob the host instances of their 4 reserved devices by creating the maximum allowed number of devices in a single binderfs instance located in a non-initial ipc namespace and then mounting 4 separate binderfs instances in non-initial ipc namespaces. That happens because the limit is currently not respected for the creation of the initial binder-control device node. Block this nonsense by performing the same check in binderfs_binder_ctl_create() that we perform in binderfs_binder_device_create(). Fixes: 36bdf3c ("binderfs: reserve devices for initial mount") Signed-off-by: Christian Brauner <christian@brauner.io> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 793c823 commit da8ddba

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎drivers/android/binderfs.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
395395
struct inode *inode = NULL;
396396
struct dentry *root = sb->s_root;
397397
struct binderfs_info *info = sb->s_fs_info;
398+
#if defined(CONFIG_IPC_NS)
399+
bool use_reserve = (info->ipc_ns == &init_ipc_ns);
400+
#else
401+
bool use_reserve = true;
402+
#endif
398403

399404
device = kzalloc(sizeof(*device), GFP_KERNEL);
400405
if (!device)
@@ -413,7 +418,10 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
413418

414419
/* Reserve a new minor number for the new device. */
415420
mutex_lock(&binderfs_minors_mutex);
416-
minor = ida_alloc_max(&binderfs_minors, BINDERFS_MAX_MINOR, GFP_KERNEL);
421+
minor = ida_alloc_max(&binderfs_minors,
422+
use_reserve ? BINDERFS_MAX_MINOR :
423+
BINDERFS_MAX_MINOR_CAPPED,
424+
GFP_KERNEL);
417425
mutex_unlock(&binderfs_minors_mutex);
418426
if (minor < 0) {
419427
ret = minor;

0 commit comments

Comments
 (0)