[Cbe-oss-dev] [PATCH] spufs: disallow writes to signal{1, 2} files for nosched contexts

Christoph Hellwig hch at lst.de
Sun Feb 10 18:04:14 EST 2008


In any unix system root can overrid the lack of write permission on a
file when opening it.  On files that don't have a ->write method the
VFS will make sure to return EINVAL in the case of actually performing
a write operations.

But in spufs we have the signal1 and signal2 files that do have a ->write
method and are allowed to be written to for normal contexts, just not
nosched contexts.  To actually enforce this the file permissions are not
enough as explained above so we need to explicitly return EINVAL for
nosched contexts in the ->write methods.


Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: linux-2.6/arch/powerpc/platforms/cell/spufs/file.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/file.c	2008-02-10 07:55:19.000000000 +0100
+++ linux-2.6/arch/powerpc/platforms/cell/spufs/file.c	2008-02-10 07:57:18.000000000 +0100
@@ -951,11 +951,16 @@ static ssize_t spufs_signal1_read(struct
 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
 			size_t len, loff_t *pos)
 {
-	struct spu_context *ctx;
+	struct spu_context *ctx = file->private_data;
 	ssize_t ret;
 	u32 data;
 
-	ctx = file->private_data;
+	/*
+	 * Root can override the lack of write permission for the signal{1,2}
+	 * files, so we need to manually reject the write here.
+	 */
+	if (ctx->flags & SPU_CREATE_NOSCHED)
+		return -EINVAL;
 
 	if (len < 4)
 		return -EINVAL;
@@ -1087,11 +1092,16 @@ static ssize_t spufs_signal2_read(struct
 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
 			size_t len, loff_t *pos)
 {
-	struct spu_context *ctx;
+	struct spu_context *ctx = file->private_data;
 	ssize_t ret;
 	u32 data;
 
-	ctx = file->private_data;
+	/*
+	 * Root can override the lack of write permission for the signal{1,2}
+	 * files, so we need to manually reject the write here.
+	 */
+	if (ctx->flags & SPU_CREATE_NOSCHED)
+		return -EINVAL;
 
 	if (len < 4)
 		return -EINVAL;



More information about the cbe-oss-dev mailing list