[PATCH][RFC] security: call security_file_permission from rw_verify_area

Previous thread: Re: [RFD] Incremental fsck by Bodo Eggert on Friday, January 11, 2008 - 10:20 am. (2 messages)

Next thread: [ANNOUNCE] autofs 5.0.3 release by Ian Kent on Monday, January 14, 2008 - 1:22 am. (1 message)
To: <linux-fsdevel@...>
Cc: <linux-kernel@...>, <linux-security-module@...>
Date: Saturday, January 12, 2008 - 7:20 am

Please review.

Tested with SELinux in enforcing mode.

---

All instances of rw_verify_area() are followed by a call to
security_file_permission(), so just call the latter from the former.

Signed-off-by: James Morris <jmorris@namei.org>
---
fs/compat.c | 4 ---
fs/read_write.c | 63 +++++++++++++++++++++----------------------------------
fs/splice.c | 8 -------
3 files changed, 24 insertions(+), 51 deletions(-)

diff --git a/fs/compat.c b/fs/compat.c
index 15078ce..5216c3f 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1104,10 +1104,6 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
if (ret < 0)
goto out;

- ret = security_file_permission(file, type == READ ? MAY_READ:MAY_WRITE);
- if (ret)
- goto out;
-
fnv = NULL;
if (type == READ) {
fn = file->f_op->read;
diff --git a/fs/read_write.c b/fs/read_write.c
index ea1f94c..c4d3d17 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -197,25 +197,27 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
{
struct inode *inode;
loff_t pos;
+ int retval = -EINVAL;

inode = file->f_path.dentry->d_inode;
if (unlikely((ssize_t) count < 0))
- goto Einval;
+ return retval;
pos = *ppos;
if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
- goto Einval;
+ return retval;

if (unlikely(inode->i_flock && mandatory_lock(inode))) {
- int retval = locks_mandatory_area(
+ retval = locks_mandatory_area(
read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
inode, file, pos, count);
if (retval < 0)
return retval;
}
+ retval = security_file_permission(file,
+ read_write == READ ? MAY_READ : MAY_WRITE);
+ if (retval)
+ return retval;
return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
-
-Einval:
- return -EINVAL;
}

static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
@@ -267,18 +269,15 @@ ssize_t vfs_read(struct file *file, ch...

Previous thread: Re: [RFD] Incremental fsck by Bodo Eggert on Friday, January 11, 2008 - 10:20 am. (2 messages)

Next thread: [ANNOUNCE] autofs 5.0.3 release by Ian Kent on Monday, January 14, 2008 - 1:22 am. (1 message)