Commit d6ba7348 authored by Carlos Llamas's avatar Carlos Llamas Committed by Greg Kroah-Hartman
Browse files

rust_binderfs: fix ida_alloc_max() upper bound



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: eafedbc7 ("rust_binder: add Rust Binder driver")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202512181203.IOv6IChH-lkp@intel.com/


Signed-off-by: default avatarCarlos Llamas <cmllamas@google.com>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260127235545.2307876-1-cmllamas@google.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1769f90e
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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;
@@ -405,8 +405,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) {