Skip to contentSkip to conversation

ANDROID: binderfs: add capabilities support

PATCH In review Carlos Llamas 3 participants 12 messages Jul 7, 2021 – Jul 15, 2021

Subsystems (3)
lore
Share & tools
lore

Carlos Llamas

author maintainer
#0 lore raw

PATCH 1/1 ANDROID: binderfs: add capabilities support

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +45 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
 	binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+	bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
 	{ "global", binderfs_stats_mode_global },
 	{}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
 	{}
 };
 
+static struct binder_capabilities binder_caps = {
+	.oneway_spam = true,
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
 	return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
 	return dentry;
 }
 
+static int binder_caps_show(struct seq_file *m, void *unused)
+{
+	bool *cap = m->private;
+
+	seq_printf(m, "%d\n", *cap);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)
+{
+	struct dentry *dentry, *root;
+	int ret = 0;
+
+	root = binderfs_create_dir(sb->s_root, "caps");
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
+		goto out;
+	}
+
+	dentry = binderfs_create_file(root, "oneway_spam",
+				      &binder_caps_fops,
+				      &binder_caps.oneway_spam);
+	if (IS_ERR(dentry)) {
+		ret = PTR_ERR(dentry);
+		goto out;
+	}
+
+out:
+	return ret;
+}
+
 static int init_binder_logs(struct super_block *sb)
 {
 	struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir;
@@ -723,6 +764,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
 			name++;
 	}
 
+	ret = init_binder_caps(sb);
+	if (ret)
+		return ret;
+
 	if (info->mount_opts.stats_mode == binderfs_stats_mode_global)
 		return init_binder_logs(sb);
 
Signature · 1 line
2.32.0.93.g670b81a890-goog
#1 lore raw
Quoted 4 lines · Carlos Llamas

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

What defines "new" vs. "old"? Where was the line drawn?

Quoted 52 lines
---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +25 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
 	binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+	bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
 	{ "global", binderfs_stats_mode_global },
 	{}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
 	{}
 };
 
+static struct binder_capabilities binder_caps = {
+	.oneway_spam = true,
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
 	return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
 	return dentry;
 }
 
+static int binder_caps_show(struct seq_file *m, void *unused)
+{
+	bool *cap = m->private;
+
+	seq_printf(m, "%d\n", *cap);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)
+{
+	struct dentry *dentry, *root;
+	int ret = 0;
+
+	root = binderfs_create_dir(sb->s_root, "caps");
+	if (IS_ERR(root)) {

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 620

Quoted 10 lines
drivers/android/binderfs.c +10 -0
+		ret = PTR_ERR(root);
+		goto out;
+	}
+
+	dentry = binderfs_create_file(root, "oneway_spam",
+				      &binder_caps_fops,
+				      &binder_caps.oneway_spam);
+	if (IS_ERR(dentry)) {
+		ret = PTR_ERR(dentry);
+		goto out;

If this fails, you still report that an error happened, yet you do not remove the directory? Is that intended?

And where is this new file documented? Where are the existing binderfs files documented?

thanks,

greg k-h

author maintainer
#2 lore raw
Quoted 8 lines · Greg Kroah-Hartman
Quoted 4 lines · Carlos Llamas

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

What defines "new" vs. "old"? Where was the line drawn?

Any feature after "one way spam" may be added to the capabilities. I'll amend the commit message to indicate this.

Quoted 58 lines
Quoted 58 lines
---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +30 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
      binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+     bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
      { "global", binderfs_stats_mode_global },
      {}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
      {}
 };
 
+static struct binder_capabilities binder_caps = {
+     .oneway_spam = true,
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
      return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
      return dentry;
 }
 
+static int binder_caps_show(struct seq_file *m, void *unused)
+{
+     bool *cap = m->private;
+
+     seq_printf(m, "%d\n", *cap);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)
+{
+     struct dentry *dentry, *root;
+     int ret = 0;
+
+     root = binderfs_create_dir(sb->s_root, "caps");
+     if (IS_ERR(root)) {
+             ret = PTR_ERR(root);
+             goto out;
+     }
+
+     dentry = binderfs_create_file(root, "oneway_spam",
Quoted 8 lines

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 620

Quoted 5 lines
drivers/android/binderfs.c +5 -0
+                                   &binder_caps_fops,
+                                   &binder_caps.oneway_spam);
+     if (IS_ERR(dentry)) {
+             ret = PTR_ERR(dentry);
+             goto out;

If this fails, you still report that an error happened, yet you do not remove the directory? Is that intended?

Propagating an error in this case will kill the super block along with the capabilities entries. At a user level the binderfs will fail to be mounted, so anything created up until this point is removed.

Quoted 3 lines

And where is this new file documented? Where are the existing binderfs files documented?

oh! we do have "Documentation/admin-guide/binderfs.rst". I'll add a brief explanation of these new capabilities files there.

Quoted 4 lines

thanks,

greg k-h

thanks,
carlos llamas

#3 lore raw
In reply to Greg Kroah-Hartman
Quoted 74 lines · Greg Kroah-Hartman
Quoted 4 lines · Carlos Llamas

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

What defines "new" vs. "old"? Where was the line drawn?

Quoted 52 lines
---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +25 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
 	binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+	bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
 	{ "global", binderfs_stats_mode_global },
 	{}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
 	{}
 };
 
+static struct binder_capabilities binder_caps = {
+	.oneway_spam = true,
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
 	return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
 	return dentry;
 }
 
+static int binder_caps_show(struct seq_file *m, void *unused)
+{
+	bool *cap = m->private;
+
+	seq_printf(m, "%d\n", *cap);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)
+{
+	struct dentry *dentry, *root;
+	int ret = 0;
+
+	root = binderfs_create_dir(sb->s_root, "caps");
+	if (IS_ERR(root)) {

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 620

Quoted 10 lines
drivers/android/binderfs.c +10 -0
+		ret = PTR_ERR(root);
+		goto out;
+	}
+
+	dentry = binderfs_create_file(root, "oneway_spam",
+				      &binder_caps_fops,
+				      &binder_caps.oneway_spam);
+	if (IS_ERR(dentry)) {
+		ret = PTR_ERR(dentry);
+		goto out;

If this fails, you still report that an error happened, yet you do not remove the directory? Is that intended?

Quoted 2 lines

And where is this new file documented? Where are the existing binderfs files documented?

When I wrote it I added documentation to:

Documentation/admin-guide/binderfs.rst

So the new caps directory and file should be documented there.

I would also suggest to add a simple test reading this new caps directory and the new file in there to:

tools/testing/selftests/filesystems/binderfs_test.c

Christian

#4 lore raw
In reply to Carlos Llamas
Quoted 2 lines · Carlos Llamas

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features

Hey Carlos,

The model will be one file per feature?

Instead of calling the directory "caps" should this maybe be called "features"? I'm not fuzzed about it and if you want to keep "caps" that's fine. The term is just a bit overused and makes me think of other things than this.

Quoted 2 lines

in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

What if you ever want to deprecate one? :)

Quoted 22 lines
---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +4 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
 	binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+	bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
 	{ "global", binderfs_stats_mode_global },
 	{}

drivers/android/binderfs.c static const struct fs_parameter_spec binderfs_fs_parameters[] = { · line 77

Quoted 5 lines
drivers/android/binderfs.c +2 -0
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
 	{}
 };
 
+static struct binder_capabilities binder_caps = {
+	.oneway_spam = true,

I know this is the oneway spam _detection_ feature but this file makes it sound like the binder driver has the capability to generate one-way spam. :) Maybe name at least name the file "oneway_spam_detection".

Quoted 10 lines
drivers/android/binderfs.c +3 -0
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
 	return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
 	return dentry;
 }
 
+static int binder_caps_show(struct seq_file *m, void *unused)

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 604

Quoted 10 lines
drivers/android/binderfs.c +10 -0
+{
+	bool *cap = m->private;
+
+	seq_printf(m, "%d\n", *cap);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)

You can drop the goto here and just always return directly.

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 606

Quoted 2 lines
drivers/android/binderfs.c +2 -0
+{
+	struct dentry *dentry, *root;

Please name this "dir" instead of "root". "root" is conventionally used for sb->s_root and especially here in this file I only ever used it to indicate s_root.

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 611

Quoted 5 lines
drivers/android/binderfs.c +5 -0
+	int ret = 0;
+
+	root = binderfs_create_dir(sb->s_root, "caps");
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
	return PTR_ERR(root);

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 619

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+		goto out;
+	}
+
+	dentry = binderfs_create_file(root, "oneway_spam",
+				      &binder_caps_fops,
+				      &binder_caps.oneway_spam);
+	if (IS_ERR(dentry)) {
+		ret = PTR_ERR(dentry);
	return PTR_ERR(root);
Quoted 24 lines
drivers/android/binderfs.c +11 -0
+		goto out;
+	}
+
+out:
+	return ret;
+}
+
 static int init_binder_logs(struct super_block *sb)
 {
 	struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir;
@@ -723,6 +764,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
 			name++;
 	}
 
+	ret = init_binder_caps(sb);
+	if (ret)
+		return ret;
+
 	if (info->mount_opts.stats_mode == binderfs_stats_mode_global)
 		return init_binder_logs(sb);
 
Signature · 1 line
2.32.0.93.g670b81a890-goog
author maintainer
#5 lore raw
Quoted 8 lines · Christian Brauner
Quoted 2 lines · Carlos Llamas

Provide userspace with a mechanism to discover binder driver capabilities to refrain from using these unsupported features

Hey Carlos,

The model will be one file per feature?

Yes. I dropped a previous single bitmask file idea per Greg's suggestion. The file per feature improves on a number of areas such as feature count limit, readability and it's easier to manage (add/remove features).

Quoted 5 lines

Instead of calling the directory "caps" should this maybe be called "features"? I'm not fuzzed about it and if you want to keep "caps" that's fine. The term is just a bit overused and makes me think of other things than this.

I have no problems switching over to "features".

Quoted 5 lines
Quoted 3 lines

in the first place. Note that older capabilities are assumed to be supported and only new ones will be added.

What if you ever want to deprecate one? :)

If the file for a feature doesn't exist then such feature is not supported. So we can avoid creating such file if a feature were to be deprecated.

Quoted 26 lines
Quoted 26 lines
---
 drivers/android/binderfs.c | 45 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
drivers/android/binderfs.c +4 -0
index e80ba93c62a9..f793887f6dc8 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
      binderfs_stats_mode_global,
 };
 
+struct binder_capabilities {
+     bool oneway_spam;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
      { "global", binderfs_stats_mode_global },
      {}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
      {}
 };
 
Quoted 6 lines

drivers/android/binderfs.c static const struct fs_parameter_spec binderfs_fs_parameters[] = { · line 77

Quoted 2 lines
drivers/android/binderfs.c +2 -0
+static struct binder_capabilities binder_caps = {
+     .oneway_spam = true,

I know this is the oneway spam _detection_ feature but this file makes it sound like the binder driver has the capability to generate one-way spam. :) Maybe name at least name the file "oneway_spam_detection".

That's true. I'll rename it as suggested.

Quoted 10 lines
Quoted 10 lines
drivers/android/binderfs.c +2 -0
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
      return sb->s_fs_info;
@@ -583,6 +591,39 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
      return dentry;
 }
 
Quoted 13 lines

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 604

Quoted 11 lines
drivers/android/binderfs.c +11 -0
+static int binder_caps_show(struct seq_file *m, void *unused)
+{
+     bool *cap = m->private;
+
+     seq_printf(m, "%d\n", *cap);
+
+     return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_caps);
+
+static int init_binder_caps(struct super_block *sb)

You can drop the goto here and just always return directly.

I also noticed this and I decided to keep it consistent with init_binder_logs() structure. But I don't have a strong preference so I'll switch to early returns.

Quoted 7 lines

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 606

Quoted 3 lines
drivers/android/binderfs.c +2 -0
+{
+     struct dentry *dentry, *root;

Please name this "dir" instead of "root". "root" is conventionally used for sb->s_root and especially here in this file I only ever used it to indicate s_root.

ok, sounds good.

Quoted 41 lines

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 611

Quoted 6 lines
drivers/android/binderfs.c +5 -0
+     int ret = 0;
+
+     root = binderfs_create_dir(sb->s_root, "caps");
+     if (IS_ERR(root)) {
+             ret = PTR_ERR(root);
        return PTR_ERR(root);

drivers/android/binderfs.c static struct dentry *binderfs_create_dir(struct dentry *parent, · line 619

Quoted 8 lines
drivers/android/binderfs.c +8 -0
+             goto out;
+     }
+
+     dentry = binderfs_create_file(root, "oneway_spam",
+                                   &binder_caps_fops,
+                                   &binder_caps.oneway_spam);
+     if (IS_ERR(dentry)) {
+             ret = PTR_ERR(dentry);
        return PTR_ERR(root);
Quoted 21 lines
drivers/android/binderfs.c +11 -0
+             goto out;
+     }
+
+out:
+     return ret;
+}
+
 static int init_binder_logs(struct super_block *sb)
 {
      struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir;
@@ -723,6 +764,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
                      name++;
      }
 
+     ret = init_binder_caps(sb);
+     if (ret)
+             return ret;
+
      if (info->mount_opts.stats_mode == binderfs_stats_mode_global)
              return init_binder_logs(sb);
 
Quoted 3 lines
Quoted 3 lines

--
2.32.0.93.g670b81a890-goog

thanks,
carlos llamas

author maintainer
#6 lore raw

PATCH v2 1/3 binderfs: add support for feature files

In reply to Carlos Llamas

Provide userspace with a mechanism to discover features supported by the binder driver to refrain from using any unsupported ones in the first place. Starting with "oneway_spam_detection" only new features are to be listed under binderfs and all previous ones are assumed to be supported.

Assuming an instance of binderfs has been mounted at /dev/binderfs, binder feature files can be found under /dev/binderfs/features/. Usage example:

  $ mkdir /dev/binderfs
  $ mount -t binder binder /dev/binderfs
  $ cat /dev/binderfs/features/oneway_spam_detection
  1
---
 drivers/android/binderfs.c | 39 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/android/binderfs.c +39 -0
index e80ba93c62a9..e3605cdd4335 100644
@@ -58,6 +58,10 @@ enum binderfs_stats_mode {
 	binderfs_stats_mode_global,
 };
 
+struct binder_features {
+	bool oneway_spam_detection;
+};
+
 static const struct constant_table binderfs_param_stats[] = {
 	{ "global", binderfs_stats_mode_global },
 	{}
@@ -69,6 +73,10 @@ static const struct fs_parameter_spec binderfs_fs_parameters[] = {
 	{}
 };
 
+static struct binder_features binder_features = {
+	.oneway_spam_detection = true,
+};
+
 static inline struct binderfs_info *BINDERFS_SB(const struct super_block *sb)
 {
 	return sb->s_fs_info;
@@ -583,6 +591,33 @@ static struct dentry *binderfs_create_dir(struct dentry *parent,
 	return dentry;
 }
 
+static int binder_features_show(struct seq_file *m, void *unused)
+{
+	bool *feature = m->private;
+
+	seq_printf(m, "%d\n", *feature);
+
+	return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(binder_features);
+
+static int init_binder_features(struct super_block *sb)
+{
+	struct dentry *dentry, *dir;
+
+	dir = binderfs_create_dir(sb->s_root, "features");
+	if (IS_ERR(dir))
+		return PTR_ERR(dir);
+
+	dentry = binderfs_create_file(dir, "oneway_spam_detection",
+				      &binder_features_fops,
+				      &binder_features.oneway_spam_detection);
+	if (IS_ERR(dentry))
+		return PTR_ERR(dentry);
+
+	return 0;
+}
+
 static int init_binder_logs(struct super_block *sb)
 {
 	struct dentry *binder_logs_root_dir, *dentry, *proc_log_dir;
@@ -723,6 +758,10 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
 			name++;
 	}
 
+	ret = init_binder_features(sb);
+	if (ret)
+		return ret;
+
 	if (info->mount_opts.stats_mode == binderfs_stats_mode_global)
 		return init_binder_logs(sb);
 
Signature · 1 line
2.32.0.93.g670b81a890-goog
author maintainer
#7 lore raw

PATCH v2 2/3 docs: binderfs: add section about feature files

Document how binder feature files can be used to determine whether a feature is supported by the binder driver. "oneway_spam_detection" is used as an example as it is the first available feature file.

---
 Documentation/admin-guide/binderfs.rst | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/admin-guide/binderfs.rst +13 -0
index 199d84314a14..41a4db00df8d 100644
@@ -72,3 +72,16 @@ that the `rm() <rm_>`_ tool can be used to delete them. Note that the
 ``binder-control`` device cannot be deleted since this would make the binderfs
 instance unusable.  The ``binder-control`` device will be deleted when the
 binderfs instance is unmounted and all references to it have been dropped.
+
+Binder features
+---------------
+
+Assuming an instance of binderfs has been mounted at ``/dev/binderfs``, the
+features supported by the binder driver can be located under
+``/dev/binderfs/features/``. The presence of individual files can be tested
+to determine whether a particular feature is supported by the driver.
+
+Example::
+
+        cat /dev/binderfs/features/oneway_spam_detection
+        1
Signature · 1 line
2.32.0.93.g670b81a890-goog
author maintainer
#9 lore raw

PATCH v2 3/3 selftests/binderfs: add test for feature files

In reply to Carlos Llamas

Verify that feature files are created successfully after mounting a binderfs instance. Note that only "oneway_spam_detection" feature is tested with this patch as it is currently the only feature listed.

---
 .../filesystems/binderfs/binderfs_test.c        | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tools/testing/selftests/filesystems/binderfs/binderfs_test.c +17 -0
index 477cbb042f5b..0315955ff0f4 100644
@@ -62,6 +62,9 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
 	struct binder_version version = { 0 };
 	char binderfs_mntpt[] = P_tmpdir "/binderfs_XXXXXX",
 		device_path[sizeof(P_tmpdir "/binderfs_XXXXXX/") + BINDERFS_MAX_NAME];
+	static const char * const binder_features[] = {
+		"oneway_spam_detection",
+	};
 
 	change_mountns(_metadata);
 
@@ -150,6 +153,20 @@ static int __do_binderfs_test(struct __test_metadata *_metadata)
 	}
 
 	/* success: binder-control device removal failed as expected */
+
+	for (int i = 0; i < ARRAY_SIZE(binder_features); i++) {
+		snprintf(device_path, sizeof(device_path), "%s/features/%s",
+			 binderfs_mntpt, binder_features[i]);
+		fd = open(device_path, O_CLOEXEC | O_RDONLY);
+		EXPECT_GE(fd, 0) {
+			TH_LOG("%s - Failed to open binder feature: %s",
+				strerror(errno), binder_features[i]);
+			goto umount;
+		}
+		close(fd);
+	}
+
+	/* success: binder feature files found */
 	result = 0;
 
 umount:
Signature · 1 line
2.32.0.93.g670b81a890-goog
Acked-by on v2 1/3
#11 lore raw

Re: [PATCH v2 1/3] binderfs: add support for feature files

In reply to Carlos Llamas
Quoted 10 lines · Carlos Llamas

Provide userspace with a mechanism to discover features supported by the binder driver to refrain from using any unsupported ones in the first place. Starting with "oneway_spam_detection" only new features are to be listed under binderfs and all previous ones are assumed to be supported.

Assuming an instance of binderfs has been mounted at /dev/binderfs, binder feature files can be found under /dev/binderfs/features/. Usage example:

Quoted 7 lines
  $ mkdir /dev/binderfs
  $ mount -t binder binder /dev/binderfs
  $ cat /dev/binderfs/features/oneway_spam_detection
  1

---

Looks good,