Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1328243

[PATCH 1/2] staging/lustre/libcfs: Properly handle debugfs read- and write-only files

From green@linuxhacker.ru
Newsgroups linux.kernel
Subject [PATCH 1/2] staging/lustre/libcfs: Properly handle debugfs read- and write-only files
Date 2016-02-06 08:40 +0100
Message-ID <qZ5Dk-42z-9@gated-at.bofh.it> (permalink)
References <qZ5Dj-42z-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Oleg Drokin <green@linuxhacker.ru>

It turns out that unlike procfs, debugfs does not really enforce
permissions for root (similar to regular filesystems), so we need
to ensure we are not providing ->write() method to read-only files
and ->read() method for write-only files at registration.

This fixes a couple of crashes on unexpected access.

Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
---
 drivers/staging/lustre/lustre/libcfs/module.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
index d5a047b..611607a 100644
--- a/drivers/staging/lustre/lustre/libcfs/module.c
+++ b/drivers/staging/lustre/lustre/libcfs/module.c
@@ -502,13 +502,36 @@ static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
 	return error;
 }
 
-static const struct file_operations lnet_debugfs_file_operations = {
+static const struct file_operations lnet_debugfs_file_operations_rw = {
 	.open		= simple_open,
 	.read		= lnet_debugfs_read,
 	.write		= lnet_debugfs_write,
 	.llseek		= default_llseek,
 };
 
+static const struct file_operations lnet_debugfs_file_operations_ro = {
+	.open		= simple_open,
+	.read		= lnet_debugfs_read,
+	.llseek		= default_llseek,
+};
+
+static const struct file_operations lnet_debugfs_file_operations_wo = {
+	.open		= simple_open,
+	.write		= lnet_debugfs_write,
+	.llseek		= default_llseek,
+};
+
+static const struct file_operations *lnet_debugfs_fops_select(umode_t mode)
+{
+	if (!(mode & S_IWUGO))
+		return &lnet_debugfs_file_operations_ro;
+
+	if (!(mode & S_IRUGO))
+		return &lnet_debugfs_file_operations_wo;
+
+	return &lnet_debugfs_file_operations_rw;
+}
+
 void lustre_insert_debugfs(struct ctl_table *table,
 			   const struct lnet_debugfs_symlink_def *symlinks)
 {
@@ -525,7 +548,7 @@ void lustre_insert_debugfs(struct ctl_table *table,
 	for (; table->procname; table++)
 		debugfs_create_file(table->procname, table->mode,
 				    lnet_debugfs_root, table,
-				    &lnet_debugfs_file_operations);
+				    lnet_debugfs_fops_select(table->mode));
 
 	for (; symlinks && symlinks->name; symlinks++)
 		debugfs_create_symlink(symlinks->name, lnet_debugfs_root,
-- 
2.1.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] Lustre debugfs fixes green@linuxhacker.ru - 2016-02-06 08:40 +0100
  [PATCH 1/2] staging/lustre/libcfs: Properly handle debugfs read- and write-only files green@linuxhacker.ru - 2016-02-06 08:40 +0100
  Re: [PATCH 0/2] Lustre debugfs fixes Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-02-07 22:40 +0100
    Re: [PATCH 0/2] Lustre debugfs fixes Oleg Drokin <green@linuxhacker.ru> - 2016-02-08 01:00 +0100
      Re: [PATCH 0/2] Lustre debugfs fixes Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-02-08 03:30 +0100

csiph-web