]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
binderfs: fix ida_alloc_max() upper bound
authorCarlos Llamas <cmllamas@google.com>
Tue, 27 Jan 2026 23:55:11 +0000 (23:55 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Feb 2026 11:59:07 +0000 (12:59 +0100)
The 'max' argument of ida_alloc_max() takes the maximum valid ID and not
the "count". Using an ID of BINDERFS_MAX_MINOR (1 << 20) for dev->minor
would exceed the limits of minor numbers (20-bits). Fix this off-by-one
error by subtracting 1 from the 'max'.

Cc: stable@vger.kernel.org
Fixes: 3ad20fe393b3 ("binder: implement binderfs")
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Link: https://patch.msgid.link/20260127235545.2307876-2-cmllamas@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binderfs.c

index b46bcb91072de2a323b1b3f7dba600c0d60a217a..9f8a18c88d66ef25dd8a8089493a1b563006a3d9 100644 (file)
@@ -132,8 +132,8 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
        mutex_lock(&binderfs_minors_mutex);
        if (++info->device_count <= info->mount_opts.max)
                minor = ida_alloc_max(&binderfs_minors,
-                                     use_reserve ? BINDERFS_MAX_MINOR :
-                                                   BINDERFS_MAX_MINOR_CAPPED,
+                                     use_reserve ? BINDERFS_MAX_MINOR - 1 :
+                                                   BINDERFS_MAX_MINOR_CAPPED - 1,
                                      GFP_KERNEL);
        else
                minor = -ENOSPC;
@@ -408,8 +408,8 @@ static int binderfs_binder_ctl_create(struct super_block *sb)
        /* Reserve a new minor number for the new device. */
        mutex_lock(&binderfs_minors_mutex);
        minor = ida_alloc_max(&binderfs_minors,
-                             use_reserve ? BINDERFS_MAX_MINOR :
-                                           BINDERFS_MAX_MINOR_CAPPED,
+                             use_reserve ? BINDERFS_MAX_MINOR - 1 :
+                                           BINDERFS_MAX_MINOR_CAPPED - 1,
                              GFP_KERNEL);
        mutex_unlock(&binderfs_minors_mutex);
        if (minor < 0) {