All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] binderfs: Fix the maximum minor value in binderfs_binder_device_create() and binderfs_binder_ctl_create()
@ 2022-03-27 11:18 Christophe JAILLET
  2022-03-29 11:20 ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2022-03-27 11:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, Joel Fernandes, Christian Brauner,
	Hridya Valsaraju, Suren Baghdasaryan
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Todd Kjos

ida_alloc_max(..., max, ...) returns values from 0 to max, inclusive.

So, BINDERFS_MAX_MINOR is a valid value for 'minor'.

BINDERFS_MAX_MINOR is '1U << MINORBITS' and we have:
	#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))

So, When this value is used in MKDEV() and it will overflow.

Fixes: 3ad20fe393b3 ("binder: implement binderfs")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This patch is completely speculative.

The 'BINDERFS_MAX_MINOR_CAPPED - 1' is here only for symmetry with the
BINDERFS_MAX_MINOR case. I'm not sure at all that is is needed and, more
importantly, that it is correct.
---
 drivers/android/binderfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c
index e3605cdd4335..47df1f381150 100644
--- a/drivers/android/binderfs.c
+++ b/drivers/android/binderfs.c
@@ -130,8 +130,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;
@@ -433,8 +433,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) {
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] binderfs: Fix the maximum minor value in binderfs_binder_device_create() and binderfs_binder_ctl_create()
  2022-03-27 11:18 [PATCH] binderfs: Fix the maximum minor value in binderfs_binder_device_create() and binderfs_binder_ctl_create() Christophe JAILLET
@ 2022-03-29 11:20 ` Christian Brauner
  2022-03-31 20:35   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2022-03-29 11:20 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, Joel Fernandes, Hridya Valsaraju,
	Suren Baghdasaryan, linux-kernel, kernel-janitors, Todd Kjos

On Sun, Mar 27, 2022 at 01:18:17PM +0200, Christophe JAILLET wrote:
> ida_alloc_max(..., max, ...) returns values from 0 to max, inclusive.
> 
> So, BINDERFS_MAX_MINOR is a valid value for 'minor'.
> 
> BINDERFS_MAX_MINOR is '1U << MINORBITS' and we have:
> 	#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
> 
> So, When this value is used in MKDEV() and it will overflow.
> 
> Fixes: 3ad20fe393b3 ("binder: implement binderfs")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This patch is completely speculative.
> 
> The 'BINDERFS_MAX_MINOR_CAPPED - 1' is here only for symmetry with the
> BINDERFS_MAX_MINOR case. I'm not sure at all that is is needed and, more
> importantly, that it is correct.

Hm, since we're "removing" one alloctable device for the initial ipc
namespace, I think we need the -1 for the capped value.

Though I wonder if the simpler fix wouldn't just be to:

#define BINDERFS_MAX_MINOR MINORMASK

since include/linux/kdev_t.h has:

#define MINORBITS	20
#define MINORMASK	((1U << MINORBITS) - 1)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] binderfs: Fix the maximum minor value in binderfs_binder_device_create() and binderfs_binder_ctl_create()
  2022-03-29 11:20 ` Christian Brauner
@ 2022-03-31 20:35   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-03-31 20:35 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Greg Kroah-Hartman, Arve Hjønnevåg, Todd Kjos,
	Martijn Coenen, Joel Fernandes, Hridya Valsaraju,
	Suren Baghdasaryan, linux-kernel, kernel-janitors, Todd Kjos

Le 29/03/2022 à 13:20, Christian Brauner a écrit :
> On Sun, Mar 27, 2022 at 01:18:17PM +0200, Christophe JAILLET wrote:
>> ida_alloc_max(..., max, ...) returns values from 0 to max, inclusive.
>>
>> So, BINDERFS_MAX_MINOR is a valid value for 'minor'.
>>
>> BINDERFS_MAX_MINOR is '1U << MINORBITS' and we have:
>> 	#define MKDEV(ma,mi)	(((ma) << MINORBITS) | (mi))
>>
>> So, When this value is used in MKDEV() and it will overflow.
>>
>> Fixes: 3ad20fe393b3 ("binder: implement binderfs")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> This patch is completely speculative.
>>
>> The 'BINDERFS_MAX_MINOR_CAPPED - 1' is here only for symmetry with the
>> BINDERFS_MAX_MINOR case. I'm not sure at all that is is needed and, more
>> importantly, that it is correct.
> 
> Hm, since we're "removing" one alloctable device for the initial ipc
> namespace, I think we need the -1 for the capped value.
> 
> Though I wonder if the simpler fix wouldn't just be to:
> 
> #define BINDERFS_MAX_MINOR MINORMASK
> 
> since include/linux/kdev_t.h has:
> 
> #define MINORBITS	20
> #define MINORMASK	((1U << MINORBITS) - 1)
> 

Hi,
I mostly agree with you, but I don't have a strong opinion on the other 
uses of BINDERFS_MAX_MINOR.

The ones related to 'max' values looks good to me, but I don't know the 
implication for the one used in binderfs_make_inode() and in 
init_binderfs().

I won't be able to help further here.

CJ

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-31 20:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27 11:18 [PATCH] binderfs: Fix the maximum minor value in binderfs_binder_device_create() and binderfs_binder_ctl_create() Christophe JAILLET
2022-03-29 11:20 ` Christian Brauner
2022-03-31 20:35   ` Christophe JAILLET

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.