[PATCH 2/2] Disallow seeks on sysfs files.

From: Mitch Williams
Date: Tue Jan 25 2005 - 17:45:07 EST


This patch causes an error return if the user attempts to seek on a sysfs
file.

The patch was generated from 2.6.11-rc1.

Signed-off-by: Mitch Williams <mitch.a.williams@xxxxxxxxx>

diff -urpN -X dontdiff linux-2.6.11-clean/fs/sysfs/file.c linux-2.6.11/fs/sysfs/file.c
--- linux-2.6.11-clean/fs/sysfs/file.c 2004-12-24 13:33:50.000000000 -0800
+++ linux-2.6.11/fs/sysfs/file.c 2005-01-25 10:28:25.000000000 -0800
@@ -307,6 +307,10 @@ static int check_perm(struct inode * ino
file->private_data = buffer;
} else
error = -ENOMEM;
+
+ /* Set mode bits to disallow seeking. */
+ file->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
+
goto Done;

Einval:
@@ -349,7 +353,7 @@ static int sysfs_release(struct inode *
struct file_operations sysfs_file_operations = {
.read = sysfs_read_file,
.write = sysfs_write_file,
- .llseek = generic_file_llseek,
+ .llseek = no_llseek,
.open = sysfs_open_file,
.release = sysfs_release,
};
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/