Skip to contentSkip to conversation

Add default binderfs devices

PATCH In review Hridya Valsaraju 4 participants 22 messages Aug 8, 2019 – Sep 4, 2019 Android drivers

lore
Share & tools
lore
#0 lore raw

v3 cover Add default binderfs devices

Binderfs was created to help provide private binder devices to containers in their own IPC namespace. Currently, every time a new binderfs instance is mounted, its private binder devices need to be created via IOCTL calls. This patch series eliminates the effort for creating the default binder devices for each binderfs instance by creating them automatically.

Hridya Valsaraju (2):
binder: Add default binder devices through binderfs when configured
binder: Validate the default binderfs device names.

 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 35 ++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 5 deletions(-)
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#1 lore raw

PATCH v3 1/2 binder: Add default binder devices through binderfs when configured

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL. This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

---

Changes in v2:
- Updated commit message as per Greg Kroah-Hartman.
- Removed new module parameter creation as per Greg Kroah-Hartman/Christian Brauner.
- Refactored device name length check into a new patch as per Greg Kroah-Hartman.

Changes in v3:
-Removed unnecessary empty lines as per Dan Carpenter.

 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 23 ++++++++++++++++++++---
 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/android/binder.c +3 -2
index 466b6a7f8ab7..ca6b21a53321 100644
@@ -123,7 +123,7 @@ static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
 	BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
 module_param_named(debug_mask, binder_debug_mask, uint, 0644);
 
-static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
+char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
 module_param_named(devices, binder_devices_param, charp, 0444);
 
 static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
@@ -6279,7 +6279,8 @@ static int __init binder_init(void)
 				    &transaction_log_fops);
 	}
 
-	if (strcmp(binder_devices_param, "") != 0) {
+	if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
+	    strcmp(binder_devices_param, "") != 0) {
 		/*
 		* Copy the module_parameter string, because we don't want to
 		* tokenize it in-place.
drivers/android/binder_internal.h +2 -0
index 045b3e42d98b..fe8c745dc8e0 100644
@@ -37,6 +37,8 @@ struct binder_device {
 
 extern const struct file_operations binder_fops;
 
+extern char *binder_devices_param;
+
 #ifdef CONFIG_ANDROID_BINDERFS
 extern bool is_binderfs_device(const struct inode *inode);
 #else
drivers/android/binderfs.c +20 -3
index e773f45d19d9..aee46dd1be91 100644
@@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
 	req->major = MAJOR(binderfs_dev);
 	req->minor = minor;
 
-	ret = copy_to_user(userp, req, sizeof(*req));
-	if (ret) {
+	if (userp && copy_to_user(userp, req, sizeof(*req))) {
 		ret = -EFAULT;
 		goto err;
 	}
@@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	int ret;
 	struct binderfs_info *info;
 	struct inode *inode = NULL;
+	struct binderfs_device device_info = { 0 };
+	const char *name;
+	size_t len;
 
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
@@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	if (!sb->s_root)
 		return -ENOMEM;
 
-	return binderfs_binder_ctl_create(sb);
+	ret = binderfs_binder_ctl_create(sb);
+	if (ret)
+		return ret;
+
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		strscpy(device_info.name, name, len + 1);
+		ret = binderfs_binder_device_create(inode, NULL, &device_info);
+		if (ret)
+			return ret;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
+
+	return 0;
 }
 
 static struct dentry *binderfs_mount(struct file_system_type *fs_type,
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#2 lore raw

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

Quoted 4 lines · Hridya Valsaraju

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL.

Wasn't that a design goal of binderfs?

Quoted 7 lines

This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

This is going to change how things work today, what is going to break because of this change?

I don't object to this, except for the worry of changing the default behavior.

thanks,

greg k-h

#3 lore raw

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

Quoted 7 lines · Greg Kroah-Hartman
Quoted 4 lines · Hridya Valsaraju

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL.

Wasn't that a design goal of binderfs?

Sure, but if you solely rely binderfs to be used to provide binder devices having them pre-created on each mount makes quite some sense, imho.

Quoted 9 lines
Quoted 8 lines

This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

Quoted 5 lines

This is going to change how things work today, what is going to break because of this change?

I don't object to this, except for the worry of changing the default behavior.

This is something that Hridya and Todd can speak better to given that they suggested this change. :)
From my perspective, binderfs binder devices and the regular binder driver are mostly used mutually exclusive in practice atm so that this change has little chance of breaking anyone.

Now I really need to go back to vacation time - which I suck at apparently. :)

Christian

#4 lore raw

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

Quoted 26 lines · Christian Brauner
Quoted 7 lines · Greg Kroah-Hartman
Quoted 4 lines · Hridya Valsaraju

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL.

Wasn't that a design goal of binderfs?

Sure, but if you solely rely binderfs to be used to provide binder devices having them pre-created on each mount makes quite some sense, imho.

Quoted 12 lines
Quoted 8 lines

This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

This is going to change how things work today, what is going to break because of this change?

Quoted 8 lines
Quoted 2 lines

I don't object to this, except for the worry of changing the default behavior.

This is something that Hridya and Todd can speak better to given that they suggested this change. :)
From my perspective, binderfs binder devices and the regular binder driver are mostly used mutually exclusive in practice atm so that this change has little chance of breaking anyone.

As Christian says, we do not anticipate the change to break any existing use cases since binderfs binder devices and regular binder devices are generally not used simultaneously. Hopefully, there are not a lot of unusual use cases since binderfs itself is relatively new as well :)

Quoted 5 lines

Now I really need to go back to vacation time - which I suck at apparently. :)

Christian

Reviewed-by on v3 1/2
#5 lore raw

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

In reply to Hridya Valsaraju
Quoted 11 lines · Hridya Valsaraju

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL. This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

Quoted 3 lines

thanks,

- Joel

Quoted 103 lines

---

Changes in v2:
- Updated commit message as per Greg Kroah-Hartman.
- Removed new module parameter creation as per Greg Kroah-Hartman/Christian Brauner.
- Refactored device name length check into a new patch as per Greg Kroah-Hartman.

Changes in v3:

(quoted diff) +0 -1
-Removed unnecessary empty lines as per Dan Carpenter.
 
 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 23 ++++++++++++++++++++---
 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/android/binder.c +3 -2
index 466b6a7f8ab7..ca6b21a53321 100644
@@ -123,7 +123,7 @@ static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
 	BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
 module_param_named(debug_mask, binder_debug_mask, uint, 0644);
 
-static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
+char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
 module_param_named(devices, binder_devices_param, charp, 0444);
 
 static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
@@ -6279,7 +6279,8 @@ static int __init binder_init(void)
 				    &transaction_log_fops);
 	}
 
-	if (strcmp(binder_devices_param, "") != 0) {
+	if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
+	    strcmp(binder_devices_param, "") != 0) {
 		/*
 		* Copy the module_parameter string, because we don't want to
 		* tokenize it in-place.
drivers/android/binder_internal.h +2 -0
index 045b3e42d98b..fe8c745dc8e0 100644
@@ -37,6 +37,8 @@ struct binder_device {
 
 extern const struct file_operations binder_fops;
 
+extern char *binder_devices_param;
+
 #ifdef CONFIG_ANDROID_BINDERFS
 extern bool is_binderfs_device(const struct inode *inode);
 #else
drivers/android/binderfs.c +20 -3
index e773f45d19d9..aee46dd1be91 100644
@@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
 	req->major = MAJOR(binderfs_dev);
 	req->minor = minor;
 
-	ret = copy_to_user(userp, req, sizeof(*req));
-	if (ret) {
+	if (userp && copy_to_user(userp, req, sizeof(*req))) {
 		ret = -EFAULT;
 		goto err;
 	}
@@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	int ret;
 	struct binderfs_info *info;
 	struct inode *inode = NULL;
+	struct binderfs_device device_info = { 0 };
+	const char *name;
+	size_t len;
 
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
@@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	if (!sb->s_root)
 		return -ENOMEM;
 
-	return binderfs_binder_ctl_create(sb);
+	ret = binderfs_binder_ctl_create(sb);
+	if (ret)
+		return ret;
+
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		strscpy(device_info.name, name, len + 1);
+		ret = binderfs_binder_device_create(inode, NULL, &device_info);
+		if (ret)
+			return ret;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
+
+	return 0;
 }
 
 static struct dentry *binderfs_mount(struct file_system_type *fs_type,
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
Reviewed-by on v3 1/2
#6 lore raw

Re: [PATCH v3 1/2] binder: Add default binder devices through binderfs when configured

In reply to Hridya Valsaraju
Quoted 11 lines · Hridya Valsaraju

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL. This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

Quoted 4 lines

---

thanks,

- Joel

Quoted 102 lines

Changes in v2:
- Updated commit message as per Greg Kroah-Hartman.
- Removed new module parameter creation as per Greg Kroah-Hartman/Christian Brauner.
- Refactored device name length check into a new patch as per Greg Kroah-Hartman.

Changes in v3:

(quoted diff) +0 -1
-Removed unnecessary empty lines as per Dan Carpenter.
 
 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 23 ++++++++++++++++++++---
 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/android/binder.c +3 -2
index 466b6a7f8ab7..ca6b21a53321 100644
@@ -123,7 +123,7 @@ static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
 	BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
 module_param_named(debug_mask, binder_debug_mask, uint, 0644);
 
-static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
+char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
 module_param_named(devices, binder_devices_param, charp, 0444);
 
 static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
@@ -6279,7 +6279,8 @@ static int __init binder_init(void)
 				    &transaction_log_fops);
 	}
 
-	if (strcmp(binder_devices_param, "") != 0) {
+	if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
+	    strcmp(binder_devices_param, "") != 0) {
 		/*
 		* Copy the module_parameter string, because we don't want to
 		* tokenize it in-place.
drivers/android/binder_internal.h +2 -0
index 045b3e42d98b..fe8c745dc8e0 100644
@@ -37,6 +37,8 @@ struct binder_device {
 
 extern const struct file_operations binder_fops;
 
+extern char *binder_devices_param;
+
 #ifdef CONFIG_ANDROID_BINDERFS
 extern bool is_binderfs_device(const struct inode *inode);
 #else
drivers/android/binderfs.c +20 -3
index e773f45d19d9..aee46dd1be91 100644
@@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
 	req->major = MAJOR(binderfs_dev);
 	req->minor = minor;
 
-	ret = copy_to_user(userp, req, sizeof(*req));
-	if (ret) {
+	if (userp && copy_to_user(userp, req, sizeof(*req))) {
 		ret = -EFAULT;
 		goto err;
 	}
@@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	int ret;
 	struct binderfs_info *info;
 	struct inode *inode = NULL;
+	struct binderfs_device device_info = { 0 };
+	const char *name;
+	size_t len;
 
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
@@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	if (!sb->s_root)
 		return -ENOMEM;
 
-	return binderfs_binder_ctl_create(sb);
+	ret = binderfs_binder_ctl_create(sb);
+	if (ret)
+		return ret;
+
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		strscpy(device_info.name, name, len + 1);
+		ret = binderfs_binder_device_create(inode, NULL, &device_info);
+		if (ret)
+			return ret;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
+
+	return 0;
 }
 
 static struct dentry *binderfs_mount(struct file_system_type *fs_type,
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#7 lore raw

PATCH v3 2/2 binder: Validate the default binderfs device names.

In reply to Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +12 -0
index aee46dd1be91..55c5adb87585 100644
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;
+
+	/* Verify that the default binderfs device names are valid. */
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
 
 	/* Allocate new major number for binderfs. */
 	ret = alloc_chrdev_region(&binderfs_dev, 0, BINDERFS_MAX_MINOR,
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#8 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 22 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +2 -0
index aee46dd1be91..55c5adb87585 100644
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 584

Quoted 10 lines
drivers/android/binderfs.c +10 -0
+
+	/* Verify that the default binderfs device names are valid. */
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}

Shouldn't this be a bugfix separate from patch 1/2?

And shouldn't it be backported to older kernels that currently have this issue?

thanks,

greg k-h

#9 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

In reply to Hridya Valsaraju
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;
+
+	/* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 584

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

thanks,

greg k-h

#10 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 28 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;
+
+	/* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 12 lines

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 584

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

Christian

#11 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 39 lines · Christian Brauner
Quoted 37 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
    int ret;
+   const char *name;
+   size_t len;
+
+   /* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+   name = binder_devices_param;
+   for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+           if (len > BINDERFS_MAX_NAME)
+                   return -E2BIG;
+           name += len;
+           if (*name == ',')
+                   name++;
+   }
Quoted 7 lines
Quoted 3 lines

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

Thank you Greg and Christian, for taking another look. Yes, non-binderfs binder devices not having this limitation is the reason why the check was made specific to binderfs devices. Also, when CONFIG_ANDROID_BINDERFS is set, patch 1/2 disabled the same string being parsed in binder_init().

Quoted 9 lines

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

I do not have any objections to adding a generic check in binder_init() instead.

Quoted 2 lines

Christian

#12 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 66 lines · Hridya Valsaraju
Quoted 39 lines · Christian Brauner
Quoted 37 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
    int ret;
+   const char *name;
+   size_t len;
+
+   /* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+   name = binder_devices_param;
+   for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+           if (len > BINDERFS_MAX_NAME)
+                   return -E2BIG;
+           name += len;
+           if (*name == ',')
+                   name++;
+   }
Quoted 7 lines
Quoted 3 lines

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

Thank you Greg and Christian, for taking another look. Yes, non-binderfs binder devices not having this limitation is the reason why the check was made specific to binderfs devices. Also, when CONFIG_ANDROID_BINDERFS is set, patch 1/2 disabled the same string being parsed in binder_init().

Quoted 9 lines

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

Quoted 1 line

I do not have any objections to adding a generic check in binder_init() instead.

Was this patchset going to be redone based on this?

thanks,

greg k-h

#13 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 67 lines · Greg Kroah-Hartman
Quoted 66 lines · Hridya Valsaraju
Quoted 39 lines · Christian Brauner
Quoted 37 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
    int ret;
+   const char *name;
+   size_t len;
+
+   /* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+   name = binder_devices_param;
+   for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+           if (len > BINDERFS_MAX_NAME)
+                   return -E2BIG;
+           name += len;
+           if (*name == ',')
+                   name++;
+   }
Quoted 7 lines
Quoted 3 lines

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

Thank you Greg and Christian, for taking another look. Yes, non-binderfs binder devices not having this limitation is the reason why the check was made specific to binderfs devices. Also, when CONFIG_ANDROID_BINDERFS is set, patch 1/2 disabled the same string being parsed in binder_init().

Quoted 9 lines

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

Quoted 3 lines
Quoted 1 line

I do not have any objections to adding a generic check in binder_init() instead.

Was this patchset going to be redone based on this?

No, we decided to leave this check specific to binderfs for now because the length limit only applies to binderfs devices. If you really want to have this check in binder we can send a follow-up. I would prefer to take the series as is.

Btw, for the two binderfs series from Hridya, do you want me to get a branch ready and send you a PR for both of them together?

Christian

#14 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 72 lines · Christian Brauner
Quoted 67 lines · Greg Kroah-Hartman
Quoted 66 lines · Hridya Valsaraju
Quoted 39 lines · Christian Brauner
Quoted 37 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
    int ret;
+   const char *name;
+   size_t len;
+
+   /* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+   name = binder_devices_param;
+   for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+           if (len > BINDERFS_MAX_NAME)
+                   return -E2BIG;
+           name += len;
+           if (*name == ',')
+                   name++;
+   }
Quoted 7 lines
Quoted 3 lines

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

Thank you Greg and Christian, for taking another look. Yes, non-binderfs binder devices not having this limitation is the reason why the check was made specific to binderfs devices. Also, when CONFIG_ANDROID_BINDERFS is set, patch 1/2 disabled the same string being parsed in binder_init().

Quoted 9 lines

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

Quoted 3 lines
Quoted 1 line

I do not have any objections to adding a generic check in binder_init() instead.

Was this patchset going to be redone based on this?

Quoted 7 lines

No, we decided to leave this check specific to binderfs for now because the length limit only applies to binderfs devices. If you really want to have this check in binder we can send a follow-up. I would prefer to take the series as is.

Btw, for the two binderfs series from Hridya, do you want me to get a branch ready and send you a PR for both of them together?

Patches in email is fine, but can someone resend this one as I no longer have this series in my queue anymore?

thanks,

greg k-h

#15 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

Quoted 78 lines · Greg Kroah-Hartman
Quoted 77 lines · Christian Brauner
Quoted 67 lines · Greg Kroah-Hartman
Quoted 66 lines · Hridya Valsaraju
Quoted 39 lines · Christian Brauner
Quoted 37 lines · Greg Kroah-Hartman
Quoted 17 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +0 -0
index aee46dd1be91..55c5adb87585 100644

drivers/android/binderfs.c static struct file_system_type binder_fs_type = { · line 576

Quoted 7 lines
drivers/android/binderfs.c +4 -0
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
    int ret;
+   const char *name;
+   size_t len;
+
+   /* Verify that the default binderfs device names are valid. */

And by "valid" you only mean "not bigger than BINDERFS_MAX_NAME, right?

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+   name = binder_devices_param;
+   for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+           if (len > BINDERFS_MAX_NAME)
+                   return -E2BIG;
+           name += len;
+           if (*name == ',')
+                   name++;
+   }
Quoted 7 lines
Quoted 3 lines

We already tokenize the binderfs device names in binder_init(), why not check this there instead? Parsing the same string over and over isn't the nicest.

non-binderfs binder devices do not have their limit set to BINDERFS_NAME_MAX. That's why the check has likely been made specific to binderfs binder devices which do have that limit.

Thank you Greg and Christian, for taking another look. Yes, non-binderfs binder devices not having this limitation is the reason why the check was made specific to binderfs devices. Also, when CONFIG_ANDROID_BINDERFS is set, patch 1/2 disabled the same string being parsed in binder_init().

Quoted 9 lines

But, in practice, 255 is the standard path-part limit that no-one really exceeds especially not for stuff such as device nodes which usually have rather standard naming schemes (e.g. binder, vndbinder, hwbinder, etc.). So yes, we can move that check before both the binderfs binder device and non-binderfs binder device parsing code and treat it as a generic check.
Then we can also backport that check as you requested in the other mail. Unless Hridya or Todd have objections, of course.

Quoted 3 lines
Quoted 1 line

I do not have any objections to adding a generic check in binder_init() instead.

Was this patchset going to be redone based on this?

No, we decided to leave this check specific to binderfs for now because the length limit only applies to binderfs devices. If you really want to have this check in binder we can send a follow-up. I would prefer to take the series as is.

Quoted 5 lines
Quoted 2 lines

Btw, for the two binderfs series from Hridya, do you want me to get a branch ready and send you a PR for both of them together?

Patches in email is fine, but can someone resend this one as I no longer have this series in my queue anymore?

Done!
Christian

Reviewed-by on v3 2/2
#16 lore raw

Re: [PATCH v3 2/2] binder: Validate the default binderfs device names.

In reply to Hridya Valsaraju
Quoted 9 lines · Hridya Valsaraju

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---

thanks,

- Joel

Quoted 29 lines
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +12 -0
index aee46dd1be91..55c5adb87585 100644
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;
+
+	/* Verify that the default binderfs device names are valid. */
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
 
 	/* Allocate new major number for binderfs. */
 	ret = alloc_chrdev_region(&binderfs_dev, 0, BINDERFS_MAX_MINOR,
Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#17 lore raw
In reply to Hridya Valsaraju
Quoted 10 lines · Hridya Valsaraju

Binderfs was created to help provide private binder devices to containers in their own IPC namespace. Currently, every time a new binderfs instance is mounted, its private binder devices need to be created via IOCTL calls. This patch series eliminates the effort for creating the default binder devices for each binderfs instance by creating them automatically.

Hridya Valsaraju (2):
binder: Add default binder devices through binderfs when configured
binder: Validate the default binderfs device names.

I'd like to get a reviewed-by from the other binder maintainers before taking this series....

{hint}

#18 lore raw

v3 cover Add default binderfs devices

In reply to Hridya Valsaraju

Hey,

This is a resend of Hridya's series to add default binderfs devices. No semantical changes were made. Only Joel's Acks were added by me.

Binderfs was created to help provide private binder devices to containers in their own IPC namespace. Currently, every time a new binderfs instance is mounted, its private binder devices need to be created via IOCTL calls. This patch series eliminates the effort for creating the default binder devices for each binderfs instance by creating them automatically.

/* v0 */

/* v1 */

/* v2 */

Thanks!
Christian

Hridya Valsaraju (2):
binder: Add default binder devices through binderfs when configured
binder: Validate the default binderfs device names.

 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 35 ++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 5 deletions(-)
Signature · 1 line
2.23.0
#19 lore raw

PATCH RESEND v3 1/2 binder: Add default binder devices through binderfs when configured

From: Hridya Valsaraju <[email protected]>

Currently, since each binderfs instance needs its own private binder devices, every time a binderfs instance is mounted, all the default binder devices need to be created via the BINDER_CTL_ADD IOCTL. This patch aims to
add a solution to automatically create the default binder devices for each binderfs instance that gets mounted.
To achieve this goal, when CONFIG_ANDROID_BINDERFS is set, the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES are created in each binderfs instance instead of global devices being created by the binder driver.

---
 drivers/android/binder.c          |  5 +++--
 drivers/android/binder_internal.h |  2 ++
 drivers/android/binderfs.c        | 23 ++++++++++++++++++++---
 3 files changed, 25 insertions(+), 5 deletions(-)
drivers/android/binder.c +3 -2
index dc1c83eafc22..ef2d3e582368 100644
@@ -122,7 +122,7 @@ static uint32_t binder_debug_mask = BINDER_DEBUG_USER_ERROR |
 	BINDER_DEBUG_FAILED_TRANSACTION | BINDER_DEBUG_DEAD_TRANSACTION;
 module_param_named(debug_mask, binder_debug_mask, uint, 0644);
 
-static char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
+char *binder_devices_param = CONFIG_ANDROID_BINDER_DEVICES;
 module_param_named(devices, binder_devices_param, charp, 0444);
 
 static DECLARE_WAIT_QUEUE_HEAD(binder_user_error_wait);
@@ -6131,7 +6131,8 @@ static int __init binder_init(void)
 				    &transaction_log_fops);
 	}
 
-	if (strcmp(binder_devices_param, "") != 0) {
+	if (!IS_ENABLED(CONFIG_ANDROID_BINDERFS) &&
+	    strcmp(binder_devices_param, "") != 0) {
 		/*
 		* Copy the module_parameter string, because we don't want to
 		* tokenize it in-place.
drivers/android/binder_internal.h +2 -0
index 045b3e42d98b..fe8c745dc8e0 100644
@@ -37,6 +37,8 @@ struct binder_device {
 
 extern const struct file_operations binder_fops;
 
+extern char *binder_devices_param;
+
 #ifdef CONFIG_ANDROID_BINDERFS
 extern bool is_binderfs_device(const struct inode *inode);
 #else
drivers/android/binderfs.c +20 -3
index e773f45d19d9..aee46dd1be91 100644
@@ -186,8 +186,7 @@ static int binderfs_binder_device_create(struct inode *ref_inode,
 	req->major = MAJOR(binderfs_dev);
 	req->minor = minor;
 
-	ret = copy_to_user(userp, req, sizeof(*req));
-	if (ret) {
+	if (userp && copy_to_user(userp, req, sizeof(*req))) {
 		ret = -EFAULT;
 		goto err;
 	}
@@ -467,6 +466,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	int ret;
 	struct binderfs_info *info;
 	struct inode *inode = NULL;
+	struct binderfs_device device_info = { 0 };
+	const char *name;
+	size_t len;
 
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
@@ -521,7 +523,22 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent)
 	if (!sb->s_root)
 		return -ENOMEM;
 
-	return binderfs_binder_ctl_create(sb);
+	ret = binderfs_binder_ctl_create(sb);
+	if (ret)
+		return ret;
+
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		strscpy(device_info.name, name, len + 1);
+		ret = binderfs_binder_device_create(inode, NULL, &device_info);
+		if (ret)
+			return ret;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
+
+	return 0;
 }
 
 static struct dentry *binderfs_mount(struct file_system_type *fs_type,
Signature · 1 line
2.23.0
#20 lore raw

PATCH RESEND v3 2/2 binder: Validate the default binderfs device names.

In reply to Christian Brauner

From: Hridya Valsaraju <[email protected]>

Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME. This patch adds a check in binderfs_init() to ensure the same for the default binder devices that will be created in every binderfs instance.

---
 drivers/android/binderfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/android/binderfs.c +12 -0
index aee46dd1be91..55c5adb87585 100644
@@ -570,6 +570,18 @@ static struct file_system_type binder_fs_type = {
 int __init init_binderfs(void)
 {
 	int ret;
+	const char *name;
+	size_t len;
+
+	/* Verify that the default binderfs device names are valid. */
+	name = binder_devices_param;
+	for (len = strcspn(name, ","); len > 0; len = strcspn(name, ",")) {
+		if (len > BINDERFS_MAX_NAME)
+			return -E2BIG;
+		name += len;
+		if (*name == ',')
+			name++;
+	}
 
 	/* Allocate new major number for binderfs. */
 	ret = alloc_chrdev_region(&binderfs_dev, 0, BINDERFS_MAX_MINOR,
Signature · 1 line
2.23.0
maintainer
#21 lore raw
In reply to Christian Brauner
Quoted 11 lines · Christian Brauner

Hey,

This is a resend of Hridya's series to add default binderfs devices. No semantical changes were made. Only Joel's Acks were added by me.

Binderfs was created to help provide private binder devices to containers in their own IPC namespace. Currently, every time a new binderfs instance is mounted, its private binder devices need to be created via IOCTL calls. This patch series eliminates the effort for creating the default binder devices for each binderfs instance by creating them automatically.

All now applied, thanks!

greg k-h