slim: move file revocation into file_table.c and mprotect.c
Subsystems (6)
PATCH 1/1 slim: move file revocation into file_table.c and mprotect.c
Here is a attempt at resolving some of the complaints against the slim security module. The file revocation is perceived as too intrusive to live in a security module itself, so it is moved into file_table.c.
This patch retains the explicit file->f_mode tweaking to revoke FMODE_WRITE. That can be removed by using an approach like Pekka's revokefs, using files in the revokefs filesystem with ->read() passed through to the original file, but ->write() intercepted.
Comments greatly appreciated.
thanks,
-serge
From: "Serge E. Hallyn" <[email protected]>
Subject: [PATCH] slim: move file revocation into file_table.c and mprotect.c
Move the file revocation code out of slim. This first verison is very limited:
1. if any aio is pending, we deny the action rather than demote
2. if there are any threads, then deny the action
We should be able to switch to only denying the action if there are write aio's, and perhaps even to the target file.
Supporting threads will take more work:
1. we need to be able to pull the other threads sharing the mm_struct off the runqueue
(if any of the threads are currently running on a cpu, we must return -EAGAIN)
2. we need to check whether any of the threads are sleeping in a write syscall
3. need to check for pending aio in all the threads
4. then do revocation for all the threads
Changelog:
Feb 1: Incorporate bugfix comments from Mimi
Feb 1: Fix sleep under spinlock problem - drop cur_tsec->lock
around call to fd_revoke_write_iter.
(cherry picked from f45727a9ba555802b6f85c198e5c77c3c210b1fc commit)
---
fs/file_table.c | 77 ++++++++++++ include/linux/fs.h | 2 include/linux/mm.h | 2 include/linux/sched.h | 11 ++ mm/mprotect.c | 49 +++++++ security/slim/slm_main.c | 308 +++++++++++----------------------------------- 6 files changed, 212 insertions(+), 237 deletions(-)
35132187f8ff3475b31f4789ecbaa2416ec29e82
fs/file_table.c +77 -0
@@ -265,6 +265,83 @@ void file_kill(struct file *file) } } +/* +* Called with both task_lock and files_lock held. +* +* if f_mode tweaking is not acceptable, we'll have to switch +* to making use of Pekka's revokefs. +*/ +static void __fd_revoke_write_locked (struct file *file) +{ + file->f_mode &= ~FMODE_WRITE ; +put_write_access (file->f_dentry->d_inode); +} + +extern void mm_revoke_mmap_write (int (*need_revoke)(struct inode *,void *), +void *l); + +/* +* Currently, bail if there is >1 thread +* Later, the idea is to +* for each thread +* if on a cpu, bail and return -EAGAIN +* else pull off runqueue +* if in write syscall, bail and return -EAGAIN +* for each thread +* revoke files if need_revoke() +* for each thread +* put back on runqueue +*/ +int fd_revoke_write_iter (int (*need_revoke)(struct inode *,void *), +void *l) +{ +struct files_struct *files = current->files; +struct fdtable *fdt; +unsigned long fd =0 ; +struct file *file; +int num_revoked =0 ; +int ret =0 ; + +if (!files) +return 0 ; + +if (!thread_group_empty (current)) +return -EAGAIN ; + +if (has_pending_aio_writes (current->active_mm)) +return -EPERM ; + +/* here's where we would pull all threads off the runqueue */ + +/* +* here's wehre we'd check for any thread sleeping during a +* write syscall +*/ + +spin_lock (&files->file_lock); + fdt =files_fdtable (files); +while ((fd =find_next_bit (fdt->open_fds->fds_bits, + fdt->max_fds, fd)) < fdt->max_fds) { +struct inode *inode; + + file = fdt->fd[fd++]; +if (!file) +continue ; +if (!(file->f_mode &FMODE_WRITE )) +continue ; +if (!(inode = file->f_dentry->d_inode)) +continue ; +if (!need_revoke (inode, l)) +continue ; +__fd_revoke_write_locked (file); + num_revoked++; + } +spin_unlock (&files->file_lock); +mm_revoke_mmap_write (need_revoke, l); + +return ret; +} +int fs_may_remount_ro (struct super_block *sb) {struct list_head *p;
include/linux/fs.h +2 -0
@@ -1597,6 +1597,8 @@ extern const struct file_operations readextern const struct file_operations write_fifo_fops;extern const struct file_operations rdwr_fifo_fops; +extern int fd_revoke_write_iter (int (*need_revoke)(struct inode *,void *), +void *l);extern int fs_may_remount_ro (struct super_block *);#ifdef CONFIG_BLOCK
include/linux/mm.h +2 -0
@@ -141,6 +141,8 @@ extern unsigned int kobjsize(const void#define VM_EXEC 0x00000004#define VM_SHARED 0x00000008 +extern void mm_revoke_mmap_write (int (*need_revoke)(struct inode *,void *), +void *l);extern int do_mprotect (unsigned long start,size_t len,unsigned long prot);/* mprotect() hardcodes VM_MAYREAD >> 4 == VM_READ, and so for r/w/x bits. */
include/linux/sched.h +11 -0
@@ -381,6 +381,17 @@ struct mm_struct {struct kioctx *ioctx_list; }; +static inline int has_pending_aio_writes (struct mm_struct *mm) +{ +int ret =0 ; + +read_lock (&mm->ioctx_list_lock); +if (mm->ioctx_list !=NULL ) + ret =1 ; +read_unlock (&mm->ioctx_list_lock); +return 0 ; +} +struct sighand_struct {atomic_t count;struct k_sigaction action[_NSIG];
mm/mprotect.c +49 -0
55 lines not on this page · raw message
security/slim/slm_main.c +71 -237
361 lines not on this page · raw message
Signature · 3 lines
1.1.6 ----- End forwarded message -----
[email protected] wrote on 02/20/2007 11:58:24 AM:
Quoted 11 lines
Here is a attempt at resolving some of the complaints against the slim security module. The file revocation is perceived as too intrusive to live in a security module itself, so it is moved into
file_table.c.This patch retains the explicit
file->f_modetweaking to revokeFMODE_WRITE. That can be removed by using an approach like Pekka's revokefs, using files in the revokefs filesystem with ->read() passed through to the original file, but ->write() intercepted.Comments greatly appreciated.
I've tested the patch with slim. The patch has been up and running on my system for a couple of weeks now, and it seems to be working just fine. Is the approach acceptable? On the assumption that it is, how should we go forward with it? Can it get a test run in -mm? If not, what would be a more acceptable approach?
Thanks!
Mimi Zohar