debugfs: Add read-only/write-only bool file ops
authorStephen Boyd <sboyd@codeaurora.org>
Tue, 13 Oct 2015 01:09:12 +0000 (18:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 18 Oct 2015 05:09:03 +0000 (22:09 -0700)
There aren't any read-only or write-only bool file ops, but there
is a caller of debugfs_create_bool() that calls it with mode
equal to 0400. This leads to the possibility of userspace
modifying the file, so let's use the newly created
debugfs_create_mode() helper here to fix this.

Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/debugfs/file.c

index e8e73aebe6b824b78ac22d419bfd4a432cadef27..8450549d54a90430b86dd32ad14c038a8d6b4efd 100644 (file)
@@ -450,6 +450,18 @@ static const struct file_operations fops_bool = {
        .llseek =       default_llseek,
 };
 
+static const struct file_operations fops_bool_ro = {
+       .read =         debugfs_read_file_bool,
+       .open =         simple_open,
+       .llseek =       default_llseek,
+};
+
+static const struct file_operations fops_bool_wo = {
+       .write =        debugfs_write_file_bool,
+       .open =         simple_open,
+       .llseek =       default_llseek,
+};
+
 /**
  * debugfs_create_bool - create a debugfs file that is used to read and write a boolean value
  * @name: a pointer to a string containing the name of the file to create.
@@ -477,7 +489,8 @@ static const struct file_operations fops_bool = {
 struct dentry *debugfs_create_bool(const char *name, umode_t mode,
                                   struct dentry *parent, bool *value)
 {
-       return debugfs_create_file(name, mode, parent, value, &fops_bool);
+       return debugfs_create_mode(name, mode, parent, value, &fops_bool,
+                                  &fops_bool_ro, &fops_bool_wo);
 }
 EXPORT_SYMBOL_GPL(debugfs_create_bool);