Introduce credential record
Subsystems (63)
David Howells
maintainercover Introduce credential record
Hi Al, Christoph, Trond, Stephen, Casey,
Here's a set of patches that implement a very basic set of COW credentials. It compiles, links and runs for x86_64 with EXT3, (V)FAT, NFS, AFS, SELinux and keyrings all enabled. I've included a patch that should make most of the other archs and filesystems work, but I haven't yet merged it into the primary patches.
A tarball of the patches can be retrieved from:
http://people.redhat.com/~dhowells/nfs/nfs+fscache-24.tar.bz2
The cred struct contains the credentials that the kernel needs to act upon something or to create something. Credentials that govern how a task may be acted upon remain in the task struct.
In essence, the introduction of the cred struct separates a task's subjective context (the authority with which it acts) from its objective context (the authorisation required by others that want to act upon it), and permits overriding of the subjective context by a kernel service so that the service can act on the task's behalf to do something the task couldn't do on its own authority.
Because keyrings and effective capabilities can be installed or changed in one process by another process, they are shadowed by the cred structure rather than residing there. Additionally, the session and process keyrings are shared between all the threads of a process. The shadowing is performed by update_current_cred() which is invoked on entry to any system call that might need it.
A thread's cred struct may be read by that thread without any RCU precautions as only that thread may replace the its own cred struct. To change a thread's credentials, dup_cred() should be called to create a new copy, the copy should be changed, and then set_current_cred() should be called to make it live. Once live, it may not be changed as it may then be shared with file descriptors, RPC calls and other threads. RCU will be used to dispose of the old structure.
The six patches are:
(1) Introduce struct cred and migrate fsuid, fsgid, the groups list and the keyrings pointer to it.
(2) Introduce a security pointer into the cred struct and add LSM hooks to duplicate the information pointed to thereby and to free it.
Make SELinux implement the hooks, splitting out some the task security data to be associated with struct cred instead.
(3) Make the security functions that permit task SID retrieval return both the objective and subjective SIDs as required.
(4) Migrate the effective capabilities mask into the cred struct.
(5) Fix up all the other archs and filesystems that I can manage to compile. This should be merged into the preceding patches at some point.
(6) Provide a pair of LSM hooks so that a kernel service can (a) get a credential record representing the authority with which it is permitted to act, and (b) alter the file creation context in a credential record.
In addition, as this works with cachefiles, I've included all the FS-Cache, CacheFiles, NFS and AFS patches.
To substitute a temporary set of credentials, the cred struct attached to the task should be altered, like so:
int get_privileged_creds(...)
{
/* get special privileged creds */
my_special_cred = get_kernel_cred("cachefiles", current);
change_create_files_as(my_special_cred, my_cache_dir);
}
int do_stuff(...)
{
struct cred *cred;
/* rotate in the new creds, saving the old */
cred = __set_current_cred(get_cred(my_special_cred));
do_privileged_stuff();
/* restore the old creds */
set_current_cred(cred);
}One thing I'm not certain about is how this should interact with /proc, which can display some of the stuff in the cred struct. I think it may be necessary to have a real cred pointer and an effective cred pointer, with the contents of /proc coming from the real, but the effective governing what actually goes on.
Furthemore, I was thinking that it was a good idea to move the setting of i_uid and i_gid to current->cred->i_[ug]id into new_inode(), but now I'm not so sure, since the kernel special filesystems may assume that the i_uid and i_gid default to 0. Any thoughts on this?
The NFS FS-Cache sharing patch still needs fixing up to correctly do the sharing thing when local caching is enabled.
David
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 1/24 CRED: Introduce a COW credentials record
Introduce a copy on write credentials record (struct cred). The fsuid, fsgid, supplementary groups list move into it (DAC security). The session, process and thread keyrings are reflected in it, but don't primarily reside there as they aren't per-thread and occasionally need to be instantiated or replaced by other threads or processes.
The LSM security information (MAC security) does *not* migrate from task_struct at this point, but will be addressed by a later patch.
task_struct then gains an RCU-governed pointer to the credentials as a replacement to the members it lost.
struct file gains a pointer to (f_cred) and a reference on the cred struct that the opener was using at the time the file was opened. This replaces f_uid and f_gid.
To alter the credentials record, a copy must be made. This copy may then be altered and then the pointer in the task_struct redirected to it. From that point on the new record should be considered immutable.
In addition, the default setting of i_uid and i_gid to fsuid and fsgid has been moved from the callers of new_inode() into new_inode() itself.
---
arch/x86_64/kernel/sys_x86_64.c | 4 + fs/aio.c | 25 +++++ fs/anon_inodes.c | 2 fs/attr.c | 4 - fs/compat.c | 65 +++++++++++++ fs/compat_ioctl.c | 7 + fs/dcookies.c | 12 ++ fs/devpts/inode.c | 6 + fs/dquot.c | 2 fs/eventfd.c | 4 + fs/eventpoll.c | 16 +++ fs/exec.c | 37 ++++++-- fs/ext3/balloc.c | 2 fs/ext3/ialloc.c | 4 - fs/fcntl.c | 11 ++ fs/file_table.c | 3 - fs/filesystems.c | 7 + fs/inode.c | 6 + fs/inotify_user.c | 12 ++ fs/ioctl.c | 7 + fs/locks.c | 6 + fs/namei.c | 48 ++++++++-- fs/namespace.c | 12 ++ fs/nfs/inode.c | 2 fs/nfsctl.c | 4 + fs/open.c | 103 ++++++++++++++++++++- fs/pipe.c | 2 fs/posix_acl.c | 4 - fs/proc/array.c | 12 +- fs/quota.c | 4 + fs/ramfs/inode.c | 2 fs/read_write.c | 54 ++++++++++- fs/readdir.c | 8 ++ fs/select.c | 4 + fs/signalfd.c | 4 + fs/splice.c | 12 ++ fs/stat.c | 19 ++++ fs/super.c | 4 + fs/sync.c | 11 ++ fs/timerfd.c | 4 + fs/utimes.c | 4 + fs/xattr.c | 60 ++++++++++++ fs/xfs/linux-2.6/xfs_cred.h | 4 - include/linux/binfmts.h | 1 include/linux/cred.h | 174 ++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 5 + include/linux/init_task.h | 4 - include/linux/sched.h | 7 + include/linux/sunrpc/auth.h | 18 +--- kernel/Makefile | 2 kernel/auditsc.c | 13 ++- kernel/cred.c | 183 ++++++++++++++++++++++++++++++++++++++ kernel/exit.c | 1 kernel/fork.c | 63 ++++++++++++- kernel/kernel-int.h | 15 +++ kernel/sys.c | 144 ++++++++++++++++++++++-------- kernel/uid16.c | 7 + mm/fadvise.c | 4 + mm/filemap.c | 4 + mm/fremap.c | 7 + mm/madvise.c | 7 + mm/msync.c | 7 + mm/shmem.c | 6 - net/socket.c | 2 net/sunrpc/auth.c | 25 +---- net/sunrpc/auth_gss/auth_gss.c | 6 + net/sunrpc/auth_null.c | 4 - net/sunrpc/auth_unix.c | 6 + security/dummy.c | 13 ++- security/keys/compat.c | 6 + security/keys/key.c | 3 - security/keys/keyctl.c | 16 +++ security/keys/permission.c | 16 ++- security/keys/process_keys.c | 58 ++++-------- security/keys/request_key.c | 14 +-- security/keys/request_key_auth.c | 2 76 files changed, 1214 insertions(+), 252 deletions(-)
arch/x86_64/kernel/sys_x86_64.c +4 -0
@@ -43,6 +43,10 @@ asmlinkage long sys_mmap(unsigned long addr, unsigned long len, unsigned long prlong error;struct file * file; + error =update_current_cred (); +if (error <0 ) +return error; + error = -EINVAL ;if (off & ~PAGE_MASK ) goto out;
fs/aio.c +24 -1
@@ -1249,6 +1249,10 @@ asmlinkage long sys_io_setup(unsigned nr_events, aio_context_t __user *ctxp)unsigned long ctx;long ret; + ret =update_current_cred (); +if (ret <0 ) + goto out; + ret =get_user (ctx, ctxp);if (unlikely (ret)) goto out;
@@ -1284,6 +1288,12 @@ out:asmlinkage long sys_io_destroy (aio_context_t ctx) {struct kioctx *ioctx =lookup_ioctx (ctx); +int ret; + + ret =update_current_cred (); +if (ret <0 ) +return ret;; +if (likely (NULL != ioctx)) {io_destroy (ioctx);return 0 ;
@@ -1634,6 +1644,10 @@ asmlinkage long sys_io_submit(aio_context_t ctx_id, long nr,long ret =0 ;int i; + ret =update_current_cred (); +if (ret <0 ) +return ret;; +if (unlikely (nr <0 ))return -EINVAL ;
@@ -1711,6 +1725,10 @@ asmlinkage long sys_io_cancel(aio_context_t ctx_id, struct iocb __user *iocb,u32 key;int ret; + ret =update_current_cred (); +if (ret <0 ) +return ret;; + ret =get_user (key, &iocb->aio_key);if (unlikely (ret))return -EFAULT ;
@@ -1771,8 +1789,13 @@ asmlinkage long sys_io_getevents(aio_context_t ctx_id, struct timespec __user *timeout) {struct kioctx *ioctx =lookup_ioctx (ctx_id); -long ret = -EINVAL ; +long ret; + ret =update_current_cred (); +if (ret <0 ) +return ret; + + ret = -EINVAL ;if (likely (ioctx)) {if (likely (min_nr <= nr && min_nr >=0 && nr >=0 )) ret =read_events (ioctx, min_nr, nr, events, timeout);
fs/anon_inodes.c +0 -2
@@ -163,8 +163,6 @@ static struct inode *anon_inode_mkinode(void)*/ inode->i_state =I_DIRTY ; inode->i_mode =S_IRUSR |S_IWUSR ; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;return inode; }
fs/attr.c +2 -2
@@ -29,13 +29,13 @@ int inode_change_ok(struct inode *inode, struct iattr *attr)/* Make sure a caller can chown. */ if ((ia_valid &ATTR_UID ) && - (current->fsuid != inode->i_uid || + (current->cred->uid != inode->i_uid || attr->ia_uid != inode->i_uid) && !capable (CAP_CHOWN )) goto error;/* Make sure caller can chgrp. */ if ((ia_valid &ATTR_GID ) && - (current->fsuid != inode->i_uid || + (current->cred->uid != inode->i_uid || (!in_group_p (attr->ia_gid) && attr->ia_gid != inode->i_gid)) && !capable (CAP_CHOWN )) goto error;
fs/compat.c +62 -3
154 lines not on this page · raw message
fs/compat_ioctl.c +6 -1
@@ -3567,10 +3567,15 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) {struct file *filp; -int error = -EBADF ; +int error;struct ioctl_trans *t;int fput_needed; + error =update_current_cred (); +if (error <0 ) + goto out; + + error = -EBADF ; filp =fget_light (fd, &fput_needed);if (!filp) goto out;
fs/dcookies.c +8 -4
@@ -24,6 +24,7 @@#include <linux/errno.h> #include <linux/dcookies.h> #include <linux/mutex.h> +#include <linux/cred.h> #include <asm/uaccess.h> /* The dcookies are allocated from a kmem_cache and
@@ -146,12 +147,16 @@ out:asmlinkage long sys_lookup_dcookie (u64 cookie64,char __user * buf,size_t len) {unsigned long cookie = (unsigned long )cookie64; -int err = -EINVAL ; +int err;char * kbuf;char * path;size_t pathlen;struct dcookie_struct * dcs; + err =update_current_cred (); +if (err <0 ) +return err; +/* we could leak path information to users * without dir read permission without this */
@@ -160,10 +165,9 @@ asmlinkage long sys_lookup_dcookie(u64 cookie64, char __user * buf, size_t len)mutex_lock (&dcookie_mutex); -if (!is_live ()) { - err = -EINVAL ; + err = -EINVAL ; +if (!is_live ()) goto out; - }if (!(dcs =find_dcookie (cookie))) goto out;
fs/devpts/inode.c +4 -2
@@ -172,8 +172,10 @@ int devpts_pty_new(struct tty_struct *tty)return -ENOMEM ; inode->i_ino = number+2 ; - inode->i_uid = config.setuid ? config.uid : current->fsuid; - inode->i_gid = config.setgid ? config.gid : current->fsgid; +if (config.setuid) + inode->i_uid = config.uid; +if (config.setgid) + inode->i_gid = config.gid; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME ;init_special_inode (inode,S_IFCHR |config.mode, device); inode->i_private = tty;
fs/dquot.c +1 -1
@@ -832,7 +832,7 @@ static inline int need_print_warning(struct dquot *dquot)switch (dquot->dq_type) {case USRQUOTA : -return current->fsuid == dquot->dq_id; +return current->cred->uid == dquot->dq_id;case GRPQUOTA :return in_group_p (dquot->dq_id); }
fs/eventfd.c +4 -0
@@ -204,6 +204,10 @@ asmlinkage long sys_eventfd(unsigned int count)struct file *file;struct inode *inode; + error =update_current_cred (); +if (error <0 ) +return error; + ctx =kmalloc (sizeof (*ctx),GFP_KERNEL );if (!ctx)return -ENOMEM ;
fs/eventpoll.c +16 -0
@@ -1081,6 +1081,10 @@ asmlinkage long sys_epoll_create(int size)DNPRINTK (3 , (KERN_INFO "[%p] eventpoll: sys_epoll_create(%d)\n" , current, size)); + error =update_current_cred (); +if (error <0 ) + goto error_return; +/* * Sanity check on the size parameter, and create the internal data * structure ( "struct eventpoll" ).
@@ -1128,6 +1132,10 @@ asmlinkage long sys_epoll_ctl(int epfd, int op, int fd,DNPRINTK (3 , (KERN_INFO "[%p] eventpoll: sys_epoll_ctl(%d, %d, %d, %p)\n" , current, epfd, op, fd, event)); + error =update_current_cred (); +if (error <0 ) + goto error_return; + error = -EFAULT ;if (ep_op_has_event (op) &©_from_user (&epds, event,sizeof (struct epoll_event )))
@@ -1224,6 +1232,10 @@ asmlinkage long sys_epoll_wait(int epfd, struct epoll_event __user *events,DNPRINTK (3 , (KERN_INFO "[%p] eventpoll: sys_epoll_wait(%d, %p, %d, %d)\n" , current, epfd, events, maxevents, timeout)); + error =update_current_cred (); +if (error <0 ) + goto error_return; +/* The maximum number of event must be greater than zero */ if (maxevents <=0 || maxevents >EP_MAX_EVENTS )return -EINVAL ;
@@ -1279,6 +1291,10 @@ asmlinkage long sys_epoll_pwait(int epfd, struct epoll_event __user *events,int error;sigset_t ksigmask, sigsaved; + error =update_current_cred (); +if (error <0 ) +return error; +/* * If the caller wants a certain signal mask to be set during the wait, * we apply it here.
fs/exec.c +31 -6
@@ -130,6 +130,10 @@ asmlinkage long sys_uselib(const char __user * library)struct nameidata nd;int error; + error =update_current_cred (); +if (error <0 ) +return error; + error =__user_path_lookup_open (library,LOOKUP_FOLLOW , &nd,FMODE_READ |FMODE_EXEC );if (error) goto out;
@@ -1137,6 +1141,11 @@ int prepare_binprm(struct linux_binprm *bprm) } } +/* prepare the new credentials */ + bprm->cred =dup_cred (current->cred); +if (!bprm->cred) +return -ENOMEM ; +/* fill in binprm security blob */ retval =security_bprm_set (bprm);if (retval)
@@ -1178,7 +1187,9 @@ void compute_creds(struct linux_binprm *bprm)task_lock (current); unsafe =unsafe_exec (current);security_bprm_apply_creds (bprm, unsafe); +set_current_cred (bprm->cred);task_unlock (current); + bprm->cred =NULL ;security_bprm_post_apply_creds (bprm); }EXPORT_SYMBOL (compute_creds);
@@ -1344,6 +1355,10 @@ int do_execve(char * filename,unsigned long env_p;int retval; + retval =update_current_cred (); +if (retval <0 ) +return retval; + retval = -ENOMEM ; bprm =kzalloc (sizeof (*bprm),GFP_KERNEL );if (!bprm)
@@ -1409,6 +1424,8 @@ out:free_arg_pages (bprm);if (bprm->security)security_bprm_free (bprm); +if (bprm->cred) +put_cred (bprm->cred); out_mm:if (bprm->mm)
@@ -1716,8 +1733,8 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)struct linux_binfmt * binfmt;struct inode * inode;struct file * file; +struct cred *cred;int retval =0 ; -int fsuid = current->fsuid;int flag =0 ;int ispipe =0 ;
@@ -1732,6 +1749,10 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) goto fail; } + cred =dup_cred (current->cred); +if (!cred) + goto fail; +/* * We cannot trust fsuid as being the "true" uid of the * process nor do we know its entire history. We only know it
@@ -1739,13 +1760,13 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)*/ if (get_dumpable (mm) ==2 ) {/* Setuid core dump mode */ flag =O_EXCL ;/* Stop rewrite attacks */ - current->fsuid =0 ;/* Dump root private */ +change_fsuid (cred,0 );/* Dump root private */ }set_dumpable (mm,0 ); retval =coredump_wait (exit_code);if (retval <0 ) - goto fail; + goto fail_cred;/* * Clear any false indication of pending signals that might
@@ -1763,19 +1784,20 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)lock_kernel (); ispipe =format_corename (corename, core_pattern, signr);unlock_kernel (); + cred =__set_current_cred (cred);if (ispipe) {/* SIGPIPE can happen, but it's just never processed */ if (call_usermodehelper_pipe (corename+1 ,NULL ,NULL , &file)) {printk (KERN_INFO "Core dump to %s pipe failed\n" , corename); - goto fail_unlock; + goto fail_restore_cred; } }else file =filp_open (corename,O_CREAT |2 |O_NOFOLLOW |O_LARGEFILE | flag,0600 );if (IS_ERR (file)) - goto fail_unlock; + goto fail_restore_cred; inode = file->f_path.dentry->d_inode;if (inode->i_nlink >1 ) goto close_fail;/* multiple links - don't dump */
@@ -1799,9 +1821,12 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs) current->signal->group_exit_code |=0x80 ; close_fail:filp_close (file,NULL ); +fail_restore_cred: +set_current_cred (cred); fail_unlock: - current->fsuid = fsuid;complete_all (&mm->core_done); +fail_cred: +put_cred (cred); fail:return retval; }
fs/ext3/balloc.c +1 -1
@@ -1360,7 +1360,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi) free_blocks =percpu_counter_read_positive (&sbi->s_freeblocks_counter); root_blocks =le32_to_cpu (sbi->s_es->s_r_blocks_count);if (free_blocks < root_blocks +1 && !capable (CAP_SYS_RESOURCE ) && - sbi->s_resuid != current->fsuid && + sbi->s_resuid != current->cred->uid && (sbi->s_resgid ==0 || !in_group_p (sbi->s_resgid))) {return 0 ; }
fs/ext3/ialloc.c +1 -3
@@ -546,15 +546,13 @@ got:percpu_counter_inc (&sbi->s_dirs_counter); sb->s_dirt =1 ; - inode->i_uid = current->fsuid;if (test_opt (sb,GRPID )) inode->i_gid = dir->i_gid;else if (dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; - }else - inode->i_gid = current->fsgid; + } inode->i_mode = mode; inode->i_ino = ino;
fs/fcntl.c +10 -1
@@ -385,8 +385,13 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,asmlinkage long sys_fcntl (unsigned int fd,unsigned int cmd,unsigned long arg) {struct file *filp; -long err = -EBADF ; +long err; + + err =update_current_cred (); +if (err <0 ) +return err; + err = -EBADF ; filp =fget (fd);if (!filp) goto out;
@@ -410,6 +415,10 @@ asmlinkage long sys_fcntl64(unsigned int fd, unsigned int cmd, unsigned long argstruct file * filp;long err; + err =update_current_cred (); +if (err <0 ) +return err; + err = -EBADF ; filp =fget (fd);if (!filp)
fs/file_table.c +1 -2
@@ -115,8 +115,7 @@ struct file *get_empty_filp(void)INIT_LIST_HEAD (&f->f_u.fu_list);atomic_set (&f->f_count,1 );rwlock_init (&f->f_owner.lock); - f->f_uid = tsk->fsuid; - f->f_gid = tsk->fsgid; + f->f_cred =get_current_cred ();eventpoll_init_file (f);/* f->f_version: 0 */ return f;
fs/filesystems.c +6 -1
@@ -179,8 +179,13 @@ static int fs_maxindex(void)*/ asmlinkage long sys_sysfs (int option,unsigned long arg1,unsigned long arg2) { -int retval = -EINVAL ; +int retval; + retval =update_current_cred (); +if (retval <0 ) +return retval; + + retval = -EINVAL ;switch (option) {case 1 : retval =fs_index ((const char __user *) arg1);
fs/inode.c +6 -0
@@ -531,6 +531,10 @@ repeat:* mapping_set_gfp_mask() must be called with suitable flags on the * newly created inode's mapping * +* The inode's user and group IDs are set to the current task's fsuid and +* fsgid respectively as a default, but this should be overridden by the +* caller as appropriate. +* */ struct inode *new_inode (struct super_block *sb) {
@@ -553,6 +557,8 @@ struct inode *new_inode(struct super_block *sb) inode->i_ino = ++last_ino; inode->i_state =0 ;spin_unlock (&inode_lock); + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; }return inode; }
fs/inotify_user.c +12 -0
@@ -547,6 +547,10 @@ asmlinkage long sys_inotify_init(void)struct file *filp;int fd, ret; + ret =update_current_cred (); +if (ret <0 ) +return ret; + fd =get_unused_fd ();if (fd <0 )return fd;
@@ -619,6 +623,10 @@ asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)int ret, fput_needed;unsigned flags =0 ; + ret =update_current_cred (); +if (ret <0 ) +return ret; + filp =fget_light (fd, &fput_needed);if (unlikely (!filp))return -EBADF ;
@@ -660,6 +668,10 @@ asmlinkage long sys_inotify_rm_watch(int fd, u32 wd)struct inotify_device *dev;int ret, fput_needed; + ret =update_current_cred (); +if (ret <0 ) +return ret; + filp =fget_light (fd, &fput_needed);if (unlikely (!filp))return -EBADF ;
fs/ioctl.c +6 -1
@@ -157,9 +157,14 @@ int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned lonasmlinkage long sys_ioctl (unsigned int fd,unsigned int cmd,unsigned long arg) {struct file * filp; -int error = -EBADF ; +int error;int fput_needed; + error =update_current_cred (); +if (error <0 ) + goto out; + + error = -EBADF ; filp =fget_light (fd, &fput_needed);if (!filp) goto out;
fs/locks.c +5 -1
@@ -1341,7 +1341,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)struct inode *inode = dentry->d_inode;int error, rdlease_count =0 , wrlease_count =0 ; -if ((current->fsuid != inode->i_uid) && !capable (CAP_LEASE )) +if ((current->cred->uid != inode->i_uid) && !capable (CAP_LEASE ))return -EACCES ;if (!S_ISREG (inode->i_mode))return -EINVAL ;
@@ -1559,6 +1559,10 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)int can_sleep, unlock;int error; + error =update_current_cred (); +if (error <0 ) +return error; + error = -EBADF ; filp =fget (fd);if (!filp)
fs/namei.c +38 -10
136 lines not on this page · raw message
fs/namespace.c +12 -0
@@ -633,6 +633,10 @@ asmlinkage long sys_umount(char __user * name, int flags)struct nameidata nd;int retval; + retval =update_current_cred (); +if (retval <0 ) + goto out; + retval =__user_walk (name,LOOKUP_FOLLOW , &nd);if (retval) goto out;
@@ -1537,6 +1541,10 @@ asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,unsigned long dev_page;char *dir_page; + retval =update_current_cred (); +if (retval <0 ) +return retval; + retval =copy_mount_options (type, &type_page);if (retval <0 )return retval;
@@ -1670,6 +1678,10 @@ asmlinkage long sys_pivot_root(const char __user * new_root,struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd;int error; + error =update_current_cred (); +if (error <0 ) +return error; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
fs/nfs/inode.c +0 -2
@@ -285,8 +285,6 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) nfsi->change_attr = fattr->change_attr; inode->i_size =nfs_size_to_loff_t (fattr->size); inode->i_nlink = fattr->nlink; - inode->i_uid = fattr->uid; - inode->i_gid = fattr->gid;if (fattr->valid & (NFS_ATTR_FATTR_V3 |NFS_ATTR_FATTR_V4 )) {/* * report the blocks in 512byte units
fs/nfsctl.c +4 -0
@@ -90,6 +90,10 @@ asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *rint version;int err; + err =update_current_cred (); +if (err <0 ) +return err; +if (copy_from_user (&version, &arg->ca_version,sizeof (int )))return -EFAULT ;
fs/open.c +94 -9
241 lines not on this page · raw message
fs/pipe.c +0 -2
@@ -939,8 +939,6 @@ static struct inode * get_pipe_inode(void)*/ inode->i_state =I_DIRTY ; inode->i_mode =S_IFIFO |S_IRUSR |S_IWUSR ; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;return inode;
fs/posix_acl.c +2 -2
@@ -217,11 +217,11 @@ posix_acl_permission(struct inode *inode, const struct posix_acl *acl, int want)switch (pa->e_tag) {case ACL_USER_OBJ :/* (May have been checked already) */ -if (inode->i_uid == current->fsuid) +if (inode->i_uid == current->cred->uid) goto check_perm;break ;case ACL_USER : -if (pa->e_id == current->fsuid) +if (pa->e_id == current->cred->uid) goto mask;break ;case ACL_GROUP_OBJ :
fs/proc/array.c +6 -6
@@ -159,10 +159,12 @@ static inline const char *get_task_state(struct task_struct *tsk)static inline char *task_state (struct task_struct *p,char *buffer) {struct group_info *group_info; +struct cred *cred;int g;struct fdtable *fdt =NULL ;rcu_read_lock (); + cred =get_task_cred (p); buffer +=sprintf (buffer,"State:\t%s\n" "Tgid:\t%d\n"
@@ -175,8 +177,8 @@ static inline char *task_state(struct task_struct *p, char *buffer) p->tgid, p->pid,pid_alive (p) ?rcu_dereference (p->real_parent)->tgid :0 ,pid_alive (p) && p->ptrace ?rcu_dereference (p->parent)->pid :0 , - p->uid, p->euid, p->suid, p->fsuid, - p->gid, p->egid, p->sgid, p->fsgid); + p->uid, p->euid, p->suid, cred->uid, + p->gid, p->egid, p->sgid, cred->gid);task_lock (p);if (p->files)
@@ -186,14 +188,12 @@ static inline char *task_state(struct task_struct *p, char *buffer)"Groups:\t" , fdt ? fdt->max_fds : 0);rcu_read_unlock (); - - group_info = p->group_info; -get_group_info (group_info);task_unlock (p); + group_info = cred->group_info;for (g =0 ; g <min (group_info->ngroups,NGROUPS_SMALL ); g++) buffer +=sprintf (buffer,"%d " ,GROUP_AT (group_info, g)); -put_group_info (group_info); +put_cred (cred); buffer +=sprintf (buffer,"\n" );return buffer;
fs/quota.c +4 -0
@@ -369,6 +369,10 @@ asmlinkage long sys_quotactl(unsigned int cmd, const char __user *special, qid_tstruct super_block *sb =NULL ;int ret; + ret =update_current_cred (); +if (ret <0 ) +return ret; + cmds = cmd >>SUBCMDSHIFT ; type = cmd &SUBCMDMASK ;
fs/ramfs/inode.c +0 -2
@@ -55,8 +55,6 @@ struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev)if (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_mapping->a_ops = &ramfs_aops; inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info;
fs/read_write.c +48 -6
126 lines not on this page · raw message
fs/readdir.c +8 -0
@@ -187,6 +187,10 @@ asmlinkage long sys_getdents(unsigned int fd, struct linux_dirent __user * direnstruct getdents_callback buf;int error; + error =update_current_cred (); +if (error <0 ) + goto out; + error = -EFAULT ;if (!access_ok (VERIFY_WRITE , dirent, count)) goto out;
@@ -271,6 +275,10 @@ asmlinkage long sys_getdents64(unsigned int fd, struct linux_dirent64 __user * dstruct getdents_callback64 buf;int error; + error =update_current_cred (); +if (error <0 ) + goto out; + error = -EFAULT ;if (!access_ok (VERIFY_WRITE , dirent, count)) goto out;
fs/select.c +4 -0
@@ -661,6 +661,10 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds, s64 *timeout)long stack_pps[POLL_STACK_ALLOC /sizeof (long )];struct poll_list *stack_pp =NULL ; + err =update_current_cred (); +if (err <0 ) +return err; +/* Do a sanity check on nfds ... */ if (nfds > current->signal->rlim[RLIMIT_NOFILE ].rlim_cur)return -EINVAL ;
fs/signalfd.c +4 -0
@@ -207,6 +207,10 @@ asmlinkage long sys_signalfd(int ufd, sigset_t __user *user_mask, size_t sizemasstruct file *file;struct inode *inode; + error =update_current_cred (); +if (error <0 ) +return error; +if (sizemask !=sizeof (sigset_t) ||copy_from_user (&sigmask, user_mask,sizeof (sigmask)))return -EINVAL ;
fs/splice.c +12 -0
@@ -1510,6 +1510,10 @@ asmlinkage long sys_vmsplice(int fd, const struct iovec __user *iov,else if (unlikely (!nr_segs))return 0 ; + error =update_current_cred (); +if (error <0 ) +return error; + error = -EBADF ; file =fget_light (fd, &fput);if (file) {
@@ -1535,6 +1539,10 @@ asmlinkage long sys_splice(int fd_in, loff_t __user *off_in,if (unlikely (!len))return 0 ; + error =update_current_cred (); +if (error <0 ) +return error; + error = -EBADF ; in =fget_light (fd_in, &fput_in);if (in) {
@@ -1752,6 +1760,10 @@ asmlinkage long sys_tee(int fdin, int fdout, size_t len, unsigned int flags)if (unlikely (!len))return 0 ; + error =update_current_cred (); +if (error <0 ) +return error; + error = -EBADF ; in =fget_light (fdin, &fput_in);if (in) {
fs/stat.c +18 -1
@@ -60,6 +60,10 @@ int vfs_stat_fd(int dfd, char __user *name, struct kstat *stat)struct nameidata nd;int error; + error =update_current_cred (); +if (error <0 ) +return error; + error =__user_walk_fd (dfd, name,LOOKUP_FOLLOW , &nd);if (!error) { error =vfs_getattr (nd.mnt, nd.dentry, stat);
@@ -80,6 +84,10 @@ int vfs_lstat_fd(int dfd, char __user *name, struct kstat *stat)struct nameidata nd;int error; + error =update_current_cred (); +if (error <0 ) +return error; + error =__user_walk_fd (dfd, name,0 , &nd);if (!error) { error =vfs_getattr (nd.mnt, nd.dentry, stat);
@@ -98,8 +106,13 @@ EXPORT_SYMBOL(vfs_lstat);int vfs_fstat (unsigned int fd,struct kstat *stat) {struct file *f =fget (fd); -int error = -EBADF ; +int error; + error =update_current_cred (); +if (error <0 ) +return error; + + error = -EBADF ;if (f) { error =vfs_getattr (f->f_path.mnt, f->f_path.dentry, stat);fput (f);
@@ -300,6 +313,10 @@ asmlinkage long sys_readlinkat(int dfd, const char __user *path,if (bufsiz <=0 )return -EINVAL ; + error =update_current_cred (); +if (error <0 ) +return error; + error =__user_walk_fd (dfd, path,0 , &nd);if (!error) {struct inode * inode = nd.dentry->d_inode;
fs/super.c +4 -0
@@ -540,6 +540,10 @@ asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf)struct kstatfs sbuf;int err = -EINVAL ; + err =update_current_cred (); +if (err <0 ) +return err; + s =user_get_super (new_decode_dev (dev));if (s ==NULL ) goto out;
fs/sync.c +10 -1
@@ -108,8 +108,13 @@ out:static long __do_fsync (unsigned int fd,int datasync) {struct file *file; -int ret = -EBADF ; +int ret; + + ret =update_current_cred (); +if (ret <0 ) +return ret; + ret = -EBADF ; file =fget (fd);if (file) { ret =do_fsync (file, datasync);
@@ -183,6 +188,10 @@ asmlinkage long sys_sync_file_range(int fd, loff_t offset, loff_t nbytes,int fput_needed;umode_t i_mode; + ret =update_current_cred (); +if (ret <0 ) + goto out; + ret = -EINVAL ;if (flags & ~VALID_FLAGS ) goto out;
fs/timerfd.c +4 -0
@@ -159,6 +159,10 @@ asmlinkage long sys_timerfd(int ufd, int clockid, int flags,struct inode *inode;struct itimerspec ktmr; + error =update_current_cred (); +if (error <0 ) +return error; +if (copy_from_user (&ktmr, utmr,sizeof (ktmr)))return -EFAULT ;
fs/utimes.c +4 -0
@@ -51,6 +51,10 @@ long do_utimes(int dfd, char __user *filename, struct timespec *times, int flagsstruct iattr newattrs;struct file *f =NULL ; + error =update_current_cred (); +if (error <0 ) + goto out; + error = -EINVAL ;if (flags & ~AT_SYMLINK_NOFOLLOW ) goto out;
fs/xattr.c +56 -4
136 lines not on this page · raw message
fs/xfs/linux-2.6/xfs_cred.h +1 -3
@@ -23,9 +23,7 @@/* * Credentials */ -typedef struct cred { -/* EMPTY */ -}cred_t ; +typedef struct cred cred_t ;extern struct cred *sys_cred;
include/linux/binfmts.h +1 -0
@@ -39,6 +39,7 @@ struct linux_binprm{int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective;void *security; +struct cred *cred;int argc, envc;char * filename;/* Name of binary as seen by procps */ char * interp;/* Name of the binary really executed. Most
include/linux/cred.h new file +174 -0
174 lines not on this page · raw message
include/linux/fs.h +3 -2
@@ -285,6 +285,7 @@ extern int dir_notify_enable;#include <linux/mutex.h> #include <linux/sysctl.h> #include <linux/capability.h> +#include <linux/cred.h> #include <asm/atomic.h> #include <asm/semaphore.h>
@@ -736,7 +737,7 @@ struct file {mode_t f_mode;loff_t f_pos;struct fown_struct f_owner; -unsigned int f_uid, f_gid; +struct cred *f_cred;struct file_ra_state f_ra;unsigned long f_version;
@@ -999,7 +1000,7 @@ enum {#define has_fs_excl () atomic_read(¤t->fs_excl)#define is_owner_or_cap (inode) \ - ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER)) + ((current->cred->uid == (inode)->i_uid) || capable(CAP_FOWNER))/* not quite ready to be deprecated, but... */ extern void lock_super (struct super_block *);
include/linux/init_task.h +1 -3
@@ -89,8 +89,6 @@ extern struct nsproxy init_nsproxy; .signalfd_wqh = __WAIT_QUEUE_HEAD_INITIALIZER(sighand.signalfd_wqh), \ } -extern struct group_info init_groups; -#define INIT_STRUCT_PID { \ .count = ATOMIC_INIT(1), \ .nr = 0, \
@@ -142,7 +140,7 @@ extern struct group_info init_groups; .children = LIST_HEAD_INIT(tsk.children), \ .sibling = LIST_HEAD_INIT(tsk.sibling), \ .group_leader = &tsk, \ - .group_info = &init_groups, \ + .cred = &init_cred, \ .cap_effective = CAP_INIT_EFF_SET, \ .cap_inheritable = CAP_INIT_INH_SET, \ .cap_permitted = CAP_FULL_SET, \
include/linux/sched.h +4 -3
@@ -79,6 +79,7 @@ struct sched_param {#include <linux/rcupdate.h> #include <linux/futex.h> #include <linux/rtmutex.h> +#include <linux/cred.h> #include <linux/time.h> #include <linux/param.h>
@@ -1033,9 +1034,9 @@ struct task_struct {struct list_head cpu_timers[3 ];/* process credentials */ -uid_t uid,euid,suid,fsuid; -gid_t gid,egid,sgid,fsgid; -struct group_info *group_info; +struct cred *cred; +uid_t uid,euid,suid; +gid_t gid,egid,sgid;kernel_cap_t cap_effective, cap_inheritable, cap_permitted; unsigned keep_capabilities:1;struct user_struct *user;
include/linux/sunrpc/auth.h +6 -12
@@ -21,13 +21,6 @@/* size of the nodename buffer */ #define UNX_MAXNODENAME 32 -/* Work around the lack of a VFS credential */ -struct auth_cred { -uid_t uid; -gid_t gid; -struct group_info *group_info; -}; -/* * Client user credentials */
@@ -94,6 +87,7 @@ struct rpc_auth {/* * Client authentication ops */ +struct cred ;struct rpc_authops {struct module *owner;rpc_authflavor_t au_flavor;/* flavor (RPC_AUTH_*) */
@@ -103,8 +97,8 @@ struct rpc_authops {struct rpc_auth * (*create)(struct rpc_clnt *,rpc_authflavor_t );void (*destroy)(struct rpc_auth *); -struct rpc_cred * (*lookup_cred)(struct rpc_auth *,struct auth_cred *,int ); -struct rpc_cred * (*crcreate)(struct rpc_auth *,struct auth_cred *,int ); +struct rpc_cred * (*lookup_cred)(struct rpc_auth *,struct cred *,int ); +struct rpc_cred * (*crcreate)(struct rpc_auth *,struct cred *,int ); };struct rpc_credops {
@@ -112,7 +106,7 @@ struct rpc_credops {int (*cr_init)(struct rpc_auth *,struct rpc_cred *);void (*crdestroy)(struct rpc_cred *); -int (*crmatch)(struct auth_cred *,struct rpc_cred *,int ); +int (*crmatch)(struct cred *,struct rpc_cred *,int );__be32 * (*crmarshal)(struct rpc_task *,__be32 *);int (*crrefresh)(struct rpc_task *);__be32 * (*crvalidate)(struct rpc_task *,__be32 *);
@@ -133,8 +127,8 @@ int rpcauth_register(const struct rpc_authops *);int rpcauth_unregister (const struct rpc_authops *);struct rpc_auth *rpcauth_create (rpc_authflavor_t ,struct rpc_clnt *);void rpcauth_release (struct rpc_auth *); -struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct auth_cred *,int ); -void rpcauth_init_cred (struct rpc_cred *,const struct auth_cred *,struct rpc_auth *,const struct rpc_credops *); +struct rpc_cred *rpcauth_lookup_credcache (struct rpc_auth *,struct cred *,int ); +void rpcauth_init_cred (struct rpc_cred *,const struct cred *,struct rpc_auth *,const struct rpc_credops *);struct rpc_cred *rpcauth_lookupcred (struct rpc_auth *,int );struct rpc_cred *rpcauth_bindcred (struct rpc_task *);void rpcauth_holdcred (struct rpc_task *);
kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ rcupdate.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o \ - utsname.o + utsname.o cred.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-y += time/
kernel/auditsc.c +9 -4
@@ -303,7 +303,8 @@ static int audit_filter_rules(struct task_struct *tsk, result =audit_comparator (tsk->suid, f->op, f->val);break ;case AUDIT_FSUID : - result =audit_comparator (tsk->fsuid, f->op, f->val); + result =audit_comparator (task_fsuid (tsk), f->op, + f->val);break ;case AUDIT_GID : result =audit_comparator (tsk->gid, f->op, f->val);
@@ -315,7 +316,8 @@ static int audit_filter_rules(struct task_struct *tsk, result =audit_comparator (tsk->sgid, f->op, f->val);break ;case AUDIT_FSGID : - result =audit_comparator (tsk->fsgid, f->op, f->val); + result =audit_comparator (task_fsgid (tsk), f->op, + f->val);break ;case AUDIT_PERS : result =audit_comparator (tsk->personality, f->op, f->val);
@@ -885,12 +887,15 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts context->gid = tsk->gid; context->euid = tsk->euid; context->suid = tsk->suid; - context->fsuid = tsk->fsuid; context->egid = tsk->egid; context->sgid = tsk->sgid; - context->fsgid = tsk->fsgid; context->personality = tsk->personality; +rcu_read_lock (); + context->fsuid =__task_fsuid (tsk); + context->fsgid =__task_fsgid (tsk); +rcu_read_unlock (); + ab =audit_log_start (context,GFP_KERNEL ,AUDIT_SYSCALL );if (!ab)return ;/* audit_panic has been called */
kernel/cred.c new file +183 -0
183 lines not on this page · raw message
kernel/exit.c +1 -0
@@ -288,6 +288,7 @@ static void reparent_to_kthreadd(void)/* cpus_allowed? */ /* rt_priority? */ /* signals? */ +set_current_cred (get_cred (&init_cred));security_task_reparent_to_init (current);memcpy (current->signal->rlim, init_task.signal->rlim,sizeof (current->signal->rlim));
kernel/fork.c +58 -5
96 lines not on this page · raw message
kernel/kernel-int.h new file +15 -0
@@ -0,0 +1,15 @@ +/* kernel/ internal definitions +* +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +/* +* sys.c +*/ +extern struct group_info init_groups;
kernel/sys.c +104 -40
371 lines not on this page · raw message
kernel/uid16.c +3 -4
@@ -161,25 +161,24 @@ static int groups16_from_user(struct group_info *group_info,asmlinkage long sys_getgroups16 (int gidsetsize,old_gid_t __user *grouplist) { +struct group_info *group_info = current->cred->group_info;int i =0 ;if (gidsetsize <0 )return -EINVAL ; -get_group_info (current->group_info); - i = current->group_info->ngroups; + i = group_info->ngroups;if (gidsetsize) {if (i > gidsetsize) { i = -EINVAL ; goto out; } -if (groups16_to_user (grouplist, current->group_info)) { +if (groups16_to_user (grouplist, group_info)) { i = -EFAULT ; goto out; } } out: -put_group_info (current->group_info);return i; }
mm/fadvise.c +4 -0
@@ -35,6 +35,10 @@ asmlinkage long sys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)unsigned long nrpages;int ret =0 ; + ret =update_current_cred (); +if (ret <0 ) +return ret; +if (!file)return -EBADF ;
mm/filemap.c +4 -0
@@ -1235,6 +1235,10 @@ asmlinkage ssize_t sys_readahead(int fd, loff_t offset, size_t count)ssize_t ret;struct file *file; + ret =update_current_cred (); +if (ret <0 ) +return ret; + ret = -EBADF ; file =fget (fd);if (file) {
mm/fremap.c +6 -1
@@ -122,9 +122,14 @@ asmlinkage long sys_remap_file_pages(unsigned long start, unsigned long size,struct address_space *mapping;unsigned long end = start + size;struct vm_area_struct *vma; -int err = -EINVAL ; +int err;int has_write_lock =0 ; + err =update_current_cred (); +if (err <0 ) +return err; + + err = -EINVAL ;if (__prot)return err;/*
mm/madvise.c +6 -1
@@ -286,10 +286,15 @@ asmlinkage long sys_madvise(unsigned long start, size_t len_in, int behavior)unsigned long end, tmp;struct vm_area_struct * vma, *prev;int unmapped_error =0 ; -int error = -EINVAL ; +int error;int write;size_t len; + error =update_current_cred (); +if (error <0 ) +return error; + + error = -EINVAL ; write =madvise_need_mmap_write (behavior);if (write)down_write (¤t->mm->mmap_sem);
mm/msync.c +6 -1
@@ -34,8 +34,13 @@ asmlinkage long sys_msync(unsigned long start, size_t len, int flags)struct mm_struct *mm = current->mm;struct vm_area_struct *vma;int unmapped_error =0 ; -int error = -EINVAL ; +int error; + error =update_current_cred (); +if (error <0 ) +return error; + + error = -EINVAL ;if (flags & ~(MS_ASYNC |MS_INVALIDATE |MS_SYNC )) goto out;if (start & ~PAGE_MASK )
mm/shmem.c +2 -4
@@ -1394,8 +1394,6 @@ shmem_get_inode(struct super_block *sb, int mode, dev_t dev) inode =new_inode (sb);if (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_mapping->a_ops = &shmem_aops; inode->i_mapping->backing_dev_info = &shmem_backing_dev_info;
@@ -2212,8 +2210,8 @@ static int shmem_fill_super(struct super_block *sb,struct inode *inode;struct dentry *root;int mode =S_IRWXUGO |S_ISVTX ; -uid_t uid = current->fsuid; -gid_t gid = current->fsgid; +uid_t uid = current->cred->uid; +gid_t gid = current->cred->gid;int err = -ENOMEM ;struct shmem_sb_info *sbinfo;unsigned long blocks =0 ;
net/socket.c +0 -2
@@ -483,8 +483,6 @@ static struct socket *sock_alloc(void) sock =SOCKET_I (inode); inode->i_mode =S_IFSOCK |S_IRWXUGO ; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid;get_cpu_var (sockets_in_use)++;put_cpu_var (sockets_in_use);
net/sunrpc/auth.c +4 -21
@@ -267,7 +267,7 @@ rpcauth_cache_shrinker(int nr_to_scan, gfp_t gfp_mask)* Look up a process' credentials in the authentication cache */ struct rpc_cred * -rpcauth_lookup_credcache (struct rpc_auth *auth,struct auth_cred * acred, +rpcauth_lookup_credcache (struct rpc_auth *auth,struct cred *acred,int flags) {LIST_HEAD (free);
@@ -336,23 +336,13 @@ out:struct rpc_cred *rpcauth_lookupcred (struct rpc_auth *auth,int flags) { -struct auth_cred acred = { - .uid = current->fsuid, - .gid = current->fsgid, - .group_info = current->group_info, - }; -struct rpc_cred *ret; -dprintk ("RPC: looking up %s cred\n" , auth->au_ops->au_name); -get_group_info (acred.group_info); - ret = auth->au_ops->lookup_cred (auth, &acred, flags); -put_group_info (acred.group_info); -return ret; +return auth->au_ops->lookup_cred (auth, current->cred, flags); }void -rpcauth_init_cred (struct rpc_cred *cred,const struct auth_cred *acred, +rpcauth_init_cred (struct rpc_cred *cred,const struct cred *acred,struct rpc_auth *auth,const struct rpc_credops *ops) {INIT_HLIST_NODE (&cred->cr_hash);
@@ -372,25 +362,18 @@ struct rpc_cred * rpcauth_bindcred(struct rpc_task *task) {struct rpc_auth *auth = task->tk_client->cl_auth; -struct auth_cred acred = { - .uid = current->fsuid, - .gid = current->fsgid, - .group_info = current->group_info, - };struct rpc_cred *ret;int flags =0 ;dprintk ("RPC: %5u looking up %s cred\n" , task->tk_pid, task->tk_client->cl_auth->au_ops->au_name); -get_group_info (acred.group_info);if (task->tk_flags &RPC_TASK_ROOTCREDS ) flags |=RPCAUTH_LOOKUP_ROOTCREDS ; - ret = auth->au_ops->lookup_cred (auth, &acred, flags); + ret = auth->au_ops->lookup_cred (auth, current->cred, flags);if (!IS_ERR (ret)) task->tk_msg.rpc_cred = ret;else task->tk_status =PTR_ERR (ret); -put_group_info (acred.group_info);return ret; }
net/sunrpc/auth_gss/auth_gss.c +3 -3
@@ -793,13 +793,13 @@ gss_destroy_cred(struct rpc_cred *cred)* Lookup RPCSEC_GSS cred for the current process */ static struct rpc_cred * -gss_lookup_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) +gss_lookup_cred (struct rpc_auth *auth,struct cred *acred,int flags) {return rpcauth_lookup_credcache (auth, acred, flags); }static struct rpc_cred * -gss_create_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) +gss_create_cred (struct rpc_auth *auth,struct cred *acred,int flags) { struct gss_auth *gss_auth = container_of(auth, struct gss_auth, rpc_auth);struct gss_cred *cred =NULL ;
@@ -840,7 +840,7 @@ gss_cred_init(struct rpc_auth *auth, struct rpc_cred *cred) }static int -gss_match (struct auth_cred *acred,struct rpc_cred *rc,int flags) +gss_match (struct cred *acred,struct rpc_cred *rc,int flags) { struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
net/sunrpc/auth_null.c +2 -2
@@ -34,7 +34,7 @@ nul_destroy(struct rpc_auth *auth)* Lookup NULL creds for current process */ static struct rpc_cred * -nul_lookup_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) +nul_lookup_cred (struct rpc_auth *auth,struct cred *acred,int flags) {return get_rpccred (&null_cred); }
@@ -51,7 +51,7 @@ nul_destroy_cred(struct rpc_cred *cred)* Match cred handle against current process */ static int -nul_match (struct auth_cred *acred,struct rpc_cred *cred,int taskflags) +nul_match (struct cred *acred,struct rpc_cred *cred,int taskflags) {return 1 ; }
net/sunrpc/auth_unix.c +3 -3
@@ -51,13 +51,13 @@ unx_destroy(struct rpc_auth *auth)* Lookup AUTH_UNIX creds for current process */ static struct rpc_cred * -unx_lookup_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) +unx_lookup_cred (struct rpc_auth *auth,struct cred *acred,int flags) {return rpcauth_lookup_credcache (auth, acred, flags); }static struct rpc_cred * -unx_create_cred (struct rpc_auth *auth,struct auth_cred *acred,int flags) +unx_create_cred (struct rpc_auth *auth,struct cred *acred,int flags) {struct unx_cred *cred;int i;
@@ -115,7 +115,7 @@ unx_destroy_cred(struct rpc_cred *cred)* request root creds (e.g. for NFS swapping). */ static int -unx_match (struct auth_cred *acred,struct rpc_cred *rcred,int flags) +unx_match (struct cred *acred,struct rpc_cred *rcred,int flags) { struct unx_cred *cred = container_of(rcred, struct unx_cred, uc_base);int i;
security/dummy.c +9 -4
@@ -43,10 +43,12 @@ static int dummy_capget (struct task_struct *target, kernel_cap_t * effective, *permitted |= (~0 & ~CAP_FS_MASK ); *effective |= (~0 & ~CAP_TO_MASK (CAP_SETPCAP ) & ~CAP_FS_MASK ); } -if (target->fsuid ==0 ) { +rcu_read_lock (); +if (task_cred (target)->uid ==0 ) { *permitted |=CAP_FS_MASK ; *effective |=CAP_FS_MASK ; } +rcu_read_unlock (); }return 0 ; }
@@ -138,8 +140,11 @@ static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe) } } - current->suid = current->euid = current->fsuid = bprm->e_uid; - current->sgid = current->egid = current->fsgid = bprm->e_gid; + current->suid = current->euid = bprm->e_uid; + current->sgid = current->egid = bprm->e_gid; + +change_fsuid (bprm->cred, bprm->e_uid); +change_fsgid (bprm->cred, bprm->e_gid);dummy_capget (current, ¤t->cap_effective, ¤t->cap_inheritable, ¤t->cap_permitted); }
@@ -572,7 +577,7 @@ static int dummy_task_prctl (int option, unsigned long arg2, unsigned long arg3,static void dummy_task_reparent_to_init (struct task_struct *p) { - p->euid = p->fsuid =0 ; + p->euid =0 ;return ; }
security/keys/compat.c +6 -0
@@ -25,6 +25,12 @@asmlinkage long compat_sys_keyctl (u32 option,u32 arg2,u32 arg3,u32 arg4,u32 arg5) { +int ret; + + ret =update_current_cred (); +if (ret <0 ) +return ret; +switch (option) {case KEYCTL_GET_KEYRING_ID :return keyctl_get_keyring_ID (arg2, arg3);
security/keys/key.c +2 -1
@@ -817,7 +817,8 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref, perm |=KEY_USR_WRITE ;/* allocate a new key */ - key =key_alloc (ktype, description, current->fsuid, current->fsgid, + key =key_alloc (ktype, description, + current->cred->uid, current->cred->gid, current, perm, flags);if (IS_ERR (key)) { key_ref =ERR_PTR (PTR_ERR (key));
security/keys/keyctl.c +15 -1
@@ -67,6 +67,10 @@ asmlinkage long sys_add_key(const char __user *_type,if (plen >32767 ) goto error; + ret =update_current_cred (); +if (ret <0 ) + goto error; +/* draw all the data into kernel space */ ret =key_get_type_from_user (type, _type,sizeof (type));if (ret <0 )
@@ -143,6 +147,10 @@ asmlinkage long sys_request_key(const char __user *_type,char type[32 ], *description, *callout_info;long ret; + ret =update_current_cred (); +if (ret <0 ) + goto error; +/* pull the type into kernel space */ ret =key_get_type_from_user (type, _type,sizeof (type));if (ret <0 )
@@ -794,7 +802,7 @@ long keyctl_setperm_key(key_serial_t id, key_perm_t perm)down_write (&key->sem);/* if we're not the sysadmin, we can only change a key that we own */ -if (capable (CAP_SYS_ADMIN ) || key->uid == current->fsuid) { +if (capable (CAP_SYS_ADMIN ) || key->uid == current->cred->uid) { key->perm = perm; ret =0 ; }
@@ -1062,6 +1070,12 @@ error:asmlinkage long sys_keyctl (int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5) { +int ret; + + ret =update_current_cred (); +if (ret <0 ) +return ret; +switch (option) {case KEYCTL_GET_KEYRING_ID : return keyctl_get_keyring_ID((key_serial_t) arg2,
security/keys/permission.c +10 -6
@@ -22,14 +22,19 @@ int key_task_permission(const key_ref_t key_ref, struct task_struct *context, key_perm_t perm) { +struct cred *cred;struct key *key;key_perm_t kperm;int ret; +rcu_read_lock (); + cred =get_task_cred (context); +rcu_read_unlock (); + key =key_ref_to_ptr (key_ref);/* use the second 8-bits of permissions for keys the caller owns */ -if (key->uid == context->fsuid) { +if (key->uid == cred->uid) { kperm = key->perm >>16 ; goto use_these_perms; }
@@ -37,15 +42,12 @@ int key_task_permission(const key_ref_t key_ref,/* use the third 8-bits of permissions for keys the caller has a group * membership in common with */ if (key->gid !=-1 && key->perm &KEY_GRP_ALL ) { -if (key->gid == context->fsgid) { +if (key->gid == cred->gid) { kperm = key->perm >>8 ; goto use_these_perms; } -task_lock (context); - ret =groups_search (context->group_info, key->gid); -task_unlock (context); - + ret =groups_search (cred->group_info, key->gid);if (ret) { kperm = key->perm >>8 ; goto use_these_perms;
@@ -56,6 +58,8 @@ int key_task_permission(const key_ref_t key_ref, kperm = key->perm; use_these_perms: +put_cred (cred); +/* use the top 8-bits of permissions for keys the caller possesses * - possessor permissions are additive with other permissions */
security/keys/process_keys.c +18 -40
42 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: [PATCH 01/24] CRED: Introduce a COW credentials record
Quoted 3 lines · David Howells
To alter the credentials record, a copy must be made. This copy may then be altered and then the pointer in the
task_structredirected to it. From that point on the new record should be considered immutable.
Umm... Perhaps a better primitive would be "make sure that our cred is not shared with anybody, creating a copy and redirecting reference to it if needed".
Quoted 2 lines
In addition, the default setting of
i_uidandi_gidto fsuid and fsgid has been moved from the callers ofnew_inode()intonew_inode()itself.
I don't think it's safe; better do something trivial like
own_inode(inode)
that would set these (and that's a goot splitup candidate, to go in front of the series).
FWIW, the main weakness here is the need of update_current_cred() splattered all over the entry points. Two problems:
a) it's a bug source (somebody adds a syscall and forgets to
add that call / somebody modifies syscall guts and doesn't notice that it needs to be added).
b) it's almost always doing noting, so being lazier would be
better (event numbers checked in the inlined part, perhaps?)
The former would be more robust if it had been closer to the places where we get to passing current->cred to functions. The latter... When do we actually step into this kind of situation (somebody changing keys on us) and what's the right semantics here? E.g. if it happens in the middle of long read(), do we want to keep using the original keys?
Comments?
David Howells
maintainerRe: [PATCH 01/24] CRED: Introduce a COW credentials record
Quoted 3 lines · Al Viro
Umm... Perhaps a better primitive would be "make sure that our cred is not shared with anybody, creating a copy and redirecting reference to it if needed".
I wanted to make the point that once a cred record was made live - i.e. exposed to the rest of the system - it should not be changed. I'll think about rewording that. Also "making sure that our cred is not shared" does not work for cachefiles where we actually want to create a new set of creds.
Quoted 7 lines · Al Viro
Quoted 2 lines
In addition, the default setting of
i_uidandi_gidto fsuid and fsgid has been moved from the callers ofnew_inode()intonew_inode()itself.I don't think it's safe; better do something trivial like
own_inode(inode)
that would set these (and that's a goot splitup candidate, to go in front of the series).
I think you're probably right. I commented on this at the bottom of the cover note. One thing I could do is provide a variant on own_inode() that takes a parent dir inode pointer and does the sticky GID thing - something that several filesystems do.
Quoted 2 lines
FWIW, the main weakness here is the need of
update_current_cred()splattered all over the entry points.
Yeah. I'm not keen on that, but I'm even less keen on sticking something in everywhere that the cred struct is consulted. I don't like the idea of making it implicit in the dereference of current->cred either, and neither is Linus.
Quoted 4 lines
Two problems:
a) it's a bug source (somebody adds a syscall and forgets to
add that call / somebody modifies syscall guts and doesn't notice that it needs to be added).
It's simpler to check for its existence at the beginning of a syscall.
Quoted 2 lines
b) it's almost always doing noting, so being lazier would be
better (event numbers checked in the inlined part, perhaps?)
Linus is against having an inlined part:-/
Quoted 2 lines
The former would be more robust if it had been closer to the places where we get to passing
current->credto functions.
You can't do it there because there may be an override in effect. Or, rather, if you do do it there, you have to not do it if there's an override set.
Quoted 2 lines
The latter... When do we actually step into this kind of situation (somebody changing keys on us)
There are four cases:
(1) The request_key() upcall forces us to create a thread keyring.
(2) The request_key() upcall forces us to create a process keyring.
(3) A sibling thread instantiates our common process keyring.
(4) A sibling thread replaces our common session keyring.
The first three could be trivially avoidable by creating the thread and process keyrings in advance, (1) and (2) at request_key() time, (3) at clone time. It eats extra resources, but it's easy.
The fourth is more tricky. A sibling thread can replace our common session keyring on us at any time. I suppose we could decree that you can't replace your session keyring if you've got multiple threads. That ought to be simple enough, and I suspect won't impact particularly.
The alternatives are (b) not to include the keyrings in the cred stuff, though they are relevant; and (c) to make it possible for sibling threads to change each other's creds. I'm really not keen on (c) as that means you can't just dereference your own creds directly without taking locks and stuff.
Quoted 2 lines
and what's the right semantics here? E.g. if it happens
in the middle of longread(), do we want to keep using the original keys?
If you're in the middle of a long read(), you should be using the cred struct attached to file->f_cred, not current->cred, and so that problem should not arise.
As for long ops that aren't I/O operations on file descriptors, I think it's reasonable for you to do the entire op with the creds you started off doing it with.
Don't forget that there's also the cap_effective stuff, which appears that it can be changed by someone other than the target process.
David
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 2/24 CRED: Split the task security data and move part of it into struct cred
In reply to David HowellsMove into the cred struct the part of the task security data that defines how a task acts upon an object. The part that defines how something acts upon a task remains attached to the task.
For SELinux this requires some of task_security_struct to be split off into cred_security_struct which is then attached to struct cred. Note that the contents of cred_security_struct may not be changed without the generation of a new struct cred.
The split is as follows:
(*) create_sid, keycreate_sid and sockcreate_sid just move across.
(*) sid is split into victim_sid - which remains - and action_sid - which
migrates.
(*) osid, exec_sid and ptrace_sid remain.
victim_sid is the SID used to govern actions upon the task. action_sid is used to govern actions made by the task.
When accessing the cred_security_struct of another process, RCU read procedures must be observed.
---
include/linux/cred.h | 1 include/linux/security.h | 33 ++ kernel/cred.c | 7 + security/dummy.c | 11 + security/selinux/exports.c | 6 security/selinux/hooks.c | 497 +++++++++++++++++++++++-------------- security/selinux/include/objsec.h | 16 + security/selinux/selinuxfs.c | 8 - security/selinux/xfrm.c | 6 9 files changed, 379 insertions(+), 206 deletions(-)
include/linux/cred.h +1 -0
@@ -26,6 +26,7 @@ struct cred {gid_t gid;/* fsgid as was */ struct rcu_head exterminate;/* cred destroyer */ struct group_info *group_info; +void *security;/* caches for references to the three task keyrings * - note that key_ref_t isn't typedef'd at this point, hence the odd
include/linux/security.h +33 -0
@@ -504,6 +504,17 @@ struct request_sock;* @file contains the file structure being received. * Return 0 if permission is granted. * +* Security hooks for credential structure operations. +* +* @cred_dup: +* Duplicate the credentials onto a duplicated cred structure. +* @cred points to the credentials structure. cred->security points to the +* security struct that was attached to the original cred struct, but it +* lacks a reference for the duplication if reference counting is needed. +* @cred_destroy: +* Destroy the credentials attached to a cred structure. +* @cred points to the credentials structure that is to be destroyed. +* * Security hooks for task operations. * * @task_create:
@@ -1257,6 +1268,9 @@ struct security_operations { struct fown_struct * fown, int sig);int (*file_receive) (struct file * file); +int (*cred_dup)(struct cred *cred); +void (*cred_destroy)(struct cred *cred); +int (*task_create) (unsigned long clone_flags);int (*task_alloc_security) (struct task_struct * p);void (*task_free_security) (struct task_struct * p);
@@ -1864,6 +1878,16 @@ static inline int security_file_receive (struct file *file)return security_ops->file_receive (file); } +static inline int security_cred_dup (struct cred *cred) +{ +return security_ops->cred_dup (cred); +} + +static inline void security_cred_destroy (struct cred *cred) +{ +return security_ops->cred_destroy (cred); +} +static inline int security_task_create (unsigned long clone_flags) {return security_ops->task_create (clone_flags);
@@ -2546,6 +2570,15 @@ static inline int security_file_receive (struct file *file)return 0 ; } +static inline int security_cred_dup (struct cred *cred) +{ +return 0 ; +} + +static inline void security_cred_destroy (struct cred *cred) +{ +} +static inline int security_task_create (unsigned long clone_flags) {return 0 ;
kernel/cred.c +7 -0
@@ -94,6 +94,12 @@ struct cred *dup_cred(const struct cred *pcred)if (likely (cred)) { *cred = *pcred;atomic_set (&cred->usage,1 ); + +if (security_cred_dup (cred) <0 ) { +kfree (cred); +return NULL ; + } +get_group_info (cred->group_info);#ifdef CONFIG_KEYS key_get (key_ref_to_ptr (cred->session_keyring));
@@ -113,6 +119,7 @@ static void put_cred_rcu(struct rcu_head *rcu) { struct cred *cred = container_of(rcu, struct cred, exterminate); +security_cred_destroy (cred);put_group_info (cred->group_info);key_ref_put (cred->session_keyring);key_ref_put (cred->process_keyring);
security/dummy.c +11 -0
@@ -468,6 +468,15 @@ static int dummy_file_receive (struct file *file)return 0 ; } +static int dummy_cred_dup (struct cred *cred) +{ +return 0 ; +} + +static void dummy_cred_destroy (struct cred *cred) +{ +} +static int dummy_task_create (unsigned long clone_flags) {return 0 ;
@@ -1038,6 +1047,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, file_set_fowner);set_to_dummy_if_null (ops, file_send_sigiotask);set_to_dummy_if_null (ops, file_receive); +set_to_dummy_if_null (ops, cred_dup); +set_to_dummy_if_null (ops, cred_destroy);set_to_dummy_if_null (ops, task_create);set_to_dummy_if_null (ops, task_alloc_security);set_to_dummy_if_null (ops, task_free_security);
security/selinux/exports.c +3 -3
@@ -57,7 +57,7 @@ void selinux_get_task_sid(struct task_struct *tsk, u32 *sid) {if (selinux_enabled) {struct task_security_struct *tsec = tsk->security; - *sid = tsec->sid; + *sid = tsec->victim_sid;return ; } *sid =0 ;
@@ -77,9 +77,9 @@ EXPORT_SYMBOL_GPL(selinux_string_to_sid);int selinux_relabel_packet_permission (u32 sid) {if (selinux_enabled) { -struct task_security_struct *tsec = current->security; +struct cred_security_struct *csec = current->cred->security; -return avc_has_perm (tsec->sid, sid,SECCLASS_PACKET , +return avc_has_perm (csec->action_sid, sid,SECCLASS_PACKET ,PACKET__RELABELTO ,NULL ); }return 0 ;
security/selinux/hooks.c +305 -192
1,290 lines not on this page · raw message
security/selinux/include/objsec.h +12 -4
@@ -27,14 +27,22 @@#include "flask.h" #include "avc.h" +/* +* the security parameters associated with the credentials record structure +* (struct cred::security) +*/ +struct cred_security_struct { +u32 action_sid;/* perform action as SID */ +u32 create_sid;/* filesystem object creation as SID */ +u32 keycreate_sid;/* key creation as SID */ +u32 sockcreate_sid;/* socket creation as SID */ +}; +struct task_security_struct {struct task_struct *task;/* back pointer to task object */ u32 osid;/* SID prior to last execve */ -u32 sid;/* current SID */ +u32 victim_sid;/* current SID affecting victimisation of this task */ u32 exec_sid;/* exec SID */ -u32 create_sid;/* fscreate SID */ -u32 keycreate_sid;/* keycreate SID */ -u32 sockcreate_sid;/* fscreate SID */ u32 ptrace_sid;/* SID of ptrace parent */ };
security/selinux/selinuxfs.c +4 -4
@@ -77,13 +77,13 @@ extern void selnl_notify_setenforce(int val);static int task_has_security (struct task_struct *tsk,u32 perms) { -struct task_security_struct *tsec; +struct cred_security_struct *csec; - tsec = tsk->security; -if (!tsec) + csec = tsk->cred->security; +if (!csec)return -EACCES ; -return avc_has_perm (tsec->sid,SECINITSID_SECURITY , +return avc_has_perm (csec->action_sid,SECINITSID_SECURITY ,SECCLASS_SECURITY , perms,NULL ); }
security/selinux/xfrm.c +3 -3
@@ -240,7 +240,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,/* * Does the subject have permission to set security context? */ - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );if (rc)
@@ -341,7 +341,7 @@ int selinux_xfrm_policy_delete(struct xfrm_policy *xp)int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
@@ -383,7 +383,7 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 3/24 CRED: Alter security_task_getsecid() and similar to return both task SIDs
In reply to David HowellsAlter security_task_getsecid(), selinux_get_task_sid() and associated functions to return both the objective/victim and subjective/action task SIDs. Both results are optional by submitting NULL result pointers.
Interestingly, AF_NETLINK calls directly into SELinux. I suspect this to be incorrect. It should probably use security_task_getsecid() instead.
---
drivers/usb/core/devio.c | 4 ++-- include/linux/security.h | 18 +++++++++++++----- include/linux/selinux.h | 15 ++++++++++----- kernel/auditsc.c | 14 +++++++------- net/netlabel/netlabel_unlabeled.c | 2 +- net/netlink/af_netlink.c | 2 +- security/dummy.c | 3 ++- security/selinux/exports.c | 22 ++++++++++++++++++---- security/selinux/hooks.c | 5 +++-- security/selinux/xfrm.c | 12 ++++++------ 10 files changed, 63 insertions(+), 34 deletions(-)
drivers/usb/core/devio.c +2 -2
@@ -579,7 +579,7 @@ static int usbdev_open(struct inode *inode, struct file *file) ps->disc_euid = current->euid; ps->disccontext =NULL ; ps->ifclaimed =0 ; -security_task_getsecid (current, &ps->secid); +security_task_getsecid (current,NULL , &ps->secid);smp_wmb ();list_add_tail (&ps->list, &dev->filelist); file->private_data = ps;
@@ -1069,7 +1069,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb, as->pid =get_pid (task_pid (current)); as->uid = current->uid; as->euid = current->euid; -security_task_getsecid (current, &as->secid); +security_task_getsecid (current,NULL , &as->secid);if (!(uurb->endpoint &USB_DIR_IN )) {if (copy_from_user (as->urb->transfer_buffer, uurb->buffer, as->urb->transfer_buffer_length)) {free_async (as);
include/linux/security.h +13 -5
@@ -584,7 +584,12 @@ struct request_sock;* Return 0 if permission is granted. * @task_getsecid: * Retrieve the security identifier of the process @p. -* @p contains the task_struct for the process and place is into @secid. +* @p contains the task_struct for the process to be interrogated. The +* security ID of the task itself is placed in *@object_secid, and the +* security ID as which the task is currently acting is placed in +* *@action_secid. Either result pointer may be NULL if that particular +* ID is not required. +* * @task_setgroups: * Check permission before setting the supplementary group set of the * current process.
@@ -1281,7 +1286,8 @@ struct security_operations {int (*task_setpgid) (struct task_struct * p,pid_t pgid);int (*task_getpgid) (struct task_struct * p);int (*task_getsid) (struct task_struct * p); -void (*task_getsecid) (struct task_struct * p,u32 * secid); +void (*task_getsecid) (struct task_struct * p, +u32 * object_secid,u32 * subject_secid);int (*task_setgroups) (struct group_info *group_info);int (*task_setnice) (struct task_struct * p,int nice);int (*task_setioprio) (struct task_struct * p,int ioprio);
@@ -1936,9 +1942,10 @@ static inline int security_task_getsid (struct task_struct *p)return security_ops->task_getsid (p); } -static inline void security_task_getsecid (struct task_struct *p,u32 *secid) +static inline void security_task_getsecid (struct task_struct *p, +u32 *object_secid,u32 *action_secid) { - security_ops->task_getsecid (p, secid); + security_ops->task_getsecid (p, object_secid, action_secid); }static inline int security_task_setgroups (struct group_info *group_info)
@@ -2625,7 +2632,8 @@ static inline int security_task_getsid (struct task_struct *p)return 0 ; } -static inline void security_task_getsecid (struct task_struct *p,u32 *secid) +static inline void security_task_getsecid (struct task_struct *p, +u32 *object_secid,u32 *action_secid) { }static inline int security_task_setgroups (struct group_info *group_info)
include/linux/selinux.h +10 -5
@@ -101,12 +101,16 @@ void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid);/** * selinux_get_task_sid - return the SID of task -* @tsk: the task whose SID will be returned -* @sid: pointer to security context ID to be filled in. +* @tsk: the task to be queried. +* @object_sid: optional pointer to where the objective security context ID +* of the task is to be placed. +* @action_sid: optional pointer to where the subjective security context ID +* of the task is to be placed. * * Returns nothing */ -void selinux_get_task_sid (struct task_struct *tsk,u32 *sid); +void selinux_get_task_sid (struct task_struct *tsk, +u32 *object_sid,u32 *action_sid);/** * selinux_string_to_sid - map a security context string to a security ID
@@ -173,9 +177,10 @@ static inline void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *si *sid =0 ; } -static inline void selinux_get_task_sid (struct task_struct *tsk,u32 *sid) +lstatic inline void selinux_get_task_sid(struct task_struct *tsk, +u32 *object_sid,u32 *action_sid) { - *sid =0 ; + *object_sid = *action_sid =0 ; }static inline int selinux_string_to_sid (const char *str,u32 *sid)
kernel/auditsc.c +7 -7
@@ -399,7 +399,7 @@ static int audit_filter_rules(struct task_struct *tsk,logged upon error */ if (f->se_rule) {if (need_sid) { -selinux_get_task_sid (tsk, &sid); +selinux_get_task_sid (tsk,NULL , &sid); need_sid =0 ; } result = selinux_audit_rule_match(sid, f->type,
@@ -746,7 +746,7 @@ void audit_log_task_context(struct audit_buffer *ab)int error;u32 sid; -selinux_get_task_sid (current, &sid); +selinux_get_task_sid (current,NULL , &sid);if (!sid)return ;
@@ -1977,7 +1977,7 @@ void __audit_ptrace(struct task_struct *t)struct audit_context *context = current->audit_context; context->target_pid = t->pid; -selinux_get_task_sid (t, &context->target_sid); +selinux_get_task_sid (t, &context->target_sid,NULL ); }/**
@@ -2004,7 +2004,7 @@ int __audit_signal_info(int sig, struct task_struct *t) audit_sig_uid = ctx->loginuid; else audit_sig_uid = tsk->uid; -selinux_get_task_sid (tsk, &audit_sig_sid); +selinux_get_task_sid (tsk,NULL , &audit_sig_sid); }if (!audit_signals ||audit_dummy_context ())return 0 ;
@@ -2014,7 +2014,7 @@ int __audit_signal_info(int sig, struct task_struct *t)* in audit_context */ if (!ctx->target_pid) { ctx->target_pid = t->tgid; -selinux_get_task_sid (t, &ctx->target_sid); +selinux_get_task_sid (t, &ctx->target_sid,NULL );return 0 ; }
@@ -2031,7 +2031,7 @@ int __audit_signal_info(int sig, struct task_struct *t)BUG_ON (axp->pid_count >=AUDIT_AUX_PIDS ); axp->target_pid[axp->pid_count] = t->tgid; -selinux_get_task_sid (t, &axp->target_sid[axp->pid_count]); +selinux_get_task_sid (t, &axp->target_sid[axp->pid_count],NULL ); axp->pid_count++;return 0 ;
@@ -2059,7 +2059,7 @@ void audit_core_dumps(long signr)audit_log_format (ab,"auid=%u uid=%u gid=%u" ,audit_get_loginuid (current->audit_context), current->uid, current->gid); -selinux_get_task_sid (current, &sid); +selinux_get_task_sid (current,NULL , &sid);if (sid) {char *ctx =NULL ;u32 len;
net/netlabel/netlabel_unlabeled.c +1 -1
@@ -277,7 +277,7 @@ int netlbl_unlabel_defconf(void)/* Only the kernel is allowed to call this function and the only time * it is called is at bootup before the audit subsystem is reporting * messages so don't worry to much about these values. */ -security_task_getsecid (current, &audit_info.secid); +security_task_getsecid (current,NULL , &audit_info.secid); audit_info.loginuid =0 ; entry =kzalloc (sizeof (*entry),GFP_KERNEL );
net/netlink/af_netlink.c +1 -1
@@ -1190,7 +1190,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,NETLINK_CB (skb).pid = nlk->pid;NETLINK_CB (skb).dst_group = dst_group;NETLINK_CB (skb).loginuid =audit_get_loginuid (current->audit_context); -selinux_get_task_sid (current, &(NETLINK_CB (skb).sid)); +selinux_get_task_sid (current,NULL , &(NETLINK_CB (skb).sid));memcpy (NETLINK_CREDS (skb), &siocb->scm->creds,sizeof (struct ucred ));/* What can I do? Netlink is asynchronous, so that
security/dummy.c +2 -1
@@ -523,7 +523,8 @@ static int dummy_task_getsid (struct task_struct *p)return 0 ; } -static void dummy_task_getsecid (struct task_struct *p,u32 *secid) +static void dummy_task_getsecid (struct task_struct *p, +u32 *object_secid,u32 *action_secid) { }static int dummy_task_setgroups (struct group_info *group_info)
security/selinux/exports.c +18 -4
@@ -53,14 +53,28 @@ void selinux_get_ipc_sid(const struct kern_ipc_perm *ipcp, u32 *sid) *sid =0 ; } -void selinux_get_task_sid (struct task_struct *tsk,u32 *sid) +void selinux_get_task_sid (struct task_struct *tsk, +u32 *object_sid,u32 *action_sid) {if (selinux_enabled) { -struct task_security_struct *tsec = tsk->security; - *sid = tsec->victim_sid; +struct task_security_struct *tsec; +struct cred_security_struct *csec; +if (object_sid) { + tsec = tsk->security; + *object_sid = tsec->victim_sid; + } +if (action_sid) { +rcu_read_lock (); + csec =task_cred (tsk)->security; + *action_sid = csec->action_sid; +rcu_read_unlock (); + }return ; } - *sid =0 ; +if (object_sid) + *object_sid =0 ; +if (action_sid) + *action_sid =0 ; }int selinux_string_to_sid (char *str,u32 *sid)
security/selinux/hooks.c +3 -2
@@ -2853,9 +2853,10 @@ static int selinux_task_getsid(struct task_struct *p)return task_has_perm (current, p,PROCESS__GETSESSION ); } -static void selinux_task_getsecid (struct task_struct *p,u32 *secid) +static void selinux_task_getsecid (struct task_struct *p, +u32 *object_secid,u32 *action_secid) { -selinux_get_task_sid (p, secid); +selinux_get_task_sid (p, object_secid, action_secid); }static int selinux_task_setgroups (struct group_info *group_info)
security/selinux/xfrm.c +6 -6
@@ -199,7 +199,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *uctx, u32 sid) { int rc = 0; -struct task_security_struct *tsec = current->security; +struct cred_security_struct *csec = current->cred->security;struct xfrm_sec_ctx *ctx =NULL ;char *ctx_str =NULL ;u32 str_len;
@@ -240,7 +240,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,/* * Does the subject have permission to set security context? */ - rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid, + rc =avc_has_perm (csec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );if (rc)
@@ -336,12 +336,12 @@ void selinux_xfrm_policy_free(struct xfrm_policy *xp)*/ int selinux_xfrm_policy_delete (struct xfrm_policy *xp) { -struct task_security_struct *tsec = current->security; +struct cred_security_struct *csec = current->cred->security;struct xfrm_sec_ctx *ctx = xp->security;int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid, + rc =avc_has_perm (csec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
@@ -378,12 +378,12 @@ void selinux_xfrm_state_free(struct xfrm_state *x)*/ int selinux_xfrm_state_delete (struct xfrm_state *x) { -struct task_security_struct *tsec = current->security; +struct cred_security_struct *csec = current->cred->security;struct xfrm_sec_ctx *ctx = x->security;int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->action_sid, ctx->ctx_sid, + rc =avc_has_perm (csec->action_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 4/24 CRED: Move the effective capabilities into the cred struct
In reply to David HowellsMove the effective capabilities mask from the task struct into the credentials record.
Note that the effective capabilities mask in the cred struct shadows that in the task_struct because a thread can have its capabilities masks changed by another thread. The shadowing is performed by update_current_cred() which is invoked on entry to any system call that might need it.
---
fs/buffer.c | 3 +++ fs/ioprio.c | 3 +++ fs/open.c | 27 +++++++++------------------ fs/proc/array.c | 2 +- fs/readdir.c | 3 +++ include/linux/cred.h | 2 ++ include/linux/init_task.h | 2 +- include/linux/sched.h | 2 +- ipc/msg.c | 3 +++ ipc/sem.c | 3 +++ ipc/shm.c | 3 +++ kernel/acct.c | 3 +++ kernel/capability.c | 3 +++ kernel/compat.c | 3 +++ kernel/cred.c | 36 +++++++++++++++++++++++++++++------- kernel/exit.c | 2 ++ kernel/fork.c | 6 +++++- kernel/futex.c | 3 +++ kernel/futex_compat.c | 3 +++ kernel/kexec.c | 3 +++ kernel/module.c | 6 ++++++ kernel/ptrace.c | 3 +++ kernel/sched.c | 9 +++++++++ kernel/signal.c | 6 ++++++ kernel/sys.c | 39 +++++++++++++++++++++++++++++++++++++++ kernel/sysctl.c | 3 +++ kernel/time.c | 9 +++++++++ kernel/uid16.c | 3 +++ mm/mempolicy.c | 6 ++++++ mm/migrate.c | 3 +++ mm/mlock.c | 4 ++++ mm/mmap.c | 3 +++ mm/mremap.c | 3 +++ mm/oom_kill.c | 9 +++++++-- mm/swapfile.c | 6 ++++++ net/compat.c | 6 ++++++ net/socket.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ security/commoncap.c | 32 +++++++++++++++++--------------- security/dummy.c | 22 ++++++++++++++++++---- 39 files changed, 282 insertions(+), 50 deletions(-)
fs/buffer.c +3 -0
@@ -2909,6 +2909,9 @@ asmlinkage long sys_bdflush(int func, long data) {static int msg_count; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
fs/ioprio.c +3 -0
@@ -63,6 +63,9 @@ asmlinkage long sys_ioprio_set(int which, int who, int ioprio)struct pid *pgrp;int ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +switch (class) {case IOPRIO_CLASS_RT :if (!capable (CAP_SYS_ADMIN ))
fs/open.c +9 -18
@@ -450,7 +450,7 @@ out:asmlinkage long sys_faccessat (int dfd,const char __user *filename,int mode) {struct nameidata nd; -kernel_cap_t old_cap; +kernel_cap_t old_cap, want_cap =CAP_EMPTY_SET ;struct cred *cred;int res;
@@ -461,33 +461,26 @@ asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode)if (res <0 )return res; - old_cap = current->cap_effective; +/* Clear the capabilities if we switch to a non-root user */ +if (!current->uid) + want_cap = current->cap_permitted; + + old_cap = current->cred->cap_effective;if (current->cred->uid != current->uid || - current->cred->gid != current->gid) { + current->cred->gid != current->gid || + current->cred->cap_effective != want_cap) { cred =dup_cred (current->cred);if (!cred)return -ENOMEM ;change_fsuid (cred, current->uid);change_fsgid (cred, current->gid); +change_cap (cred, want_cap); }else { cred =get_current_cred (); } -/* -* Clear the capabilities if we switch to a non-root user -* -* FIXME: There is a race here against sys_capset. The -* capabilities can change yet we will restore the old -* value below. We should hold task_capabilities_lock, -* but we cannot because user_path_walk can sleep. -*/ -if (current->uid) -cap_clear (current->cap_effective); -else - current->cap_effective = current->cap_permitted; - cred =__set_current_cred (cred); res =__user_walk_fd (dfd, filename,LOOKUP_FOLLOW |LOOKUP_ACCESS , &nd);if (res)
@@ -506,8 +499,6 @@ out_path_release:path_release (&nd); out:set_current_cred (cred); - current->cap_effective = old_cap; -return res; }
fs/proc/array.c +1 -1
@@ -286,7 +286,7 @@ static inline char *task_cap(struct task_struct *p, char *buffer)"CapEff:\t%016x\n" ,cap_t (p->cap_inheritable),cap_t (p->cap_permitted), - cap_t(p->cap_effective)); + cap_t(p->_cap_effective)); } static inline char *task_context_switch_counts(struct task_struct *p,
fs/readdir.c +3 -0
@@ -103,6 +103,9 @@ asmlinkage long old_readdir(unsigned int fd, struct old_linux_dirent __user * distruct file * file;struct readdir_callback buf; +if (update_current_cred () <0 ) +return -ENOMEM ; + error = -EBADF ; file =fget (fd);if (!file)
include/linux/cred.h +2 -0
@@ -24,6 +24,7 @@ struct cred {atomic_t usage;uid_t uid;/* fsuid as was */ gid_t gid;/* fsgid as was */ +kernel_cap_t cap_effective;struct rcu_head exterminate;/* cred destroyer */ struct group_info *group_info;void *security;
@@ -48,6 +49,7 @@ extern void put_cred(struct cred *);extern void change_fsuid (struct cred *,uid_t );extern void change_fsgid (struct cred *,gid_t );extern void change_groups (struct cred *,struct group_info *); +extern void change_cap (struct cred *,kernel_cap_t );extern struct cred *dup_cred (const struct cred *);/**
include/linux/init_task.h +1 -1
@@ -141,7 +141,7 @@ extern struct nsproxy init_nsproxy; .sibling = LIST_HEAD_INIT(tsk.sibling), \ .group_leader = &tsk, \ .cred = &init_cred, \ - .cap_effective = CAP_INIT_EFF_SET, \ + ._cap_effective = CAP_INIT_EFF_SET, \ .cap_inheritable = CAP_INIT_INH_SET, \ .cap_permitted = CAP_FULL_SET, \ .keep_capabilities = 0, \
include/linux/sched.h +1 -1
@@ -1037,7 +1037,7 @@ struct task_struct {struct cred *cred;uid_t uid,euid,suid;gid_t gid,egid,sgid; -kernel_cap_t cap_effective, cap_inheritable, cap_permitted; +kernel_cap_t _cap_effective, cap_inheritable, cap_permitted; unsigned keep_capabilities:1;struct user_struct *user;#ifdef CONFIG_KEYS
ipc/msg.c +3 -0
@@ -393,6 +393,9 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)if (msqid <0 || cmd <0 )return -EINVAL ; +if (update_current_cred () <0 ) +return -ENOMEM ; + version =ipc_parse_version (&cmd); ns = current->nsproxy->ipc_ns;
ipc/sem.c +3 -0
@@ -927,6 +927,9 @@ asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)if (semid <0 )return -EINVAL ; +if (update_current_cred () <0 ) +return -ENOMEM ; + version =ipc_parse_version (&cmd); ns = current->nsproxy->ipc_ns;
ipc/shm.c +3 -0
@@ -589,6 +589,9 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf) goto out; } +if (update_current_cred () <0 ) +return -ENOMEM ; + version =ipc_parse_version (&cmd); ns = current->nsproxy->ipc_ns;
kernel/acct.c +3 -0
@@ -253,6 +253,9 @@ asmlinkage long sys_acct(const char __user *name) {int error; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_PACCT ))return -EPERM ;
kernel/capability.c +3 -0
@@ -178,6 +178,9 @@ asmlinkage long sys_capset(cap_user_header_t header, const cap_user_data_t data)int ret;pid_t pid; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (get_user (version, &header->version))return -EFAULT ;
kernel/compat.c +3 -0
@@ -909,6 +909,9 @@ asmlinkage long compat_sys_adjtimex(struct compat_timex __user *utp)struct timex txc;int ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +memset (&txc,0 ,sizeof (struct timex )); if (!access_ok(VERIFY_READ, utp, sizeof(struct compat_timex)) ||
kernel/cred.c +29 -7
@@ -21,16 +21,19 @@*/ struct cred init_cred = { .usage =ATOMIC_INIT (2 ), + .cap_effective =CAP_INIT_EFF_SET , .group_info = &init_groups, };/** * update_current_cred - Bring the current task's creds up to date * -* Bring the current task's credentials up to date with respect to the keyrings -* they shadow. The process and session level keyrings may get changed by -* sibling threads with the same process, but the change can't be applied back -* to this thread's cred struct except by this thread itself. +* Bring the current task's credential record up to date with respect to the +* effective capability mask and keyrings it shadows. The capabilities mask +* may get changed by other processes, and process and session level keyrings +* may get changed by sibling threads with the same process, but the change +* can't be applied back to this thread's cred struct except by this thread +* itself. */ int update_current_cred (void ) {
@@ -46,16 +49,21 @@ int update_current_cred(void)key_ref_to_ptr (cred->process_keyring) == sig->process_keyring &&key_ref_to_ptr (cred->thread_keyring) == current->thread_keyring && #endif - true) + cred->cap_effective != current->_cap_effective) return 0; - cred =kmalloc (sizeof (struct cred ),GFP_KERNEL ); + cred =kmemdup (current->cred,sizeof (struct cred ),GFP_KERNEL );if (!cred)return -ENOMEM ; - *cred = *current->cred; +if (security_cred_dup (cred) <0 ) { +kfree (cred); +return -ENOMEM ; + } +atomic_set (&cred->usage,1 );get_group_info (cred->group_info); + cred->cap_effective = current->_cap_effective;#ifdef CONFIG_KEYS rcu_read_lock ();
@@ -188,3 +196,17 @@ void change_groups(struct cred *cred, struct group_info *group_info) }EXPORT_SYMBOL (change_groups); + +/** +* change_cap - Change the supplementary groups in a new credential record +* @cred: The credential record to alter +* @cap: The capabilities to set +* +* Change the effective capabilities in a new credential record. +*/ +void change_cap (struct cred *cred,kernel_cap_t cap) +{ + cred->cap_effective = cap; +} + +EXPORT_SYMBOL (change_cap);
kernel/exit.c +2 -0
@@ -888,6 +888,8 @@ fastcall NORET_TYPE void do_exit(long code)struct task_struct *tsk = current;int group_dead; +update_current_cred (); +profile_task_exit (tsk);WARN_ON (atomic_read (&tsk->fs_excl));
kernel/fork.c +5 -1
@@ -1422,9 +1422,13 @@ long do_fork(unsigned long clone_flags, {struct task_struct *p;int trace =0 ; -struct pid *pid =alloc_pid (); +struct pid *pid;long nr; +if (update_current_cred ()) +return -ENOMEM ; + + pid =alloc_pid ();if (!pid)return -EAGAIN ; nr = pid->nr;
kernel/futex.c +3 -0
@@ -1846,6 +1846,9 @@ sys_get_robust_list(int pid, struct robust_list_head __user * __user *head_ptr,struct robust_list_head __user *head;unsigned long ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!pid) head = current->robust_list;else {
kernel/futex_compat.c +3 -0
@@ -109,6 +109,9 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,struct compat_robust_list_head __user *head;unsigned long ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!pid) head = current->compat_robust_list;else {
kernel/kexec.c +3 -0
@@ -921,6 +921,9 @@ asmlinkage long sys_kexec_load(unsigned long entry, unsigned long nr_segments,int locked;int result; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* We only trust the superuser with rebooting the system. */ if (!capable (CAP_SYS_BOOT ))return -EPERM ;
kernel/module.c +6 -0
@@ -660,6 +660,9 @@ sys_delete_module(const char __user *name_user, unsigned int flags)char name[MODULE_NAME_LEN ];int ret, forced =0 ; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_MODULE ))return -EPERM ;
@@ -1978,6 +1981,9 @@ sys_init_module(void __user *umod,struct module *mod;int ret =0 ; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* Must have permission */ if (!capable (CAP_SYS_MODULE ))return -EPERM ;
kernel/ptrace.c +3 -0
@@ -456,6 +456,9 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)struct task_struct *child;long ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* * This lock_kernel fixes a subtle race with suid exec */
kernel/sched.c +9 -0
@@ -4063,6 +4063,9 @@ asmlinkage long sys_nice(int increment) {long nice, retval; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* * Setpriority might change our priority at the same moment. * We don't have to worry. Conceptually one call occurs first
@@ -4295,6 +4298,9 @@ do_sched_setscheduler(pid_t pid, int policy, struct sched_param __user *param)struct task_struct *p;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!param || pid <0 )return -EINVAL ;if (copy_from_user (&lparam, param,sizeof (struct sched_param )))
@@ -4468,6 +4474,9 @@ asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,cpumask_t new_mask;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =get_user_cpu_mask (user_mask_ptr, len, &new_mask);if (retval)return retval;
kernel/signal.c +6 -0
@@ -2197,6 +2197,9 @@ sys_kill(int pid, int sig) {struct siginfo info; +if (update_current_cred () <0 ) +return -ENOMEM ; + info.si_signo = sig; info.si_errno =0 ; info.si_code =SI_USER ;
@@ -2212,6 +2215,9 @@ static int do_tkill(int tgid, int pid, int sig)struct siginfo info;struct task_struct *p; +if (update_current_cred () <0 ) +return -ENOMEM ; + error = -ESRCH ; info.si_signo = sig; info.si_errno =0 ;
kernel/sys.c +39 -0
@@ -670,6 +670,9 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)int error = -EINVAL ;struct pid *pgrp; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (which >PRIO_USER || which <PRIO_PROCESS ) goto out;
@@ -896,6 +899,9 @@ asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void __user {char buffer[256 ]; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* We only trust the superuser with rebooting the system. */ if (!capable (CAP_SYS_BOOT ))return -EPERM ;
@@ -1019,6 +1025,9 @@ asmlinkage long sys_setregid(gid_t rgid, gid_t egid)int new_egid = old_egid;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setgid (rgid, egid, (gid_t)-1 ,LSM_SETID_RE );if (retval)return retval;
@@ -1072,6 +1081,9 @@ asmlinkage long sys_setgid(gid_t gid)int old_egid = current->egid;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setgid (gid, (gid_t)-1 , (gid_t)-1 ,LSM_SETID_ID );if (retval)return retval;
@@ -1150,6 +1162,9 @@ asmlinkage long sys_setreuid(uid_t ruid, uid_t euid)int old_ruid, old_euid, old_suid, new_ruid, new_euid;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setuid (ruid, euid, (uid_t)-1 ,LSM_SETID_RE );if (retval)return retval;
@@ -1221,6 +1236,9 @@ asmlinkage long sys_setuid(uid_t uid)int old_ruid, old_suid, new_suid;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setuid (uid, (uid_t)-1 , (uid_t)-1 ,LSM_SETID_ID );if (retval)return retval;
@@ -1271,6 +1289,9 @@ asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid)int old_suid = current->suid;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setuid (ruid, euid, suid,LSM_SETID_RES );if (retval)return retval;
@@ -1333,6 +1354,9 @@ asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid)struct cred *cred;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; + retval =security_task_setgid (rgid, egid, sgid,LSM_SETID_RES );if (retval)return retval;
@@ -1876,6 +1900,9 @@ asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist)struct group_info *group_info;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SETGID ))return -EPERM ;if ((unsigned )gidsetsize >NGROUPS_MAX )
@@ -1941,6 +1968,9 @@ asmlinkage long sys_sethostname(char __user *name, int len)int errno;char tmp[__NEW_UTS_LEN]; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;if (len <0 || len > __NEW_UTS_LEN)
@@ -1986,6 +2016,9 @@ asmlinkage long sys_setdomainname(char __user *name, int len)int errno;char tmp[__NEW_UTS_LEN]; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;if (len <0 || len > __NEW_UTS_LEN)
@@ -2045,6 +2078,9 @@ asmlinkage long sys_setrlimit(unsigned int resource, struct rlimit __user *rlim)unsigned long it_prof_secs;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (resource >=RLIM_NLIMITS )return -EINVAL ;if (copy_from_user (&new_rlim, rlim,sizeof (*rlim)))
@@ -2226,6 +2262,9 @@ asmlinkage long sys_prctl(int option, unsigned long arg2, unsigned long arg3, {long error; +if (update_current_cred () <0 ) +return -ENOMEM ; + error =security_task_prctl (option, arg2, arg3, arg4, arg5);if (error)return error;
kernel/sysctl.c +3 -0
@@ -1347,6 +1347,9 @@ asmlinkage long sys_sysctl(struct __sysctl_args __user *args)struct __sysctl_args tmp;int error; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (copy_from_user (&tmp, args,sizeof (tmp)))return -EFAULT ;
kernel/time.c +9 -0
@@ -82,6 +82,9 @@ asmlinkage long sys_stime(time_t __user *tptr)struct timespec tv;int err; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (get_user (tv.tv_sec, tptr))return -EFAULT ;
@@ -186,6 +189,9 @@ asmlinkage long sys_settimeofday(struct timeval __user *tv,struct timespec new_ts;struct timezone new_tz; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (tv) {if (copy_from_user (&user_tv, tv,sizeof (*tv)))return -EFAULT ;
@@ -205,6 +211,9 @@ asmlinkage long sys_adjtimex(struct timex __user *txc_p)struct timex txc;/* Local copy of parameter */ int ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* Copy the user data space into the kernel copy * structure. But bear in mind that the structures * may change
kernel/uid16.c +3 -0
@@ -187,6 +187,9 @@ asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)struct group_info *group_info;int retval; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SETGID ))return -EPERM ;if ((unsigned )gidsetsize >NGROUPS_MAX )
mm/mempolicy.c +6 -0
@@ -878,6 +878,9 @@ asmlinkage long sys_mbind(unsigned long start, unsigned long len,nodemask_t nodes;int err; +if (update_current_cred () <0 ) +return -ENOMEM ; + err =get_nodes (&nodes, nmask, maxnode);if (err)return err;
@@ -914,6 +917,9 @@ asmlinkage long sys_migrate_pages(pid_t pid, unsigned long maxnode,nodemask_t task_nodes;int err; +if (update_current_cred () <0 ) +return -ENOMEM ; + err =get_nodes (&old, old_nodes, maxnode);if (err)return err;
mm/migrate.c +3 -0
@@ -915,6 +915,9 @@ asmlinkage long sys_move_pages(pid_t pid, unsigned long nr_pages,struct mm_struct *mm;struct page_to_node *pm =NULL ; +if (update_current_cred () <0 ) +return -ENOMEM ; +/* Check flags */ if (flags & ~(MPOL_MF_MOVE |MPOL_MF_MOVE_ALL ))return -EINVAL ;
mm/mlock.c +4 -0
@@ -138,6 +138,8 @@ asmlinkage long sys_mlock(unsigned long start, size_t len)unsigned long lock_limit;int error = -ENOMEM ; +if (update_current_cred () <0 ) +return -ENOMEM ;if (!can_do_mlock ())return -EPERM ;
@@ -203,6 +205,8 @@ asmlinkage long sys_mlockall(int flags)if (!flags || (flags & ~(MCL_CURRENT |MCL_FUTURE ))) goto out; +if (update_current_cred () <0 ) +return -ENOMEM ; ret = -EPERM ;if (!can_do_mlock ()) goto out;
mm/mmap.c +3 -0
@@ -240,6 +240,9 @@ asmlinkage unsigned long sys_brk(unsigned long brk)unsigned long newbrk, oldbrk;struct mm_struct *mm = current->mm; +if (update_current_cred () <0 ) +return -ENOMEM ; +down_write (&mm->mmap_sem);if (brk < mm->end_code)
mm/mremap.c +3 -0
@@ -418,6 +418,9 @@ asmlinkage unsigned long sys_mremap(unsigned long addr, {unsigned long ret; +if (update_current_cred () <0 ) +return -ENOMEM ; +down_write (¤t->mm->mmap_sem); ret =do_mremap (addr, old_len, new_len, flags, new_addr);up_write (¤t->mm->mmap_sem);
mm/oom_kill.c +7 -2
@@ -53,6 +53,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)unsigned long points, cpu_time, run_time, s;struct mm_struct *mm;struct task_struct *child; +kernel_cap_t cap_effective;task_lock (p); mm = p->mm;
@@ -123,7 +124,11 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)* Superuser processes are usually more important, so we make it * less likely that we kill those. */ -if (cap_t (p->cap_effective) &CAP_TO_MASK (CAP_SYS_ADMIN ) || +rcu_read_lock (); + cap_effective =task_cred (p)->cap_effective; +rcu_read_unlock (); + +if (cap_t (cap_effective) &CAP_TO_MASK (CAP_SYS_ADMIN ) || p->uid ==0 || p->euid ==0 ) points /=4 ;
@@ -133,7 +138,7 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)* tend to only have this flag set on applications they think * of as important. */ -if (cap_t (p->cap_effective) &CAP_TO_MASK (CAP_SYS_RAWIO )) +if (cap_t (cap_effective) &CAP_TO_MASK (CAP_SYS_RAWIO )) points /=4 ;/*
mm/swapfile.c +6 -0
@@ -1183,6 +1183,9 @@ asmlinkage long sys_swapoff(const char __user * specialfile)int i, type, prev;int err; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
@@ -1433,6 +1436,9 @@ asmlinkage long sys_swapon(const char __user * specialfile, int swap_flags)struct inode *inode =NULL ;int did_down =0 ; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;spin_lock (&swap_lock);
net/compat.c +6 -0
@@ -483,6 +483,9 @@ asmlinkage long compat_sys_setsockopt(int fd, int level, int optname,int err;struct socket *sock; +if (update_current_cred () <0 ) +return -ENOMEM ; +if (level ==SOL_IPV6 && optname ==IPT_SO_SET_REPLACE )return do_netfilter_replace (fd, level, optname, optval, optlen);
@@ -603,6 +606,9 @@ asmlinkage long compat_sys_getsockopt(int fd, int level, int optname,int err;struct socket *sock; +if (update_current_cred () <0 ) +return -ENOMEM ; +if ((sock =sockfd_lookup (fd, &err))!=NULL ) { err = security_socket_getsockopt(sock, level,
net/socket.c +45 -0
135 lines not on this page · raw message
security/commoncap.c +17 -15
@@ -25,7 +25,7 @@int cap_netlink_send (struct sock *sk,struct sk_buff *skb) { -NETLINK_CB (skb).eff_cap = current->cap_effective; +NETLINK_CB (skb).eff_cap = current->cred->cap_effective;return 0 ; }
@@ -43,7 +43,7 @@ EXPORT_SYMBOL(cap_netlink_recv);int cap_capable (struct task_struct *tsk,int cap) {/* Derived from include/linux/sched.h:capable. */ -if (cap_raised (tsk->cap_effective, cap)) +if (cap_raised (tsk->cred->cap_effective, cap))return 0 ;return -EPERM ; }
@@ -68,7 +68,9 @@ int cap_capget (struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted) {/* Derived from kernel/capability.c:sys_capget. */ - *effective =cap_t (target->cap_effective); +rcu_read_lock (); + *effective =cap_t (task_cred (target)->cap_effective); +rcu_read_unlock (); *inheritable =cap_t (target->cap_inheritable); *permitted =cap_t (target->cap_permitted);return 0 ;
@@ -103,7 +105,7 @@ int cap_capset_check (struct task_struct *target, kernel_cap_t *effective,void cap_capset_set (struct task_struct *target,kernel_cap_t *effective,kernel_cap_t *inheritable,kernel_cap_t *permitted) { - target->cap_effective = *effective; + target->_cap_effective = *effective; target->cap_inheritable = *inheritable; target->cap_permitted = *permitted; }
@@ -162,15 +164,15 @@ void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe) } } - current->suid = current->euid = current->fsuid = bprm->e_uid; - current->sgid = current->egid = current->fsgid = bprm->e_gid; + current->suid = current->euid = current->cred->uid = bprm->e_uid; + current->sgid = current->egid = current->cred->gid = bprm->e_gid;/* For init, we want to retain the capabilities set * in the init_task struct. Thus we skip the usual * capability rules */ if (!is_init (current)) { current->cap_permitted = new_permitted; - current->cap_effective = + current->_cap_effective =cap_intersect (new_permitted, bprm->cap_effective); }
@@ -246,13 +248,13 @@ static inline void cap_emulate_setxuid (int old_ruid, int old_euid, (current->uid != 0 && current->euid != 0 && current->suid != 0) && !current->keep_capabilities) {cap_clear (current->cap_permitted); -cap_clear (current->cap_effective); +cap_clear (current->_cap_effective); }if (old_euid ==0 && current->euid !=0 ) { -cap_clear (current->cap_effective); +cap_clear (current->_cap_effective); }if (old_euid !=0 && current->euid ==0 ) { - current->cap_effective = current->cap_permitted; + current->_cap_effective = current->cap_permitted; } }
@@ -280,12 +282,12 @@ int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid,*/ if (!issecure (SECURE_NO_SETUID_FIXUP )) { -if (old_fsuid ==0 && current->fsuid !=0 ) { -cap_t (current->cap_effective) &= +if (old_fsuid ==0 && current->cred->uid !=0 ) { +cap_t (current->_cap_effective) &= ~CAP_FS_MASK ; } -if (old_fsuid !=0 && current->fsuid ==0 ) { -cap_t (current->cap_effective) |= +if (old_fsuid !=0 && current->cred->uid ==0 ) { +cap_t (current->_cap_effective) |= (cap_t (current->cap_permitted) &CAP_FS_MASK ); }
@@ -301,7 +303,7 @@ int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid,void cap_task_reparent_to_init (struct task_struct *p) { - p->cap_effective =CAP_INIT_EFF_SET ; + p->_cap_effective =CAP_INIT_EFF_SET ; p->cap_inheritable =CAP_INIT_INH_SET ; p->cap_permitted =CAP_FULL_SET ; p->keep_capabilities =0 ;
security/dummy.c +18 -4
@@ -76,7 +76,13 @@ static int dummy_acct (struct file *file)static int dummy_capable (struct task_struct *tsk,int cap) { -if (cap_raised (tsk->cap_effective, cap)) +kernel_cap_t cap_effective; + +rcu_read_lock (); + cap_effective =task_cred (tsk)->cap_effective; +rcu_read_unlock (); + +if (cap_raised (cap_effective, cap))return 0 ;return -EPERM ; }
@@ -146,7 +152,12 @@ static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)change_fsuid (bprm->cred, bprm->e_uid);change_fsgid (bprm->cred, bprm->e_gid); -dummy_capget (current, ¤t->cap_effective, ¤t->cap_inheritable, ¤t->cap_permitted); +dummy_capget (current, + ¤t->_cap_effective, + ¤t->cap_inheritable, + ¤t->cap_permitted); + +change_cap (bprm->cred, current->_cap_effective); }static void dummy_bprm_post_apply_creds (struct linux_binprm *bprm)
@@ -499,7 +510,10 @@ static int dummy_task_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)static int dummy_task_post_setuid (uid_t id0,uid_t id1,uid_t id2,int flags) { -dummy_capget (current, ¤t->cap_effective, ¤t->cap_inheritable, ¤t->cap_permitted); +dummy_capget (current, + ¤t->_cap_effective, + ¤t->cap_inheritable, + ¤t->cap_permitted);return 0 ; }
@@ -697,7 +711,7 @@ static int dummy_sem_semop (struct sem_array *sma,static int dummy_netlink_send (struct sock *sk,struct sk_buff *skb) { -NETLINK_CB (skb).eff_cap = current->cap_effective; +NETLINK_CB (skb).eff_cap = current->cred->cap_effective;return 0 ; }
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 5/24 CRED: Fix up the other credentials references
In reply to David HowellsFix up the other credentials references to use the new COW cred struct.
---
arch/ia64/ia32/sys_ia32.c | 7 ++-- arch/ia64/kernel/perfmon.c | 2 - arch/powerpc/platforms/cell/spufs/inode.c | 2 - arch/s390/kernel/compat_linux.c | 18 +++------- arch/sparc64/kernel/sys_sparc32.c | 18 +++------- drivers/isdn/capi/capifs.c | 4 +- drivers/usb/core/inode.c | 2 - fs/9p/vfs_inode.c | 4 +- fs/9p/vfs_super.c | 4 +- fs/affs/inode.c | 4 +- fs/bfs/dir.c | 4 +- fs/cifs/cifsproto.h | 2 + fs/cifs/dir.c | 12 +++--- fs/cifs/inode.c | 8 ++-- fs/cifs/misc.c | 4 +- fs/coda/cache.c | 6 ++- fs/coda/file.c | 2 + fs/coda/upcall.c | 4 +- fs/ext2/balloc.c | 2 + fs/ext2/ialloc.c | 4 +- fs/ext4/balloc.c | 2 + fs/ext4/ialloc.c | 4 +- fs/fuse/dev.c | 4 +- fs/gfs2/inode.c | 10 +++-- fs/hfs/inode.c | 4 +- fs/hfsplus/inode.c | 4 +- fs/hpfs/namei.c | 24 ++++++------- fs/hugetlbfs/inode.c | 16 ++++----- fs/jffs2/fs.c | 4 +- fs/jfs/jfs_inode.c | 4 +- fs/minix/bitmap.c | 4 +- fs/nfsd/auth.c | 32 +++++++++++------ fs/nfsd/nfs4callback.c | 16 +++++---- fs/nfsd/nfs4recover.c | 54 +++++++++++++++-------------- fs/nfsd/vfs.c | 2 + fs/ocfs2/dlm/dlmfs.c | 4 -- fs/ocfs2/namei.c | 4 +- fs/reiserfs/namei.c | 3 -- fs/sysv/ialloc.c | 4 +- fs/udf/ialloc.c | 3 -- fs/udf/namei.c | 1 - fs/ufs/ialloc.c | 4 +- fs/xfs/linux-2.6/xfs_linux.h | 4 +- fs/xfs/xfs_acl.c | 6 ++- ipc/mqueue.c | 4 +- kernel/cpuset.c | 4 +- net/9p/client.c | 2 + net/ipv4/netfilter/ipt_LOG.c | 3 +- net/ipv4/netfilter/ipt_owner.c | 4 +- net/ipv6/netfilter/ip6t_LOG.c | 3 +- net/ipv6/netfilter/ip6t_owner.c | 4 +- net/netfilter/nfnetlink_log.c | 2 + 52 files changed, 167 insertions(+), 189 deletions(-)
arch/ia64/ia32/sys_ia32.c +3 -4
@@ -2088,25 +2088,24 @@ groups16_from_user(struct group_info *group_info, short __user *grouplist)asmlinkage long sys32_getgroups16 (int gidsetsize,short __user *grouplist) { +struct group_info *groups = current->cred->group_info;int i;if (gidsetsize <0 )return -EINVAL ; -get_group_info (current->group_info); - i = current->group_info->ngroups; + i = groups->ngroups;if (gidsetsize) {if (i > gidsetsize) { i = -EINVAL ; goto out; } -if (groups16_to_user (grouplist, current->group_info)) { +if (groups16_to_user (grouplist, groups)) { i = -EFAULT ; goto out; } } out: -put_group_info (current->group_info);return i; }
arch/ia64/kernel/perfmon.c +0 -2
@@ -2212,8 +2212,6 @@ pfm_alloc_fd(struct file **cfile)DPRINT (("new inode ino=%ld @%p\n" , inode->i_ino, inode)); inode->i_mode =S_IFCHR |S_IRUGO ; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid;sprintf (name,"[%lu]" , inode->i_ino); this.name = name;
arch/powerpc/platforms/cell/spufs/inode.c +0 -2
@@ -84,8 +84,6 @@ spufs_new_inode(struct super_block *sb, int mode) goto out; inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; out:
arch/s390/kernel/compat_linux.c +6 -12
@@ -213,25 +213,19 @@ static int groups16_from_user(struct group_info *group_info, u16 __user *groupliasmlinkage long sys32_getgroups16 (int gidsetsize,u16 __user *grouplist) { +struct group_info *groups = current->cred->group_info;int i;if (gidsetsize <0 )return -EINVAL ; -get_group_info (current->group_info); - i = current->group_info->ngroups; + i = groups->ngroups;if (gidsetsize) { -if (i > gidsetsize) { - i = -EINVAL ; - goto out; - } -if (groups16_to_user (grouplist, current->group_info)) { - i = -EFAULT ; - goto out; - } +if (i > gidsetsize) +return -EINVAL ; +if (groups16_to_user (grouplist, groups)) +return -EFAULT ; } -out: -put_group_info (current->group_info);return i; }
arch/sparc64/kernel/sys_sparc32.c +6 -12
@@ -171,25 +171,19 @@ static int groups16_from_user(struct group_info *group_info, u16 __user *groupliasmlinkage long sys32_getgroups16 (int gidsetsize,u16 __user *grouplist) { +struct group_info *groups = current->cred->group_info;int i;if (gidsetsize <0 )return -EINVAL ; -get_group_info (current->group_info); - i = current->group_info->ngroups; + i = groups->ngroups;if (gidsetsize) { -if (i > gidsetsize) { - i = -EINVAL ; - goto out; - } -if (groups16_to_user (grouplist, current->group_info)) { - i = -EFAULT ; - goto out; - } +if (i > gidsetsize) +return -EINVAL ; +if (groups16_to_user (grouplist, groups)) +return -EFAULT ; } -out: -put_group_info (current->group_info);return i; }
drivers/isdn/capi/capifs.c +2 -2
@@ -148,8 +148,8 @@ void capifs_new_ncci(unsigned int number, dev_t device)if (!inode)return ; inode->i_ino = number+2 ; - inode->i_uid = config.setuid ? config.uid : current->fsuid; - inode->i_gid = config.setgid ? config.gid : current->fsgid; + inode->i_uid = config.setuid ? config.uid : current->cred->uid; + inode->i_gid = config.setgid ? config.gid : current->cred->gid; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME ;init_special_inode (inode,S_IFCHR |config.mode, device);//inode->i_op = &capifs_file_inode_operations;
drivers/usb/core/inode.c +0 -2
@@ -246,8 +246,6 @@ static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t deif (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;switch (mode &S_IFMT ) {
fs/9p/vfs_inode.c +2 -2
@@ -202,8 +202,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) inode =new_inode (sb);if (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_blocks =0 ; inode->i_rdev =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
fs/9p/vfs_super.c +2 -2
@@ -112,8 +112,8 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,struct v9fs_session_info *v9ses =NULL ;struct p9_stat *st =NULL ;int mode =S_IRWXUGO |S_ISVTX ; -uid_t uid = current->fsuid; -gid_t gid = current->fsgid; +uid_t uid = current->cred->uid; +gid_t gid = current->cred->gid;struct p9_fid *fid;int retval =0 ;
fs/affs/inode.c +2 -2
@@ -305,8 +305,8 @@ affs_new_inode(struct inode *dir)mark_buffer_dirty_inode (bh, inode);affs_brelse (bh); - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_ino = block; inode->i_nlink =1 ; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ;
fs/bfs/dir.c +2 -2
@@ -99,8 +99,8 @@ static int bfs_create(struct inode * dir, struct dentry * dentry, int mode, }set_bit (ino, info->si_imap); info->si_freei--; - inode->i_uid = current->fsuid; - inode->i_gid = (dir->i_mode &S_ISGID ) ? dir->i_gid : current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = (dir->i_mode &S_ISGID ) ? dir->i_gid : current->cred->gid; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ; inode->i_blocks =0 ; inode->i_op = &bfs_file_inops;
fs/cifs/cifsproto.h +1 -1
@@ -39,7 +39,7 @@ extern int smb_send(struct socket *, struct smb_hdr *, unsigned int /* length */ , struct sockaddr *);extern unsigned int _GetXid (void );extern void _FreeXid (unsigned int ); -#define GetXid () (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__FUNCTION__, xid,current->fsuid)); +#define GetXid () (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__FUNCTION__, xid,current->cred->uid));#define FreeXid (curr_xid) {_FreeXid(curr_xid); cFYI(1,("CIFS VFS: leaving %s (xid = %d) rc = %d",__FUNCTION__,curr_xid,(int)rc));}extern char *build_path_from_dentry (struct dentry *);extern char *build_wildcard_path_from_dentry (struct dentry *direntry);
fs/cifs/dir.c +6 -6
@@ -211,8 +211,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, mode &= ~current->fs->umask;if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_SET_UID ) { CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, - (__u64)current->fsuid, - (__u64)current->fsgid, + (__u64)current->cred->uid, + (__u64)current->cred->gid, 0 /* dev */, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
@@ -246,8 +246,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,if ((oplock &CIFS_CREATE_ACTION ) && (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_SET_UID )) { - newinode->i_uid = current->fsuid; - newinode->i_gid = current->fsgid; + newinode->i_uid = current->cred->uid; + newinode->i_gid = current->cred->gid; } } }
@@ -340,8 +340,8 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, mode &= ~current->fs->umask;if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_SET_UID ) { rc =CIFSSMBUnixSetPerms (xid, pTcon, full_path, - mode, (__u64 )current->fsuid, - (__u64 )current->fsgid, + mode, (__u64 )current->cred->uid, + (__u64 )current->cred->gid, device_number, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MAP_SPECIAL_CHR );
fs/cifs/inode.c +4 -4
@@ -1003,8 +1003,8 @@ mkdir_get_info:if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_SET_UID ) { CIFSSMBUnixSetPerms(xid, pTcon, full_path, mode, - (__u64)current->fsuid, - (__u64)current->fsgid, + (__u64)current->cred->uid, + (__u64)current->cred->gid, 0 /* dev_t */, cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
@@ -1027,9 +1027,9 @@ mkdir_get_info:if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_SET_UID ) { direntry->d_inode->i_uid = - current->fsuid; + current->cred->uid; direntry->d_inode->i_gid = - current->fsgid; + current->cred->gid; } } }
fs/cifs/misc.c +2 -2
@@ -352,13 +352,13 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,/* BB Add support for establishing new tCon and SMB Session */ /* with userid/password pairs found on the smb session */ /* for other target tcp/ip addresses BB */ -if (current->fsuid != treeCon->ses->linux_uid) { +if (current->cred->uid != treeCon->ses->linux_uid) {cFYI (1 , ("Multiuser mode and UID " "did not match tcon uid" ));read_lock (&GlobalSMBSeslock);list_for_each (temp_item, &GlobalSMBSessionList) { ses = list_entry(temp_item, struct cifsSesInfo, cifsSessionList); -if (ses->linux_uid == current->fsuid) { +if (ses->linux_uid == current->cred->uid) {if (ses->server == treeCon->ses->server) {cFYI (1 , ("found matching uid substitute right smb_uid" )); buffer->Uid = ses->Suid;
fs/coda/cache.c +3 -3
@@ -32,8 +32,8 @@ void coda_cache_enter(struct inode *inode, int mask)struct coda_inode_info *cii =ITOC (inode); cii->c_cached_epoch =atomic_read (&permission_epoch); -if (cii->c_uid != current->fsuid) { - cii->c_uid = current->fsuid; +if (cii->c_uid != current->cred->uid) { + cii->c_uid = current->cred->uid; cii->c_cached_perm = mask; }else cii->c_cached_perm |= mask;
@@ -60,7 +60,7 @@ int coda_cache_check(struct inode *inode, int mask)int hit; hit = (mask & cii->c_cached_perm) == mask && - cii->c_uid == current->fsuid && + cii->c_uid == current->cred->uid && cii->c_cached_epoch ==atomic_read (&permission_epoch);return hit;
fs/coda/file.c +1 -1
@@ -174,7 +174,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)BUG_ON (!cfi || cfi->cfi_magic !=CODA_MAGIC ); err =venus_close (coda_inode->i_sb,coda_i2f (coda_inode), - coda_flags, coda_file->f_uid); + coda_flags, coda_file->f_cred->uid); host_inode = cfi->cfi_container->f_path.dentry->d_inode; cii =ITOC (coda_inode);
fs/coda/upcall.c +2 -2
@@ -54,9 +54,9 @@ static void *alloc_upcall(int opcode, int size) inp->ih.pgid =process_group (current);#ifdef CONFIG_CODA_FS_OLD_API memset (&inp->ih.cred,0 ,sizeof (struct coda_cred )); - inp->ih.cred.cr_fsuid = current->fsuid; + inp->ih.cred.cr_fsuid = current->cred->uid;#else - inp->ih.uid = current->fsuid; + inp->ih.uid = current->cred->uid;#endif return (void *)inp; }
fs/ext2/balloc.c +1 -1
@@ -112,7 +112,7 @@ static int reserve_blocks(struct super_block *sb, int count) count = free_blocks;if (free_blocks < root_blocks + count && !capable (CAP_SYS_RESOURCE ) && - sbi->s_resuid != current->fsuid && + sbi->s_resuid != current->cred->uid && (sbi->s_resgid ==0 || !in_group_p (sbi->s_resgid))) {/* * We are too close to reserve and we are not privileged.
fs/ext2/ialloc.c +1 -3
@@ -562,15 +562,13 @@ got: sb->s_dirt =1 ;mark_buffer_dirty (bh2); - inode->i_uid = current->fsuid;if (test_opt (sb,GRPID )) inode->i_gid = dir->i_gid;else if (dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; - }else - inode->i_gid = current->fsgid; + } inode->i_mode = mode; inode->i_ino = ino;
fs/ext4/balloc.c +1 -1
@@ -1377,7 +1377,7 @@ static int ext4_has_free_blocks(struct ext4_sb_info *sbi) free_blocks =percpu_counter_read_positive (&sbi->s_freeblocks_counter); root_blocks =ext4_r_blocks_count (sbi->s_es);if (free_blocks < root_blocks +1 && !capable (CAP_SYS_RESOURCE ) && - sbi->s_resuid != current->fsuid && + sbi->s_resuid != current->cred->uid && (sbi->s_resgid ==0 || !in_group_p (sbi->s_resgid))) {return 0 ; }
fs/ext4/ialloc.c +1 -3
@@ -549,15 +549,13 @@ got:percpu_counter_inc (&sbi->s_dirs_counter); sb->s_dirt =1 ; - inode->i_uid = current->fsuid;if (test_opt (sb,GRPID )) inode->i_gid = dir->i_gid;else if (dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; - }else - inode->i_gid = current->fsgid; + } inode->i_mode = mode; inode->i_ino = ino;
fs/fuse/dev.c +2 -2
@@ -79,8 +79,8 @@ static void __fuse_put_request(struct fuse_req *req)static void fuse_req_init_context (struct fuse_req *req) { - req->in.h.uid = current->fsuid; - req->in.h.gid = current->fsgid; + req->in.h.uid = current->cred->uid; + req->in.h.gid = current->cred->gid; req->in.h.pid = current->pid; }
fs/gfs2/inode.c +5 -5
@@ -633,18 +633,18 @@ static void munge_mode_uid_gid(struct gfs2_inode *dip, unsigned int *mode, (dip->i_inode.i_mode & S_ISUID) && dip->i_inode.i_uid) {if (S_ISDIR (*mode)) *mode |=S_ISUID ; -else if (dip->i_inode.i_uid != current->fsuid) +else if (dip->i_inode.i_uid != current->cred->uid) *mode &= ~07111 ; *uid = dip->i_inode.i_uid; } else - *uid = current->fsuid; + *uid = current->cred->uid;if (dip->i_inode.i_mode &S_ISGID ) {if (S_ISDIR (*mode)) *mode |=S_ISGID ; *gid = dip->i_inode.i_gid; }else - *gid = current->fsgid; + *gid = current->cred->gid; }static int alloc_dinode (struct gfs2_inode *dip,u64 *no_addr,u64 *generation)
@@ -1048,8 +1048,8 @@ int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,return -EPERM ;if ((dip->i_inode.i_mode &S_ISVTX ) && - dip->i_inode.i_uid != current->fsuid && - ip->i_inode.i_uid != current->fsuid && !capable (CAP_FOWNER )) + dip->i_inode.i_uid != current->cred->uid && + ip->i_inode.i_uid != current->cred->uid && !capable (CAP_FOWNER ))return -EPERM ;if (IS_APPEND (&dip->i_inode))
fs/hfs/inode.c +2 -2
@@ -151,8 +151,8 @@ struct inode *hfs_new_inode(struct inode *dir, struct qstr *name, int mode)hfs_cat_build_key (sb, (btree_key *)&HFS_I (inode)->cat_key, dir->i_ino, name); inode->i_ino =HFS_SB (sb)->next_id++; inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_nlink =1 ; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ;HFS_I (inode)->flags =0 ;
fs/hfsplus/inode.c +2 -2
@@ -308,8 +308,8 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode) inode->i_ino =HFSPLUS_SB (sb).next_cnid++; inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_nlink =1 ; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ;INIT_LIST_HEAD (&HFSPLUS_I (inode).open_dir_list);
fs/hpfs/namei.c +12 -12
@@ -92,11 +92,11 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)inc_nlink (dir);insert_inode_hash (result); -if (result->i_uid != current->fsuid || - result->i_gid != current->fsgid || +if (result->i_uid != current->cred->uid || + result->i_gid != current->cred->gid || result->i_mode != (mode |S_IFDIR )) { - result->i_uid = current->fsuid; - result->i_gid = current->fsgid; + result->i_uid = current->cred->uid; + result->i_gid = current->cred->gid; result->i_mode = mode |S_IFDIR ;hpfs_write_inode_nolock (result); }
@@ -184,11 +184,11 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, int mode, strucinsert_inode_hash (result); -if (result->i_uid != current->fsuid || - result->i_gid != current->fsgid || +if (result->i_uid != current->cred->uid || + result->i_gid != current->cred->gid || result->i_mode != (mode |S_IFREG )) { - result->i_uid = current->fsuid; - result->i_gid = current->fsgid; + result->i_uid = current->cred->uid; + result->i_gid = current->cred->gid; result->i_mode = mode |S_IFREG ;hpfs_write_inode_nolock (result); }
@@ -247,8 +247,8 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t result->i_mtime.tv_nsec =0 ; result->i_atime.tv_nsec =0 ;hpfs_i (result)->i_ea_size =0 ; - result->i_uid = current->fsuid; - result->i_gid = current->fsgid; + result->i_uid = current->cred->uid; + result->i_gid = current->cred->gid; result->i_nlink =1 ; result->i_size =0 ; result->i_blocks =1 ;
@@ -325,8 +325,8 @@ static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *sy result->i_atime.tv_nsec =0 ;hpfs_i (result)->i_ea_size =0 ; result->i_mode =S_IFLNK |0777 ; - result->i_uid = current->fsuid; - result->i_gid = current->fsgid; + result->i_uid = current->cred->uid; + result->i_gid = current->cred->gid; result->i_blocks =1 ; result->i_nlink =1 ; result->i_size =strlen (symlink);
fs/hugetlbfs/inode.c +8 -8
@@ -422,9 +422,9 @@ static int hugetlbfs_mknod(struct inode *dir,if (S_ISDIR (mode)) mode |=S_ISGID ; }else { - gid = current->fsgid; + gid = current->cred->gid; } - inode =hugetlbfs_get_inode (dir->i_sb, current->fsuid, gid, mode, dev); + inode =hugetlbfs_get_inode (dir->i_sb, current->cred->uid, gid, mode, dev);if (inode) { dir->i_ctime = dir->i_mtime =CURRENT_TIME ;d_instantiate (dentry, inode);
@@ -457,9 +457,9 @@ static int hugetlbfs_symlink(struct inode *dir,if (dir->i_mode &S_ISGID ) gid = dir->i_gid;else - gid = current->fsgid; + gid = current->cred->gid; - inode =hugetlbfs_get_inode (dir->i_sb, current->fsuid, + inode =hugetlbfs_get_inode (dir->i_sb, current->cred->uid, gid,S_IFLNK |S_IRWXUGO ,0 );if (inode) {int l =strlen (symname)+1 ;
@@ -697,8 +697,8 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent) config.nr_blocks =-1 ;/* No limit on size by default */ config.nr_inodes =-1 ;/* No limit on number of inodes by default */ - config.uid = current->fsuid; - config.gid = current->fsgid; + config.uid = current->cred->uid; + config.gid = current->cred->gid; config.mode =0755 ; ret =hugetlbfs_parse_options (data, &config);if (ret)
@@ -816,8 +816,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size) goto out_dentry; error = -ENOSPC ; - inode =hugetlbfs_get_inode (root->d_sb, current->fsuid, - current->fsgid,S_IFREG |S_IRWXUGO ,0 ); + inode =hugetlbfs_get_inode (root->d_sb, current->cred->uid, + current->cred->gid,S_IFREG |S_IRWXUGO ,0 );if (!inode) goto out_file;
fs/jffs2/fs.c +2 -2
@@ -422,14 +422,14 @@ struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_imemset (ri,0 ,sizeof (*ri));/* Set OS-specific defaults for new inodes */ - ri->uid =cpu_to_je16 (current->fsuid); + ri->uid =cpu_to_je16 (current->cred->uid);if (dir_i->i_mode &S_ISGID ) { ri->gid =cpu_to_je16 (dir_i->i_gid);if (S_ISDIR (mode)) mode |=S_ISGID ; }else { - ri->gid =cpu_to_je16 (current->fsgid); + ri->gid =cpu_to_je16 (current->cred->gid); } ri->mode =cpu_to_jemode (mode); ret =jffs2_do_new_inode (c, f, mode, ri);
fs/jfs/jfs_inode.c +2 -2
@@ -93,13 +93,13 @@ struct inode *ialloc(struct inode *parent, umode_t mode)return ERR_PTR (rc); } - inode->i_uid = current->fsuid; + inode->i_uid = current->cred->uid;if (parent->i_mode &S_ISGID ) { inode->i_gid = parent->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; }else - inode->i_gid = current->fsgid; + inode->i_gid = current->cred->gid;/* * New inodes need to save sane values on disk when
fs/minix/bitmap.c +2 -2
@@ -262,8 +262,8 @@ struct inode * minix_new_inode(const struct inode * dir, int * error)iput (inode);return NULL ; } - inode->i_uid = current->fsuid; - inode->i_gid = (dir->i_mode &S_ISGID ) ? dir->i_gid : current->fsgid; +if (dir->i_mode &S_ISGID ) + inode->i_gid = dir->i_gid; inode->i_ino = j; inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ; inode->i_blocks =0 ;
fs/nfsd/auth.c +21 -11
@@ -29,9 +29,13 @@ int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)int nfsd_setuser (struct svc_rqst *rqstp,struct svc_export *exp) {struct svc_cred cred = rqstp->rq_cred; +struct cred *vfscred;int i;int flags =nfsexp_flags (rqstp, exp); -int ret; + + vfscred =dup_cred (current->cred); +if (!vfscred) +return -ENOMEM ;if (flags &NFSEXP_ALLSQUASH ) { cred.cr_uid = exp->ex_anon_uid;
@@ -55,24 +59,30 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp) }else get_group_info (cred.cr_group_info); +if (!cred.cr_group_info) { +put_cred (vfscred); +return -ENOMEM ; + } +if (cred.cr_uid != (uid_t) -1 ) - current->fsuid = cred.cr_uid; +change_fsuid (vfscred, cred.cr_uid);else - current->fsuid = exp->ex_anon_uid; +change_fsuid (vfscred, exp->ex_anon_uid);if (cred.cr_gid != (gid_t) -1 ) - current->fsgid = cred.cr_gid; +change_fsgid (vfscred, cred.cr_gid);else - current->fsgid = exp->ex_anon_gid; +change_fsgid (vfscred, exp->ex_anon_gid); -if (!cred.cr_group_info) -return -ENOMEM ; - ret =set_current_groups (cred.cr_group_info); +change_groups (vfscred, cred.cr_group_info);put_group_info (cred.cr_group_info);if ((cred.cr_uid)) { -cap_t (current->cap_effective) &= ~CAP_NFSD_MASK ; +cap_t (vfscred->cap_effective) &= ~CAP_NFSD_MASK ; }else { -cap_t (current->cap_effective) |= (CAP_NFSD_MASK & +cap_t (vfscred->cap_effective) |= (CAP_NFSD_MASK & current->cap_permitted); } -return ret; + + current->_cap_effective = vfscred->cap_effective; +set_current_cred (vfscred); +return 0 ; }
fs/nfsd/nfs4callback.c +9 -7
@@ -349,19 +349,21 @@ static struct rpc_version * nfs_cb_version[] = {static struct rpc_cred *nfsd4_lookupcred (struct nfs4_client *clp,int taskflags) { -struct auth_cred acred; +struct cred *acred;struct rpc_clnt *clnt = clp->cl_callback.cb_client;struct rpc_cred *ret; -get_group_info (clp->cl_cred.cr_group_info); - acred.uid = clp->cl_cred.cr_uid; - acred.gid = clp->cl_cred.cr_gid; - acred.group_info = clp->cl_cred.cr_group_info; + acred =dup_cred (&init_cred); +if (!acred) +return ERR_PTR (-ENOMEM ); +change_fsuid (acred, clp->cl_cred.cr_uid); +change_fsgid (acred, clp->cl_cred.cr_gid); +change_groups (acred, clp->cl_cred.cr_group_info);dprintk ("NFSD: looking up %s cred\n" , clnt->cl_auth->au_ops->au_name); - ret =rpcauth_lookup_credcache (clnt->cl_auth, &acred, taskflags); -put_group_info (clp->cl_cred.cr_group_info); + ret =rpcauth_lookup_credcache (clnt->cl_auth, acred, taskflags); +put_cred (acred);return ret; }
fs/nfsd/nfs4recover.c +28 -26
131 lines not on this page · raw message
fs/nfsd/vfs.c +1 -1
@@ -1875,7 +1875,7 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,* with NFSv3. */ if ((acc &MAY_OWNER_OVERRIDE ) && - inode->i_uid == current->fsuid) + inode->i_uid == current->cred->uid)return 0 ; err =permission (inode, acc & (MAY_READ |MAY_WRITE |MAY_EXEC ),NULL );
fs/ocfs2/dlm/dlmfs.c +0 -4
@@ -329,8 +329,6 @@ static struct inode *dlmfs_get_root_inode(struct super_block *sb) ip =DLMFS_I (inode); inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
@@ -355,8 +353,6 @@ static struct inode *dlmfs_get_inode(struct inode *parent,return NULL ; inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; inode->i_blocks =0 ; inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
fs/ocfs2/namei.c +2 -2
@@ -542,13 +542,13 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb, fe->i_blkno =cpu_to_le64 (fe_blkno); fe->i_suballoc_bit =cpu_to_le16 (suballoc_bit); fe->i_suballoc_slot =cpu_to_le16 (osb->slot_num); - fe->i_uid =cpu_to_le32 (current->fsuid); + fe->i_uid =cpu_to_le32 (current->cred->uid);if (dir->i_mode &S_ISGID ) { fe->i_gid =cpu_to_le32 (dir->i_gid);if (S_ISDIR (mode)) mode |=S_ISGID ; }else - fe->i_gid =cpu_to_le32 (current->fsgid); + fe->i_gid =cpu_to_le32 (current->cred->gid); fe->i_mode =cpu_to_le16 (mode);if (S_ISCHR (mode) ||S_ISBLK (mode)) fe->id1.dev1.i_rdev =cpu_to_le64 (huge_encode_dev (dev));
fs/reiserfs/namei.c +0 -3
@@ -582,7 +582,6 @@ static int new_inode_init(struct inode *inode, struct inode *dir, int mode)/* the quota init calls have to know who to charge the quota to, so ** we have to set uid and gid here */ - inode->i_uid = current->fsuid; inode->i_mode = mode;/* Make inode invalid - just in case we are going to drop it before * the initialization happens */
@@ -592,8 +591,6 @@ static int new_inode_init(struct inode *inode, struct inode *dir, int mode) inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) inode->i_mode |=S_ISGID ; - }else { - inode->i_gid = current->fsgid; }DQUOT_INIT (inode);return 0 ;
fs/sysv/ialloc.c +1 -3
@@ -164,10 +164,8 @@ struct inode * sysv_new_inode(const struct inode * dir, mode_t mode) inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; - }else - inode->i_gid = current->fsgid; + } - inode->i_uid = current->fsuid; inode->i_ino =fs16_to_cpu (sbi, ino); inode->i_mtime = inode->i_atime = inode->i_ctime =CURRENT_TIME_SEC ; inode->i_blocks =0 ;
fs/udf/ialloc.c +0 -3
@@ -105,13 +105,10 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)mark_buffer_dirty (UDF_SB_LVIDBH (sb)); } inode->i_mode = mode; - inode->i_uid = current->fsuid;if (dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) mode |=S_ISGID ; - }else { - inode->i_gid = current->fsgid; }UDF_I_LOCATION (inode).logicalBlockNum = block;
fs/udf/namei.c +0 -1
@@ -636,7 +636,6 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,if (!inode) goto out; - inode->i_uid = current->fsuid;init_special_inode (inode, mode, rdev);if (!(fi =udf_add_entry (dir, dentry, &fibh, &cfi, &err))) { inode->i_nlink--;
fs/ufs/ialloc.c +1 -3
@@ -303,13 +303,11 @@ cg_found: inode->i_ino = cg * uspi->s_ipg + bit; inode->i_mode = mode; - inode->i_uid = current->fsuid;if (dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;if (S_ISDIR (mode)) inode->i_mode |=S_ISGID ; - }else - inode->i_gid = current->fsgid; + } inode->i_blocks =0 ; inode->i_generation =0 ;
fs/xfs/linux-2.6/xfs_linux.h +2 -2
@@ -127,8 +127,8 @@#define current_cpu () (raw_smp_processor_id())#define current_pid () (current->pid) -#define current_fsuid (cred) (current->fsuid) -#define current_fsgid (cred) (current->fsgid) +#define current_fsuid (___cred) (current->cred->uid) +#define current_fsgid (___cred) (current->cred->gid)#define current_test_flags (f) (current->flags & (f))#define current_set_flags_nested (sp, f) \ (*(sp) = current->flags, current->flags |= (f))
fs/xfs/xfs_acl.c +3 -3
@@ -383,7 +383,7 @@ xfs_acl_allow_set( error =bhv_vop_getattr (vp, &va,0 ,NULL );if (error)return error; -if (va.va_uid != current->fsuid && !capable (CAP_FOWNER )) +if (va.va_uid != current->cred->uid && !capable (CAP_FOWNER ))return EPERM ;return error; }
@@ -457,13 +457,13 @@ xfs_acl_access(switch (fap->acl_entry[i].ae_tag) {case ACL_USER_OBJ : seen_userobj =1 ; -if (fuid != current->fsuid) +if (fuid != current->cred->uid)continue ; matched.ae_tag =ACL_USER_OBJ ; matched.ae_perm = allows;break ;case ACL_USER : -if (fap->acl_entry[i].ae_id != current->fsuid) +if (fap->acl_entry[i].ae_id != current->cred->uid)continue ; matched.ae_tag =ACL_USER ; matched.ae_perm = allows;
ipc/mqueue.c +2 -2
@@ -113,8 +113,8 @@ static struct inode *mqueue_get_inode(struct super_block *sb, int mode, inode =new_inode (sb);if (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_blocks =0 ; inode->i_mtime = inode->i_ctime = inode->i_atime =CURRENT_TIME ;
kernel/cpuset.c +2 -2
@@ -286,8 +286,8 @@ static struct inode *cpuset_new_inode(mode_t mode)if (inode) { inode->i_mode = mode; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; + inode->i_uid = current->cred->uid; + inode->i_gid = current->cred->gid; inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =CURRENT_TIME ; inode->i_mapping->backing_dev_info = &cpuset_backing_dev_info;
net/9p/client.c +1 -1
@@ -935,7 +935,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt) fid->rdir_fpos =0 ; fid->rdir_pos =0 ; fid->rdir_fcall =NULL ; - fid->uid = current->fsuid; + fid->uid = current->cred->uid; fid->clnt = clnt; fid->aux =NULL ;
net/ipv4/netfilter/ipt_LOG.c +2 -1
@@ -337,7 +337,8 @@ static void dump_packet(const struct nf_loginfo *info,if ((logflags &IPT_LOG_UID ) && !iphoff && skb->sk) {read_lock_bh (&skb->sk->sk_callback_lock);if (skb->sk->sk_socket && skb->sk->sk_socket->file) -printk ("UID=%u " , skb->sk->sk_socket->file->f_uid); +printk ("UID=%u " , + skb->sk->sk_socket->file->f_cred->uid);read_unlock_bh (&skb->sk->sk_callback_lock); }
net/ipv4/netfilter/ipt_owner.c +2 -2
@@ -37,13 +37,13 @@ match(const struct sk_buff *skb,return false;if (info->match &IPT_OWNER_UID ) { -if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ +if ((skb->sk->sk_socket->file->f_cred->uid != info->uid) ^ !!(info->invert &IPT_OWNER_UID ))return false; }if (info->match &IPT_OWNER_GID ) { -if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ +if ((skb->sk->sk_socket->file->f_cred->gid != info->gid) ^ !!(info->invert &IPT_OWNER_GID ))return false; }
net/ipv6/netfilter/ip6t_LOG.c +2 -1
@@ -362,7 +362,8 @@ static void dump_packet(const struct nf_loginfo *info,if ((logflags &IP6T_LOG_UID ) && recurse && skb->sk) {read_lock_bh (&skb->sk->sk_callback_lock);if (skb->sk->sk_socket && skb->sk->sk_socket->file) -printk ("UID=%u " , skb->sk->sk_socket->file->f_uid); +printk ("UID=%u " , + skb->sk->sk_socket->file->f_cred->uid);read_unlock_bh (&skb->sk->sk_callback_lock); } }
net/ipv6/netfilter/ip6t_owner.c +2 -2
@@ -39,12 +39,12 @@ match(const struct sk_buff *skb,return false;if (info->match &IP6T_OWNER_UID ) -if ((skb->sk->sk_socket->file->f_uid != info->uid) ^ +if ((skb->sk->sk_socket->file->f_cred->uid != info->uid) ^ !!(info->invert &IP6T_OWNER_UID ))return false;if (info->match &IP6T_OWNER_GID ) -if ((skb->sk->sk_socket->file->f_gid != info->gid) ^ +if ((skb->sk->sk_socket->file->f_cred->gid != info->gid) ^ !!(info->invert &IP6T_OWNER_GID ))return false;
net/netfilter/nfnetlink_log.c +1 -1
@@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,if (skb->sk) {read_lock_bh (&skb->sk->sk_callback_lock);if (skb->sk->sk_socket && skb->sk->sk_socket->file) { -__be32 uid =htonl (skb->sk->sk_socket->file->f_uid); +__be32 uid =htonl (skb->sk->sk_socket->file->f_cred->uid);/* need to unlock here since NFA_PUT may goto */ read_unlock_bh (&skb->sk->sk_callback_lock);NFA_PUT (inst->skb,NFULA_UID ,sizeof (uid), &uid);
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 6/24 CRED: Request a credential record for a kernel service
In reply to David HowellsRequest a credential record for the named kernel service. This produces a cred struct with appropriate DAC and MAC controls for effecting that service. It may be used to override the credentials on a task to do work on that task's behalf.
---
include/linux/cred.h | 2 + include/linux/security.h | 43 +++++++++++++++++++++++++++++ kernel/cred.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ security/dummy.c | 13 +++++++++ security/selinux/hooks.c | 47 ++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 0 deletions(-)
include/linux/cred.h +2 -0
@@ -51,6 +51,8 @@ extern void change_fsgid(struct cred *, gid_t);extern void change_groups (struct cred *,struct group_info *);extern void change_cap (struct cred *,kernel_cap_t );extern struct cred *dup_cred (const struct cred *); +extern struct cred *get_kernel_cred (const char *,struct task_struct *); +extern int change_create_files_as (struct cred *,struct inode *);/** * get_cred - Get an extra reference on a credentials record
include/linux/security.h +43 -0
67 lines not on this page · raw message
kernel/cred.c +68 -0
71 lines not on this page · raw message
security/dummy.c +13 -0
@@ -488,6 +488,17 @@ static void dummy_cred_destroy(struct cred *cred) { } +static int dummy_cred_kernel_act_as (struct cred *cred,const char *service, +struct task_struct *daemon) +{ +return 0 ; +} + +static int dummy_cred_create_files_as (struct cred *cred,struct inode *inode) +{ +return 0 ; +} +static int dummy_task_create (unsigned long clone_flags) {return 0 ;
@@ -1064,6 +1075,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, file_receive);set_to_dummy_if_null (ops, cred_dup);set_to_dummy_if_null (ops, cred_destroy); +set_to_dummy_if_null (ops, cred_kernel_act_as); +set_to_dummy_if_null (ops, cred_create_files_as);set_to_dummy_if_null (ops, task_create);set_to_dummy_if_null (ops, task_alloc_security);set_to_dummy_if_null (ops, task_free_security);
security/selinux/hooks.c +47 -0
59 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 7/24 FS-Cache: Release page->private after failed readahead
In reply to David HowellsThe attached patch causes read_cache_pages() to release page-private data on a page for which add_to_page_cache() fails or the filler function fails. This permits pages with caching references associated with them to be cleaned up.
The invalidatepage() address space op is called (indirectly) to do the honours.
---
mm/readahead.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-)
mm/readahead.c +38 -2
@@ -15,6 +15,7 @@#include <linux/backing-dev.h> #include <linux/task_io_accounting_ops.h> #include <linux/pagevec.h> +#include <linux/buffer_head.h> void default_unplug_io_fn (struct backing_dev_info *bdi,struct page *page) {
@@ -51,6 +52,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);#define list_to_page (head) (list_entry((head)->prev, struct page, lru)) +/* +* see if a page needs releasing upon read_cache_pages() failure +* - the caller of read_cache_pages() may have set PG_private before calling, +* such as the NFS fs marking pages that are cached locally on disk, thus we +* need to give the fs a chance to clean up in the event of an error +*/ +static void read_cache_pages_invalidate_page (struct address_space *mapping, +struct page *page) +{ +if (PagePrivate (page)) { +if (TestSetPageLocked (page)) +BUG (); + page->mapping = mapping; +do_invalidatepage (page,0 ); + page->mapping =NULL ; +unlock_page (page); + } +page_cache_release (page); +} + +/* +* release a list of pages, invalidating them first if need be +*/ +static void read_cache_pages_invalidate_pages (struct address_space *mapping, +struct list_head *pages) +{ +struct page *victim; + +while (!list_empty (pages)) { + victim =list_to_page (pages); +list_del (&victim->lru); +read_cache_pages_invalidate_page (mapping, victim); + } +} +/** * read_cache_pages - populate an address space with some pages & start reads against them * @mapping: the address_space
@@ -74,14 +110,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages, page =list_to_page (pages);list_del (&page->lru);if (add_to_page_cache (page, mapping, page->index,GFP_KERNEL )) { -page_cache_release (page); +read_cache_pages_invalidate_page (mapping, page);continue ; } ret =filler (data, page);if (!pagevec_add (&lru_pvec, page))__pagevec_lru_add (&lru_pvec);if (ret) { -put_pages_list (pages); +read_cache_pages_invalidate_pages (mapping, pages);break ; }task_io_account_read (PAGE_CACHE_SIZE );
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 8/24 FS-Cache: Recruit a couple of page flags for cache management
In reply to David HowellsRecruit a couple of page flags to aid in cache management. The following extra flags are defined:
(1) PG_fscache (PG_owner_priv_2)
The marked page is backed by a local cache and is pinning resources in the cache driver.
(2) PG_fscache_write (PG_owner_priv_3)
The marked page is being written to the local cache. The page may not be modified whilst this is in progress.
If PG_fscache is set, then things that checked for PG_private will now also check for that. This includes things like truncation and page invalidation. The function page_has_private() had been added to detect this.
---
fs/splice.c | 2 +- include/linux/page-flags.h | 30 +++++++++++++++++++++++++++++- include/linux/pagemap.h | 11 +++++++++++ mm/filemap.c | 16 ++++++++++++++++ mm/migrate.c | 2 +- mm/page_alloc.c | 3 +++ mm/readahead.c | 9 +++++---- mm/swap.c | 4 ++-- mm/swap_state.c | 4 ++-- mm/truncate.c | 10 +++++----- mm/vmscan.c | 2 +- 11 files changed, 76 insertions(+), 17 deletions(-)
fs/splice.c +1 -1
@@ -58,7 +58,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,*/ wait_on_page_writeback (page); -if (PagePrivate (page)) +if (page_has_private (page))try_to_release_page (page,GFP_KERNEL );/*
include/linux/page-flags.h +29 -1
@@ -83,19 +83,24 @@#define PG_private 11/* If pagecache, has fs-private data */ #define PG_writeback 12/* Page is under writeback */ +#define PG_owner_priv_2 13/* Owner use. If pagecache, fs may use */ #define PG_compound 14/* Part of a compound page */ #define PG_swapcache 15/* Swap page: swp_entry_t in private */ #define PG_mappedtodisk 16/* Has blocks allocated on-disk */ #define PG_reclaim 17/* To be reclaimed asap */ +#define PG_owner_priv_3 18/* Owner use. If pagecache, fs may use */ #define PG_buddy 19/* Page is free, on buddy lists */ /* PG_readahead is only used for file reads; PG_reclaim is only for writes */ #define PG_readahead PG_reclaim/* Reminder to do async read-ahead */ -/* PG_owner_priv_1 users should have descriptive aliases */ +/* PG_owner_priv_1/2/3 users should have descriptive aliases */ #define PG_checked PG_owner_priv_1/* Used by some filesystems */ #define PG_pinned PG_owner_priv_1/* Xen pinned pagetable */ +#define PG_fscache PG_owner_priv_2/* Backed by local cache */ +#define PG_fscache_write PG_owner_priv_3/* Writing to local cache */ +#if (BITS_PER_LONG >32 )/*
@@ -199,6 +204,18 @@ static inline void SetPageUptodate(struct page *page)#define TestClearPageWriteback (page) test_and_clear_bit(PG_writeback, \ &(page)->flags) +#define PageFsCache (page) test_bit(PG_fscache, &(page)->flags) +#define SetPageFsCache (page) set_bit(PG_fscache, &(page)->flags) +#define ClearPageFsCache (page) clear_bit(PG_fscache, &(page)->flags) +#define TestSetPageFsCache (page) test_and_set_bit(PG_fscache, &(page)->flags) +#define TestClearPageFsCache (page) test_and_clear_bit(PG_fscache, &(page)->flags) + +#define PageFsCacheWrite (page) test_bit(PG_fscache_write, &(page)->flags) +#define SetPageFsCacheWrite (page) set_bit(PG_fscache_write, &(page)->flags) +#define ClearPageFsCacheWrite (page) clear_bit(PG_fscache_write, &(page)->flags) +#define TestSetPageFsCacheWrite (page) test_and_set_bit(PG_fscache_write, &(page)->flags) +#define TestClearPageFsCacheWrite (page) test_and_clear_bit(PG_fscache_write, &(page)->flags) +#define PageBuddy (page) test_bit(PG_buddy, &(page)->flags)#define __SetPageBuddy (page) __set_bit(PG_buddy, &(page)->flags)#define __ClearPageBuddy (page) __clear_bit(PG_buddy, &(page)->flags)
@@ -272,4 +289,15 @@ static inline void set_page_writeback(struct page *page) test_set_page_writeback(page); } +/** +* page_has_private - Determine if page has private stuff +* @page: The page to be checked +* +* Determine if a page has private stuff, indicating that release routines +* should be invoked upon it. +*/ +#define page_has_private (page) \ + ((page)->flags & ((1 << PG_private) | \ + (1 << PG_fscache))) +#endif /* PAGE_FLAGS_H */
include/linux/pagemap.h +11 -0
@@ -208,6 +208,17 @@ static inline void wait_on_page_writeback(struct page *page)extern void end_page_writeback (struct page *page); +/* +* Wait for a page to finish being written to a local cache +*/ +static inline void wait_on_page_fscache_write (struct page *page) +{ +if (PageFsCacheWrite (page)) +wait_on_page_bit (page, PG_fscache_write); +} + +extern void end_page_fscache_write (struct page *page); +/* * Fault a userspace page into pagetables. Return non-zero on a fault. *
mm/filemap.c +16 -0
@@ -557,6 +557,19 @@ void end_page_writeback(struct page *page)EXPORT_SYMBOL (end_page_writeback);/** +* end_page_fscache_write - End writing page to cache +* @page: the page +*/ +void end_page_fscache_write (struct page *page) +{ +if (!TestClearPageFsCacheWrite (page)) +BUG (); +smp_mb__after_clear_bit (); +wake_up_page (page, PG_fscache_write); +} +EXPORT_SYMBOL (end_page_fscache_write); + +/** * __lock_page - get a lock on the page, assuming we need to sleep to get it * @page: the page to lock *
@@ -2227,6 +2240,9 @@ out:* (presumably at page->private). If the release was successful, return `1'. * Otherwise return zero. * +* This may also be called if PG_fscache is set on a page, indicating that the +* page is known to the local caching routines. +* * The @gfp_mask argument specifies whether I/O may be performed to release * this page (__GFP_IO), and whether the call may block (__GFP_WAIT). *
mm/migrate.c +1 -1
@@ -544,7 +544,7 @@ static int fallback_migrate_page(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (PagePrivate (page) && +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return -EAGAIN ;
mm/page_alloc.c +3 -0
@@ -208,6 +208,7 @@ static void bad_page(struct page *page)dump_stack (); page->flags &= ~(1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_dirty |
@@ -445,6 +446,7 @@ static inline int free_pages_check(struct page *page) (page->flags & ( 1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_slab |
@@ -593,6 +595,7 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags) (page->flags & ( 1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_dirty |
mm/readahead.c +5 -4
@@ -54,14 +54,15 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);/* * see if a page needs releasing upon read_cache_pages() failure -* - the caller of read_cache_pages() may have set PG_private before calling, -* such as the NFS fs marking pages that are cached locally on disk, thus we -* need to give the fs a chance to clean up in the event of an error +* - the caller of read_cache_pages() may have set PG_private or PG_fscache +* before calling, such as the NFS fs marking pages that are cached locally +* on disk, thus we need to give the fs a chance to clean up in the event of +* an error */ static void read_cache_pages_invalidate_page (struct address_space *mapping,struct page *page) { -if (PagePrivate (page)) { +if (page_has_private (page)) {if (TestSetPageLocked (page))BUG (); page->mapping = mapping;
mm/swap.c +2 -2
@@ -412,8 +412,8 @@ void pagevec_strip(struct pagevec *pvec)for (i =0 ; i <pagevec_count (pvec); i++) {struct page *page = pvec->pages[i]; -if (PagePrivate (page) && !TestSetPageLocked (page)) { -if (PagePrivate (page)) +if (page_has_private (page) && !TestSetPageLocked (page)) { +if (page_has_private (page))try_to_release_page (page,0 );unlock_page (page); }
mm/swap_state.c +2 -2
@@ -75,7 +75,7 @@ static int __add_to_swap_cache(struct page *page, swp_entry_t entry,int error;BUG_ON (PageSwapCache (page)); -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page)); error =radix_tree_preload (gfp_mask);if (!error) {write_lock_irq (&swapper_space.tree_lock);
@@ -126,7 +126,7 @@ void __delete_from_swap_cache(struct page *page)BUG_ON (!PageLocked (page));BUG_ON (!PageSwapCache (page));BUG_ON (PageWriteback (page)); -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page));radix_tree_delete (&swapper_space.page_tree,page_private (page));set_page_private (page,0 );
mm/truncate.c +5 -5
@@ -48,7 +48,7 @@ void do_invalidatepage(struct page *page, unsigned long offset)static inline void truncate_partial_page (struct page *page,unsigned partial) {zero_user_page (page, partial,PAGE_CACHE_SIZE - partial,KM_USER0 ); -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page, partial); }
@@ -97,7 +97,7 @@ truncate_complete_page(struct address_space *mapping, struct page *page)cancel_dirty_page (page,PAGE_CACHE_SIZE ); -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page,0 );remove_from_page_cache (page);
@@ -122,7 +122,7 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (page_has_private (page) && !try_to_release_page (page,0 ))return 0 ; ret =remove_mapping (mapping, page);
@@ -344,14 +344,14 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;write_lock_irq (&mapping->tree_lock);if (PageDirty (page)) goto failed; -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page));__remove_from_page_cache (page);write_unlock_irq (&mapping->tree_lock);ClearPageUptodate (page);
mm/vmscan.c +1 -1
@@ -578,7 +578,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,* process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. */ -if (PagePrivate (page)) { +if (page_has_private (page)) {if (!try_to_release_page (page, sc->gfp_mask)) goto activate_locked;if (!mapping &&page_count (page) ==1 )
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 9/24 FS-Cache: Provide an add_wait_queue_tail() function
In reply to David HowellsProvide an add_wait_queue_tail() function to add a waiter to the back of a wait queue instead of the front.
---
include/linux/wait.h | 1 + kernel/wait.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
include/linux/wait.h +1 -0
@@ -118,6 +118,7 @@ static inline int waitqueue_active(wait_queue_head_t *q)#define is_sync_wait (wait) (!(wait) || ((wait)->private))extern void FASTCALL (add_wait_queue (wait_queue_head_t *q,wait_queue_t * wait)); +extern void FASTCALL (add_wait_queue_tail (wait_queue_head_t *q,wait_queue_t * wait));extern void FASTCALL (add_wait_queue_exclusive (wait_queue_head_t *q,wait_queue_t * wait));extern void FASTCALL (remove_wait_queue (wait_queue_head_t *q,wait_queue_t * wait));
kernel/wait.c +18 -0
@@ -29,6 +29,24 @@ void fastcall add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait) }EXPORT_SYMBOL (add_wait_queue); +/** +* add_wait_queue_tail - Add a waiter to the back of a waitqueue +* @q: the wait queue to append the waiter to +* @wait: the waiter to be queued +* +* Add a waiter to the back of a waitqueue so that it gets woken up last. +*/ +void fastcall add_wait_queue_tail(wait_queue_head_t *q, wait_queue_t *wait) +{ +unsigned long flags; + + wait->flags &= ~WQ_FLAG_EXCLUSIVE ; +spin_lock_irqsave (&q->lock, flags); +__add_wait_queue_tail (q, wait); +spin_unlock_irqrestore (&q->lock, flags); +} +EXPORT_SYMBOL (add_wait_queue_tail); + void fastcall add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait) {unsigned long flags;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 10/24 FS-Cache: Generic filesystem caching facility
In reply to David HowellsThe attached patch adds a generic intermediary (FS-Cache) by which filesystems may call on local caching capabilities, and by which local caching backends may make caches available:
+---------+ | | +--------------+ | NFS |--+ | | | | | +-->| CacheFS | +---------+ | +----------+ | | /dev/hda5 | | | | | +--------------+ +---------+ +-->| | | | | | |--+ | AFS |----->| FS-Cache | | | | |--+ +---------+ +-->| | | | | | | +--------------+ +---------+ | +----------+ | | | | | | +-->| CacheFiles | | ISOFS |--+ | /var/cache | | | +--------------+ +---------+
The patch also documents the netfs interface and the cache backend interface provided by the facility.
There are a number of reasons why I'm not using i_mapping to do this. These have been discussed a lot on the LKML and CacheFS mailing lists, but to summarise the basics:
(1) Most filesystems don't do hole reportage. Holes in files are treated as blocks of zeros and can't be distinguished otherwise, making it difficult to distinguish blocks that have been read from the network and cached from those that haven't.
(2) The backing inode must be fully populated before being exposed to userspace through the main inode because the VM/VFS goes directly to the backing inode and does not interrogate the front inode on VM ops.
Therefore:
(a) The backing inode must fit entirely within the cache.
(b) All backed files currently open must fit entirely within the cache at the same time.
(c) A working set of files in total larger than the cache may not be cached.
(d) A file may not grow larger than the available space in the cache.
(e) A file that's open and cached, and remotely grows larger than the cache is potentially stuffed.
(3) Writes go to the backing filesystem, and can only be transferred to the network when the file is closed.
(4) There's no record of what changes have been made, so the whole file must be written back.
(5) The pages belong to the backing filesystem, and all metadata associated with that page are relevant only to the backing filesystem, and not anything stacked atop it.
The attached patch adds a generic core to which both networking filesystems and caches may bind. It transfers requests from networking filesystems to appropriate caches if possible, or else gracefully denies them.
If this facility is disabled in the kernel configuration, then all its operations will be trivially reducible to nothing by the compiler.
FS-Cache provides the following facilities:
(1) Caches can be added / removed at any time, even whilst in use.
(2) Adds a facility by which tags can be used to refer to caches, even if they're not mounted yet.
(3) More than one cache can be used at once. Caches can be selected explicitly by use of tags.
(4) The netfs is provided with an interface that allows either party to withdraw caching facilities from a file (required for (1)).
(5) A netfs may annotate cache objects that belongs to it.
(6) Cache objects can be pinned and reservations made.
(7) The interface to the netfs returns as few errors as possible, preferring rather to let the netfs remain oblivious.
(8) Cookies are used to represent indices, files and other objects to the netfs. The simplest cookie is just a NULL pointer - indicating nothing cached there.
(9) The netfs is allowed to propose - dynamically - any index hierarchy it desires, though it must be aware that the index search function is recursive, stack space is limited, and indices can only be children of indices.
(10) Indices can be used to group files together to reduce key size and to make group invalidation easier. The use of indices may make lookup quicker, but that's cache dependent.
(11) Data I/O is effectively done directly to and from the netfs's pages. The netfs indicates that page A is at index B of the data-file represented by cookie C, and that it should be read or written. The cache backend may or may not start I/O on that page, but if it does, a netfs callback will be invoked to indicate completion. The I/O may be either synchronous or asynchronous.
(12) Cookies can be "retired" upon release. At this point FS-Cache will mark them as obsolete and the index hierarchy rooted at that point will get recycled.
(13) The netfs provides a "match" function for index searches. In addition to saying whether a match was made or not, this can also specify that an entry should be updated or deleted.
FS-Cache maintains a virtual indexing tree in which all indices, files, objects and pages are kept. Bits of this tree may actually reside in one or more caches.
FSDEF
|
+------------------------------------+
| |
NFS AFS
| |
+--------------------------+ +-----------+
| | | |
homedir mirror afs.org redhat.com
| | |
+------------+ +---------------+ +----------+
| | | | | |
00001 00002 00007 00125 vol00001 vol00002
| | | | |
+---+---+ +-----+ +---+ +------+------+ +-----+----+
| | | | | | | | | | | | |
PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
| |
PG0 +-------+
| |
00001 00003
|
+---+---+
| | |
PG0 PG1 PG2In the example above, you can see two netfs's being backed: NFS and AFS. These have different index hierarchies:
(*) The NFS primary index will probably contain per-server indices. Each
server index is indexed by NFS file handles to get data file objects. Each data file objects can have an array of pages, but may also have further child objects, such as extended attributes and directory entries. Extended attribute objects themselves have page-array contents.
(*) The AFS primary index contains per-cell indices. Each cell index contains
per-logical-volume indices. Each of volume index contains up to three indices for the read-write, read-only and backup mirrors of those volumes. Each of these contains vnode data file objects, each of which contains an array of pages.
The very top index is the FS-Cache master index in which individual netfs's have entries.
Any index object may reside in more than one cache, provided it only has index children. Any index with non-index object children will be assumed to only reside in one cache.
The FS-Cache overview can be found in:
Documentation/filesystems/caching/fscache.txt
The netfs API to FS-Cache can be found in:
Documentation/filesystems/caching/netfs-api.txt
The cache backend API to FS-Cache can be found in:
Documentation/filesystems/caching/backend-api.txt
---
Documentation/filesystems/caching/backend-api.txt | 625 +++++++++++++++ Documentation/filesystems/caching/fscache.txt | 295 +++++++ Documentation/filesystems/caching/netfs-api.txt | 741 ++++++++++++++++++ fs/Kconfig | 6 fs/Makefile | 1 fs/fscache/Kconfig | 49 + fs/fscache/Makefile | 19 fs/fscache/fsc-cache.c | 512 ++++++++++++ fs/fscache/fsc-cookie.c | 494 ++++++++++++ fs/fscache/fsc-fsdef.c | 111 +++ fs/fscache/fsc-internal.h | 376 +++++++++ fs/fscache/fsc-main.c | 127 +++ fs/fscache/fsc-manage.c | 260 ++++++ fs/fscache/fsc-object.c | 586 ++++++++++++++ fs/fscache/fsc-page.c | 866 +++++++++++++++++++++ fs/fscache/fsc-proc.c | 399 ++++++++++ fs/fscache/fsc-stats.c | 103 ++ fs/fscache/fsc-threads.c | 590 ++++++++++++++ include/linux/fscache-cache.h | 433 +++++++++++ include/linux/fscache.h | 593 ++++++++++++++ 20 files changed, 7186 insertions(+), 0 deletions(-)
Documentation/filesystems/caching/backend-api.txt new file +625 -0
@@ -0,0 +1,625 @@ + ========================== + FS-CACHE CACHE BACKEND API + ========================== + +The FS-Cache system provides an API by which actual caches can be supplied to +FS-Cache for it to then serve out to network filesystems and other interested +parties. + +This API is declared in <linux/fscache-cache.h>. + + +==================================== +INITIALISING AND REGISTERING A CACHE +==================================== + +To start off, a cache definition must be initialised and registered for each +cache the backend wants to make available. For instance, CacheFS does this in +the fill_super() operation on mounting. + +The cache definition (struct fscache_cache) should be initialised by calling: + + void fscache_init_cache(struct fscache_cache *cache, + struct fscache_cache_ops *ops, + const char *idfmt, + ...); + +Where: + + (*) "cache" is a pointer to the cache definition; + + (*) "ops" is a pointer to the table of operations that the backend supports on + this cache; and + + (*) "idfmt" is a format and printf-style arguments for constructing a label + for the cache. + + +The cache should then be registered with FS-Cache by passing a pointer to the +previously initialised cache definition to: + + int fscache_add_cache(struct fscache_cache *cache, + struct fscache_object *fsdef, + const char *tagname); + +Two extra arguments should also be supplied: + + (*) "fsdef" which should point to the object representation for the FS-Cache + master index in this cache. Netfs primary index entries will be created + here. + + (*) "tagname" which, if given, should be a text string naming this cache. If + this is NULL, the identifier will be used instead. For CacheFS, the + identifier is set to name the underlying block device and the tag can be + supplied by mount. + +This function may return -ENOMEM if it ran out of memory or -EEXIST if the tag +is already in use. 0 will be returned on success. + + +===================== +UNREGISTERING A CACHE +===================== + +A cache can be withdrawn from the system by calling this function with a +pointer to the cache definition: + + void fscache_withdraw_cache(struct fscache_cache *cache); + +In CacheFS's case, this is called by put_super(). + + +======== +SECURITY +======== + +The cache methods are executed one of two contexts: + + (1) that of the userspace process that issued the netfs operation that caused + the cache method to be invoked, or + + (2) that of one of the processes in the FS-Cache thread pool. + +In either case, this may not be an appropriate context in which to access the +cache. + +The calling process's fsuid, fsgid and SELinux security identities may need to +be masqueraded for the duration of the cache driver's access to the cache. +This is left to the cache to handle; FS-Cache makes no effort in this regard. + + +=================================== +CONTROL AND STATISTICS PRESENTATION +=================================== + +The cache may present data to the outside world through FS-Cache's interfaces +in sysfs and procfs - the former for control and the latter for statistics. + +A sysfs directory called /sys/fs/fscache/<cachetag>/ is created if CONFIG_SYSFS +is enabled. This is accessible through the kobject struct fscache_cache::kobj +and is for use by the cache as it sees fit. + +The cache driver may create itself a directory named for the cache type in the +/proc/fs/fscache/ directory. This is available if CONFIG_FSCACHE_PROC is +enabled and is accessible through: + + struct proc_dir_entry *proc_fscache; + + +======================== +RELEVANT DATA STRUCTURES +======================== + + (*) Index/Data file FS-Cache representation cookie: + + struct fscache_cookie { + struct fscache_object_def *def; + struct fscache_netfs *netfs; + void *netfs_data; + ... + }; + + The fields that might be of use to the backend describe the object + definition, the netfs definition and the netfs's data for this cookie. + The object definition contain functions supplied by the netfs for loading + and matching index entries; these are required to provide some of the + cache operations. + + + (*) In-cache object representation: + + struct fscache_object { + int debug_id; + enum { + FSCACHE_OBJECT_RECYCLING, + ... + } state; + spinlock_t lock + struct fscache_cache *cache; + struct fscache_cookie *cookie; + ... + }; + + Structures of this type should be allocated by the cache backend and + passed to FS-Cache when requested by the appropriate cache operation. In + the case of CacheFS, they're embedded in CacheFS's internal object + structures. + + The debug_id is a simple integer that can be used in debugging messages + that refer to a particular object. In such a case it should be printed + using "OBJ%x" to be consistent with FS-Cache. + + Each object contains a pointer to the cookie that represents the object it + is backing. An object should retired when put_object() is called if it is + in state FSCACHE_OBJECT_RECYCLING. The fscache_object struct should be + initialised by calling fscache_object_init(object). + + + (*) FS-Cache operation record: + + struct fscache_operation { + atomic_t usage; + struct fscache_object *object; + unsigned long flags; + #define FSCACHE_OP_EXCLUSIVE + void (*processor)(struct fscache_operation *op); + void (*release)(struct fscache_operation *op); + ... + }; + + FS-Cache has a pool of threads that it uses to give CPU time to the + various asynchronous operations that need to be done as part of driving + the cache. These are represented by the above structure. The processor + method is called to give the op CPU time, and the release method to get + rid of it when its usage count reaches 0. + + An operation can be made exclusive upon an object by setting the + appropriate flag before enqueuing it with fscache_enqueue_operation(). If + an operation needs more processing time, it should be enqueued again. + + + (*) FS-Cache retrieval operation record: + + struct fscache_retrieval { + struct fscache_operation op; + struct address_space *mapping; + struct list_head *to_do; + ... + }; + + A structure of this type is allocated by FS-Cache to record retrieval and + allocation requests made by the netfs. This struct is then passed to the + backend to do the operation. The backend may get extra refs to it by + calling fscache_get_retrieval() and refs may be discarded by calling + fscache_put_retrieval(). + + A retrieval operation can be used by the backend to do retrieval work. To + do this, the retrieval->op.processor method pointer should be set + appropriately by the backend and fscache_enqueue_retrieval() called to + submit it to the thread pool. CacheFiles, for example, uses this to queue + page examination when it detects PG_lock being cleared. + + The to_do field is an empty list available for the cache backend to use as + it sees fit. + + + (*) FS-Cache storage operation record: + + struct fscache_storage { + struct fscache_operation op; + pgoff_t store_limit; + ... + }; + + A structure of this type is allocated by FS-Cache to record outstanding + writes to be made. FS-Cache itself enqueues this operation and invokes + the write_page() method on the object at appropriate times to effect + storage. + + +================ +CACHE OPERATIONS +================ + +The cache backend provides FS-Cache with a table of operations that can be +performed on the denizens of the cache. These are held in a structure of type: + + struct fscache_cache_ops + + (*) Name of cache provider [mandatory]: + + const char *name + + This isn't strictly an operation, but should be pointed at a string naming + the backend. + + + (*) Allocate a new object [mandatory]: + + struct fscache_object *(*alloc_object)(struct fscache_cache *cache, + struct fscache_cookie *cookie) + + This method is used to allocate a cache object representation to back a + cookie in a particular cache. fscache_object_init() should be called on + the object to initialise it prior to returning. + + This function may also be used to parse the index key to be used for + multiple lookup calls to turn it into a more convenient form. FS-Cache + will call the lookup_complete() method to allow the cache to release the + form once lookup is complete or aborted. + + + (*) Look up and create object [mandatory]: + + void (*lookup_object)(struct fscache_object *object) + + This method is used to look up an object, given that the object is already + allocated and attached to the cookie. This should instantiate that object + in the cache if it can. + + The method should call fscache_object_lookup_negative() as soon as + possible if it determines the object doesn't exist in the cache. If the + object is found to exist and the netfs indicates that it is valid then + fscache_obtained_object() should be called once the object is in a + position to have data stored in it. Similarly, fscache_obtained_object() + should also be called once a non-present object has been created. + + If a lookup error occurs, fscache_object_lookup_error() should be called + to abort the lookup of that object. + + + (*) Release lookup data [mandatory]: + + void (*lookup_complete)(struct fscache_object *object) + + This method is called to ask the cache to release any resources it was + using to perform a lookup. + + + (*) Increment object refcount [mandatory]: + + struct fscache_object *(*grab_object)(struct fscache_object *object) + + This method is called to increment the reference count on an object. It + may fail (for instance if the cache is being withdrawn) by returning NULL. + It should return the object pointer if successful. + + + (*) Lock/Unlock object [mandatory]: + + void (*lock_object)(struct fscache_object *object) + void (*unlock_object)(struct fscache_object *object) + + These methods are used to exclusively lock an object. It must be possible + to schedule with the lock held, so a spinlock isn't sufficient. + + + (*) Pin/Unpin object [optional]: + + int (*pin_object)(struct fscache_object *object) + void (*unpin_object)(struct fscache_object *object) + + These methods are used to pin an object into the cache. Once pinned an + object cannot be reclaimed to make space. Return -ENOSPC if there's not + enough space in the cache to permit this. + + + (*) Update object [mandatory]: + + int (*update_object)(struct fscache_object *object) + + This is called to update the index entry for the specified object. The + new information should be in object->cookie->netfs_data. This can be + obtained by calling object->cookie->def->get_aux()/get_attr(). + + + (*) Discard object [mandatory]: + + void (*drop_object)(struct fscache_object *object) + + This method is called to indicate that an object has been unbound from its + cookie, and that the cache should release the object's resources and + retire it if it's in state FSCACHE_OBJECT_RECYCLING. + + This method should not attempt to release any references held by the + caller. The caller will invoke the put_object() method as appropriate. + + + (*) Release object reference [mandatory]: + + void (*put_object)(struct fscache_object *object) + + This method is used to discard a reference to an object. The object may + be freed when all the references to it are released. + + + (*) Synchronise a cache [mandatory]: + + void (*sync)(struct fscache_cache *cache) + + This is called to ask the backend to synchronise a cache with its backing + device. + + + (*) Dissociate a cache [mandatory]: + + void (*dissociate_pages)(struct fscache_cache *cache) + + This is called to ask a cache to perform any page dissociations as part of + cache withdrawal. + + + (*) Notification that the attributes on a netfs file changed [mandatory]: + + int (*attr_changed)(struct fscache_object *object); + + This is called to indicate to the cache that certain attributes on a netfs + file have changed (for example the maximum size a file may reach). The + cache can read these from the netfs by calling the cookie's get_attr() + method. + + The cache may use the file size information to reserve space on the cache. + It should also call fscache_set_store_limit() to indicate to FS-Cache the + highest byte it's willing to store for an object. + + This method may return -ve if an error occurred or the cache object cannot + be expanded. In such a case, the object will be withdrawn from service. + + This operation is run asynchronously from FS-Cache's thread pool, and + storage and retrieval operations from the netfs are excluded during the + execution of this operation. + + + (*) Reserve cache space for an object's data [optional]: + + int (*reserve_space)(struct fscache_object *object, loff_t size); + + This is called to request that cache space be reserved to hold the data + for an object and the metadata used to track it. Zero size should be + taken as request to cancel a reservation. + + This should return 0 if successful, -ENOSPC if there isn't enough space + available, or -ENOMEM or -EIO on other errors. + + The reservation may exceed the current size of the object, thus permitting + future expansion. If the amount of space consumed by an object would + exceed the reservation, it's permitted to refuse requests to allocate + pages, but not required. An object may be pruned down to its reservation + size if larger than that already. + + + (*) Request page be read from cache [mandatory]: + + int (*read_or_alloc_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is called to attempt to read a netfs page from the cache, or to + reserve a backing block if not. FS-Cache will have done as much checking + as it can before calling, but most of the work belongs to the backend. + + If there's no page in the cache, then -ENODATA should be returned if the + backend managed to reserve a backing block; -ENOBUFS or -ENOMEM if it + didn't. + + If there is suitable data in the cache, then a read operation should be + queued and 0 returned. When the read finishes, fscache_end_io() should be + called. + + The fscache_mark_pages_cached() should be called for the page if any cache + metadata is retained. This will indicate to the netfs that the page needs + explicit uncaching. This operation takes a pagevec, thus allowing several + pages to be marked at once. + + The retrieval record pointed to by op should be retained for each page + queued and released when I/O on the page has been formally ended. + fscache_get/put_retrieval() are available for this purpose. + + The retrieval record may be used to get CPU time via the FS-Cache thread + pool. If this is desired, the op->op.processor should be set to point to + the appropriate processing routine, and fscache_enqueue_retrieval() should + be called at an appropriate point to request CPU time. For instance, the + retrieval routine could be enqueued upon the completion of a disk read. + The to_do field in the retrieval record is provided to aid in this. + + If an I/O error occurs, fscache_io_error() should be called and -ENOBUFS + returned if possible or fscache_end_io() called with a suitable error + code.. + + + (*) Request pages be read from cache [mandatory]: + + int (*read_or_alloc_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except it is handed a list + of pages instead of one page. Any pages on which a read operation is + started must be added to the page cache for the specified mapping and also + to the LRU. Such pages must also be removed from the pages list and + *nr_pages decremented per page. + + If there was an error such as -ENOMEM, then that should be returned; else + if one or more pages couldn't be read or allocated, then -ENOBUFS should + be returned; else if one or more pages couldn't be read, then -ENODATA + should be returned. If all the pages are dispatched then 0 should be + returned. + + + (*) Request page be allocated in the cache [mandatory]: + + int (*allocate_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except that it shouldn't + read from the cache, even if there's data there that could be retrieved. + It should, however, set up any internal metadata required such that + the write_page() method can write to the cache. + + If there's no backing block available, then -ENOBUFS should be returned + (or -ENOMEM if there were other problems). If a block is successfully + allocated, then the netfs page should be marked and 0 returned. + + + (*) Request pages be allocated in the cache [mandatory]: + + int (*allocate_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is an multiple page version of the allocate_page() method. pages and + nr_pages should be treated as for the read_or_alloc_pages() method. + + + (*) Request page be written to cache [mandatory]: + + int (*write_page)(struct fscache_storage *op, + struct page *page); + + This is called to write from a page on which there was a previously + successful read_or_alloc_page() call or similar. FS-Cache filters out + pages that don't have mappings. + + This method is called asynchronously from the FS-Cache thread pool. It is + not required to actually store anything, provided -ENODATA is then + returned to the next read of this page. + + If an error occurred, then a negative error code should be returned, + otherwise zero should be returned. FS-Cache will take appropriate action + in response to an error, such as withdrawing this object. + + If this method returns success then FS-Cache will inform the netfs + appropriately. + + + (*) Discard retained per-page metadata [mandatory]: + + void (*uncache_page)(struct fscache_object *object, struct page *page) + + This is called when a netfs page is being evicted from the pagecache. The + cache backend should tear down any internal representation or tracking it + maintains for this page. + + +================== +FS-CACHE UTILITIES +================== + +FS-Cache provides some utilities that a cache backend may make use of: + + (*) Note occurrence of an I/O error in a cache: + + void fscache_io_error(struct fscache_cache *cache) + + This tells FS-Cache that an I/O error occurred in the cache. After this + has been called, only resource dissociation operations (object and page + release) will be passed from the netfs to the cache backend for the + specified cache. + + This does not actually withdraw the cache. That must be done separately. + + + (*) Invoke the retrieval I/O completion function: + + void fscache_end_io(struct fscache_retrieval *op, struct page *page, + int error); + + This is called to note the end of an attempt to retrieve a page. The + error value should be 0 if successful and an error otherwise. + + + (*) Set highest store limit: + + void fscache_set_store_limit(struct fscache_object *object, + loff_t i_size); + + This sets the limit FS-Cache imposes on the highest byte it's willing to + try and store for a netfs. Any page over this limit is automatically + rejected by fscache_read_alloc_page() and co with -ENOBUFS. + + + (*) Mark pages as being cached: + + void fscache_mark_pages_cached(struct fscache_retrieval *op, + struct pagevec *pagevec); + + This marks a set of pages as being cached. After this has been called, + the netfs must call fscache_uncache_page() to unmark the pages. + + + (*) Initialise a freshly allocated object: + + void fscache_object_init(struct fscache_object *object); + + This initialises all the fields in an object representation. + + + (*) Indicate negative lookup on an object: + + void fscache_object_lookup_negative(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + found a negative result. + + This changes the state of an object to permit reads pending on lookup + completion to go off and start fetching data from the netfs server as it's + known at this point that there can't be any data in the cache. + + This may be called multiple times on an object. Only the first call is + significant - all subsequent calls are ignored. + + + (*) Indicate an object has been obtained: + + void fscache_obtained_object(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + produced a positive result, or that an object was created. This should + only be called once for any particular object. + + This changes the state of an object to indicate: + + (1) if no call to fscache_object_lookup_negative() has been made on + this object, that there may be data available, and that reads can + now go and look for it; and + + (2) that writes may now proceed against this object. + + + (*) Indicate that object lookup failed: + + void fscache_object_lookup_error(struct fscache_object *object); + + This marks an object as having encountered a fatal error (usually EIO) + and causes it to move into a state whereby it will be withdrawn as soon + as possible. + + + (*) Get and release references on a retrieval record: + + void fscache_get_retrieval(struct fscache_retrieval *op); + void fscache_put_retrieval(struct fscache_retrieval *op); + + These two functions are used to retain a retrieval record whilst doing + asynchronous data retrieval and block allocation. + + + (*) Enqueue a retrieval record for processing. + + void fscache_enqueue_retrieval(struct fscache_retrieval *op); + + This enqueues a retrieval record for processing by the FS-Cache thread + pool. One of the threads in the pool will invoke the retrieval record's + op->op.processor callback function. This function may be called from + within the callback function. + + + (*) List of object state names: + + const char *fscache_object_states[]; + + For debugging purposes, this may be used to turn the state that an object + is in into a text string for display purposes.
Documentation/filesystems/caching/fscache.txt new file +295 -0
295 lines not on this page · raw message
Documentation/filesystems/caching/netfs-api.txt new file +741 -0
741 lines not on this page · raw message
fs/Kconfig +6 -0
@@ -628,6 +628,12 @@ config GENERIC_ACL bool select FS_POSIX_ACL +menu "Caches" + +source "fs/fscache/Kconfig" + +endmenu + if BLOCK menu "CD-ROM/DVD Filesystems"
fs/Makefile +1 -0
@@ -65,6 +65,7 @@ obj-$(CONFIG_PROFILING) += dcookies.o obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line +obj-$(CONFIG_FSCACHE) += fscache/ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 obj-$(CONFIG_EXT4DEV_FS) += ext4/ # Before ext2 so root fs can be ext4dev
fs/fscache/Kconfig new file +49 -0
49 lines not on this page · raw message
fs/fscache/Makefile new file +19 -0
@@ -0,0 +1,19 @@ +# +# Makefile for general filesystem caching code +# + +fscache-y := \ + fsc-cache.o \ + fsc-cookie.o \ + fsc-fsdef.o \ + fsc-main.o \ + fsc-manage.o \ + fsc-object.o \ + fsc-page.o \ + fsc-threads.o + +fscache-$(CONFIG_FSCACHE_PROC) += \ + fsc-proc.o \ + fsc-stats.o + +obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/fsc-cache.c new file +512 -0
512 lines not on this page · raw message
fs/fscache/fsc-cookie.c new file +494 -0
494 lines not on this page · raw message
fs/fscache/fsc-fsdef.c new file +111 -0
111 lines not on this page · raw message
fs/fscache/fsc-internal.h new file +376 -0
135 lines not on this page · raw message
fs/fscache/fsc-main.c new file +127 -0
127 lines not on this page · raw message
fs/fscache/fsc-manage.c new file +260 -0
260 lines not on this page · raw message
fs/fscache/fsc-object.c new file +586 -0
586 lines not on this page · raw message
fs/fscache/fsc-page.c new file +866 -0
866 lines not on this page · raw message
fs/fscache/fsc-proc.c new file +399 -0
399 lines not on this page · raw message
fs/fscache/fsc-stats.c new file +103 -0
103 lines not on this page · raw message
fs/fscache/fsc-threads.c new file +590 -0
590 lines not on this page · raw message
include/linux/fscache-cache.h new file +433 -0
433 lines not on this page · raw message
include/linux/fscache.h new file +593 -0
593 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH 11/24 CacheFiles: Add missing copy_page export for ia64
In reply to David HowellsThis one-line patch fixes the missing export of copy_page introduced by the cachefile patches. This patch is not yet upstream, but is required for cachefile on ia64. It will be pushed upstream when cachefile goes upstream.
---
arch/ia64/kernel/ia64_ksyms.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/ia64/kernel/ia64_ksyms.c +1 -0
@@ -43,6 +43,7 @@ EXPORT_SYMBOL(__do_clear_user);EXPORT_SYMBOL (__strlen_user);EXPORT_SYMBOL (__strncpy_from_user);EXPORT_SYMBOL (__strnlen_user); +EXPORT_SYMBOL (copy_page);/* from arch/ia64/lib */ extern void __divsi3 (void );
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 12/24 CacheFiles: Add a hook to write a single page of data to an inode
In reply to David HowellsAdd an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised).
This is used by CacheFiles to store the contents of netfs pages into their backing file pages.
Supply a generic implementation for this that uses the prepare_write() and commit_write() address_space operations to bound a copy directly into the page cache.
Hook the Ext2 and Ext3 operations to the generic implementation.
---
fs/ext2/inode.c | 2 + fs/ext3/inode.c | 3 ++ include/linux/fs.h | 7 ++++ mm/filemap.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 0 deletions(-)
fs/ext2/inode.c +2 -0
@@ -695,6 +695,7 @@ const struct address_space_operations ext2_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };const struct address_space_operations ext2_aops_xip = {
@@ -713,6 +714,7 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };/*
fs/ext3/inode.c +3 -0
@@ -1713,6 +1713,7 @@ static const struct address_space_operations ext3_ordered_aops = { .releasepage = ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_writeback_aops = {
@@ -1727,6 +1728,7 @@ static const struct address_space_operations ext3_writeback_aops = { .releasepage = ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_journalled_aops = {
@@ -1740,6 +1742,7 @@ static const struct address_space_operations ext3_journalled_aops = { .bmap = ext3_bmap, .invalidatepage = ext3_invalidatepage, .releasepage = ext3_releasepage, + .write_one_page = generic_file_buffered_write_one_page, };void ext3_set_aops (struct inode *inode)
include/linux/fs.h +7 -0
@@ -434,6 +434,11 @@ struct address_space_operations {int (*migratepage) (struct address_space *,struct page *,struct page *);int (*launder_page) (struct page *); +/* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ +int (*write_one_page)(struct address_space *,pgoff_t ,struct page *); + };struct backing_dev_info ;
@@ -1669,6 +1674,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t);extern ssize_t generic_file_buffered_write (struct kiocb *,const struct iovec *,unsigned long ,loff_t ,loff_t *,size_t ,ssize_t ); +extern int generic_file_buffered_write_one_page (struct address_space *, +pgoff_t ,struct page *);extern ssize_t do_sync_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos);extern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos); extern void do_generic_mapping_read(struct address_space *mapping,
mm/filemap.c +95 -0
101 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 13/24 CacheFiles: Permit the page lock state to be monitored
In reply to David HowellsAdd a function to install a monitor on the page lock waitqueue for a particular page, thus allowing the page being unlocked to be detected.
This is used by CacheFiles to detect read completion on a page in the backing filesystem so that it can then copy the data to the waiting netfs page.
---
include/linux/pagemap.h | 5 +++++ mm/filemap.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
include/linux/pagemap.h +5 -0
@@ -220,6 +220,11 @@ static inline void wait_on_page_fscache_write(struct page *page)extern void end_page_fscache_write (struct page *page);/* +* Add an arbitrary waiter to a page's wait queue +*/ +extern void add_page_wait_queue (struct page *page,wait_queue_t *waiter); + +/* * Fault a userspace page into pagetables. Return non-zero on a fault. * * This assumes that two userspace pages are always sufficient. That's
mm/filemap.c +19 -0
@@ -518,6 +518,25 @@ void fastcall wait_on_page_bit(struct page *page, int bit_nr)EXPORT_SYMBOL (wait_on_page_bit);/** +* add_page_wait_queue - Add an arbitrary waiter to a page's wait queue +* @page - Page defining the wait queue of interest +* @waiter - Waiter to add to the queue +* +* Add an arbitrary @waiter to the wait queue for the nominated @page. +*/ +void add_page_wait_queue (struct page *page,wait_queue_t *waiter) +{ +wait_queue_head_t *q =page_waitqueue (page); +unsigned long flags; + +spin_lock_irqsave (&q->lock, flags); +__add_wait_queue (q, waiter); +spin_unlock_irqrestore (&q->lock, flags); +} + +EXPORT_SYMBOL_GPL (add_page_wait_queue); + +/** * unlock_page - unlock a locked page * @page: the page *
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 14/24 CacheFiles: Export things for CacheFiles
In reply to David HowellsExport a number of functions for CacheFiles's use.
---
fs/super.c | 2 ++ kernel/auditsc.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
fs/super.c +2 -0
@@ -270,6 +270,8 @@ int fsync_super(struct super_block *sb)return sync_blockdev (sb->s_bdev); } +EXPORT_SYMBOL_GPL (fsync_super); +/** * generic_shutdown_super - common helper for ->kill_sb() * @sb: superblock to kill
kernel/auditsc.c +2 -0
@@ -1531,6 +1531,8 @@ add_names: } } +EXPORT_SYMBOL_GPL (__audit_inode_child); +/** * auditsc_get_stamp - get local copies of audit_context values * @ctx: audit_context for the task
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 15/24 CacheFiles: A cache that backs onto a mounted filesystem
In reply to David HowellsAdd an FS-Cache cache-backend that permits a mounted filesystem to be used as a backing store for the cache.
CacheFiles uses a userspace daemon to do some of the cache management - such as reaping stale nodes and culling. This is called cachefilesd and lives in /sbin. The source for the daemon can be downloaded from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.c
And an example configuration from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.conf
The filesystem and data integrity of the cache are only as good as those of the filesystem providing the backing services. Note that CacheFiles does not attempt to journal anything since the journalling interfaces of the various filesystems are very specific in nature.
CacheFiles creates a proc-file - "/proc/fs/cachefiles" - that is used for communication with the daemon. Only one thing may have this open at once, and whilst it is open, a cache is at least partially in existence. The daemon opens this and sends commands down it to control the cache.
CacheFiles is currently limited to a single cache.
CacheFiles attempts to maintain at least a certain percentage of free space on the filesystem, shrinking the cache by culling the objects it contains to make space if necessary - see the "Cache Culling" section. This means it can be placed on the same medium as a live set of data, and will expand to make use of spare space and automatically contract when the set of data requires more space.
============
REQUIREMENTS
============
The use of CacheFiles and its daemon requires the following features to be available in the system and in the cache filesystem:
- dnotify.
- extended attributes (xattrs).
- openat() and friends.
- bmap() support on files in the filesystem (FIBMAP ioctl).
- The use of bmap() to detect a partial page at the end of the file.
It is strongly recommended that the "dir_index" option is enabled on Ext3 filesystems being used as a cache.
=============
CONFIGURATION
=============
The cache is configured by a script in /etc/cachefilesd.conf. These commands set up cache ready for use. The following script commands are available:
(*) brun <N>%
(*) bcull <N>%
(*) bstop <N>%
Configure the culling limits. Optional. See the section on culling The defaults are 7%, 5% and 1% respectively.
(*) dir <path>
Specify the directory containing the root of the cache. Mandatory.
(*) tag <name>
Specify a tag to FS-Cache to use in distinguishing multiple caches. Optional. The default is "CacheFiles".
(*) debug <mask>
Specify a numeric bitmask to control debugging in the kernel module. Optional. The default is zero (all off).
==================
STARTING THE CACHE
==================
The cache is started by running the daemon. The daemon opens the cache proc file, configures the cache and tells it to begin caching. At that point the cache binds to fscache and the cache becomes live.
The daemon is run as follows:
/sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>]
The flags are:
(*) -d
Increase the debugging level. This can be specified multiple times and is cumulative with itself.
(*) -s
Send messages to stderr instead of syslog.
(*) -n
Don't daemonise and go into background.
(*) -f <configfile>
Use an alternative configuration file rather than the default one.
===============
THINGS TO AVOID
===============
Do not mount other things within the cache as this will cause problems. The kernel module contains its own very cut-down path walking facility that ignores mountpoints, but the daemon can't avoid them.
Do not create, rename or unlink files and directories in the cache whilst the cache is active, as this may cause the state to become uncertain.
Renaming files in the cache might make objects appear to be other objects (the filename is part of the lookup key).
Do not change or remove the extended attributes attached to cache files by the cache as this will cause the cache state management to get confused.
Do not create files or directories in the cache, lest the cache get confused or serve incorrect data.
Do not chmod files in the cache. The module creates things with minimal permissions to prevent random users being able to access them directly.
=============
CACHE CULLING
=============
The cache may need culling occasionally to make space. This involves discarding objects from the cache that have been used less recently than anything else. Culling is based on the access time of data objects. Empty directories are culled if not in use.
Cache culling is done on the basis of the percentage of blocks available in the underlying filesystem. There are three "limits":
(*) brun
If the amount of available space in the cache rises above this limit, then culling is turned off.
(*) bcull
If the amount of available space in the cache falls below this limit, then culling is started.
(*) bstop
If the amount of available space in the cache falls below this limit, then no further allocation of disk space is permitted until culling has raised the amount above this limit again.
These must be configured thusly:
0 <= bstop < bcull < brun < 100
Note that these are percentages of available space, and do _not_ appear as 100 minus the percentage displayed by the "df" program.
The userspace daemon scans the cache to build up a table of cullable objects. These are then culled in least recently used order. A new scan of the cache is started as soon as space is made in the table. Objects will be skipped if their atimes have changed or if the kernel module says it is still using them.
===============
CACHE STRUCTURE
===============
The CacheFiles module will create two directories in the directory it was given:
(*) cache/
(*) graveyard/
The active cache objects all reside in the first directory. The CacheFiles kernel module moves any retired or culled objects that it can't simply unlink to the graveyard from which the daemon will actually delete them.
The daemon uses dnotify to monitor the graveyard directory, and will delete anything that appears therein.
The module represents index objects as directories with the filename "I..." or "J...". Note that the "cache/" directory is itself a special index.
Data objects are represented as files if they have no children, or directories if they do. Their filenames all begin "D..." or "E...". If represented as a directory, data objects will have a file in the directory called "data" that actually holds the data.
Special objects are similar to data objects, except their filenames begin "S..." or "T...".
If an object has children, then it will be represented as a directory. Immediately in the representative directory are a collection of directories named for hash values of the child object keys with an '@' prepended. Into this directory, if possible, will be placed the representations of the child objects:
INDEX INDEX INDEX DATA FILES ========= ========== ================================= ================ cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry
If the key is so long that it exceeds NAME_MAX with the decorations added on to it, then it will be cut into pieces, the first few of which will be used to make a nest of directories, and the last one of which will be the objects inside the last directory. The names of the intermediate directories will have '+' prepended:
J1223/@23/+xy...z/+kl...m/Epqr
Note that keys are raw data, and not only may they exceed NAME_MAX in size, they may also contain things like '/' and NUL characters, and so they may not be suitable for turning directly into a filename.
To handle this, CacheFiles will use a suitably printable filename directly and "base-64" encode ones that aren't directly suitable. The two versions of object filenames indicate the encoding:
OBJECT TYPE PRINTABLE ENCODED =============== =============== =============== Index "I..." "J..." Data "D..." "E..." Special "S..." "T..."
Intermediate directories are always "@" or "+" as appropriate.
Each object in the cache has an extended attribute label that holds the object type ID (required to distinguish special objects) and the auxiliary data from the netfs. The latter is used to detect stale objects in the cache and update or retire them.
Note that CacheFiles will erase from the cache any file it doesn't recognise or any file of an incorrect type (such as a FIFO file or a device file).
This documentation is added by the patch to:
Documentation/filesystems/caching/cachefiles.txt
---
Documentation/filesystems/caching/cachefiles.txt | 395 ++++++++++ fs/Kconfig | 1 fs/Makefile | 1 fs/cachefiles/Kconfig | 33 + fs/cachefiles/Makefile | 18 fs/cachefiles/cf-bind.c | 289 +++++++ fs/cachefiles/cf-daemon.c | 720 +++++++++++++++++++ fs/cachefiles/cf-interface.c | 444 ++++++++++++ fs/cachefiles/cf-internal.h | 369 ++++++++++ fs/cachefiles/cf-key.c | 159 ++++ fs/cachefiles/cf-main.c | 109 +++ fs/cachefiles/cf-namei.c | 743 +++++++++++++++++++ fs/cachefiles/cf-proc.c | 166 ++++ fs/cachefiles/cf-rdwr.c | 849 ++++++++++++++++++++++ fs/cachefiles/cf-security.c | 94 ++ fs/cachefiles/cf-xattr.c | 292 ++++++++ 16 files changed, 4682 insertions(+), 0 deletions(-)
Documentation/filesystems/caching/cachefiles.txt new file +395 -0
@@ -0,0 +1,395 @@ + =============================================== + CacheFiles: CACHE ON ALREADY MOUNTED FILESYSTEM + =============================================== + +Contents: + + (*) Overview. + + (*) Requirements. + + (*) Configuration. + + (*) Starting the cache. + + (*) Things to avoid. + + (*) Cache culling. + + (*) Cache structure. + + (*) Security model and SELinux. + +======== +OVERVIEW +======== + +CacheFiles is a caching backend that's meant to use as a cache a directory on +an already mounted filesystem of a local type (such as Ext3). + +CacheFiles uses a userspace daemon to do some of the cache management - such as +reaping stale nodes and culling. This is called cachefilesd and lives in +/sbin. + +The filesystem and data integrity of the cache are only as good as those of the +filesystem providing the backing services. Note that CacheFiles does not +attempt to journal anything since the journalling interfaces of the various +filesystems are very specific in nature. + +CacheFiles creates a misc character device - "/dev/cachefiles" - that is used +to communication with the daemon. Only one thing may have this open at once, +and whilst it is open, a cache is at least partially in existence. The daemon +opens this and sends commands down it to control the cache. + +CacheFiles is currently limited to a single cache. + +CacheFiles attempts to maintain at least a certain percentage of free space on +the filesystem, shrinking the cache by culling the objects it contains to make +space if necessary - see the "Cache Culling" section. This means it can be +placed on the same medium as a live set of data, and will expand to make use of +spare space and automatically contract when the set of data requires more +space. + + +============ +REQUIREMENTS +============ + +The use of CacheFiles and its daemon requires the following features to be +available in the system and in the cache filesystem: + + - dnotify. + + - extended attributes (xattrs). + + - openat() and friends. + + - bmap() support on files in the filesystem (FIBMAP ioctl). + + - The use of bmap() to detect a partial page at the end of the file. + +It is strongly recommended that the "dir_index" option is enabled on Ext3 +filesystems being used as a cache. + + +============= +CONFIGURATION +============= + +The cache is configured by a script in /etc/cachefilesd.conf. These commands +set up cache ready for use. The following script commands are available: + + (*) brun <N>% + (*) bcull <N>% + (*) bstop <N>% + (*) frun <N>% + (*) fcull <N>% + (*) fstop <N>% + + Configure the culling limits. Optional. See the section on culling + The defaults are 7% (run), 5% (cull) and 1% (stop) respectively. + + The commands beginning with a 'b' are file space (block) limits, those + beginning with an 'f' are file count limits. + + (*) dir <path> + + Specify the directory containing the root of the cache. Mandatory. + + (*) tag <name> + + Specify a tag to FS-Cache to use in distinguishing multiple caches. + Optional. The default is "CacheFiles". + + (*) debug <mask> + + Specify a numeric bitmask to control debugging in the kernel module. + Optional. The default is zero (all off). The following values can be + OR'd into the mask to collect various information: + + 1 Turn on trace of function entry (_enter() macros) + 2 Turn on trace of function exit (_leave() macros) + 4 Turn on trace of internal debug points (_debug()) + + This mask can also be set through sysfs, eg: + + echo 5 >/sys/modules/cachefiles/parameters/debug + + +================== +STARTING THE CACHE +================== + +The cache is started by running the daemon. The daemon opens the cache device, +configures the cache and tells it to begin caching. At that point the cache +binds to fscache and the cache becomes live. + +The daemon is run as follows: + + /sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>] + +The flags are: + + (*) -d + + Increase the debugging level. This can be specified multiple times and + is cumulative with itself. + + (*) -s + + Send messages to stderr instead of syslog. + + (*) -n + + Don't daemonise and go into background. + + (*) -f <configfile> + + Use an alternative configuration file rather than the default one. + + +=============== +THINGS TO AVOID +=============== + +Do not mount other things within the cache as this will cause problems. The +kernel module contains its own very cut-down path walking facility that ignores +mountpoints, but the daemon can't avoid them. + +Do not create, rename or unlink files and directories in the cache whilst the +cache is active, as this may cause the state to become uncertain. + +Renaming files in the cache might make objects appear to be other objects (the +filename is part of the lookup key). + +Do not change or remove the extended attributes attached to cache files by the +cache as this will cause the cache state management to get confused. + +Do not create files or directories in the cache, lest the cache get confused or +serve incorrect data. + +Do not chmod files in the cache. The module creates things with minimal +permissions to prevent random users being able to access them directly. + + +============= +CACHE CULLING +============= + +The cache may need culling occasionally to make space. This involves +discarding objects from the cache that have been used less recently than +anything else. Culling is based on the access time of data objects. Empty +directories are culled if not in use. + +Cache culling is done on the basis of the percentage of blocks and the +percentage of files available in the underlying filesystem. There are six +"limits": + + (*) brun + (*) frun + + If the amount of free space and the number of available files in the cache + rises above both these limits, then culling is turned off. + + (*) bcull + (*) fcull + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then culling is started. + + (*) bstop + (*) fstop + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then no further allocation of + disk space or files is permitted until culling has raised things above + these limits again. + +These must be configured thusly: + + 0 <= bstop < bcull < brun < 100 + 0 <= fstop < fcull < frun < 100 + +Note that these are percentages of available space and available files, and do +_not_ appear as 100 minus the percentage displayed by the "df" program. + +The userspace daemon scans the cache to build up a table of cullable objects. +These are then culled in least recently used order. A new scan of the cache is +started as soon as space is made in the table. Objects will be skipped if +their atimes have changed or if the kernel module says it is still using them. + + +=============== +CACHE STRUCTURE +=============== + +The CacheFiles module will create two directories in the directory it was +given: + + (*) cache/ + + (*) graveyard/ + +The active cache objects all reside in the first directory. The CacheFiles +kernel module moves any retired or culled objects that it can't simply unlink +to the graveyard from which the daemon will actually delete them. + +The daemon uses dnotify to monitor the graveyard directory, and will delete +anything that appears therein. + + +The module represents index objects as directories with the filename "I..." or +"J...". Note that the "cache/" directory is itself a special index. + +Data objects are represented as files if they have no children, or directories +if they do. Their filenames all begin "D..." or "E...". If represented as a +directory, data objects will have a file in the directory called "data" that +actually holds the data. + +Special objects are similar to data objects, except their filenames begin +"S..." or "T...". + + +If an object has children, then it will be represented as a directory. +Immediately in the representative directory are a collection of directories +named for hash values of the child object keys with an '@' prepended. Into +this directory, if possible, will be placed the representations of the child +objects: + + INDEX INDEX INDEX DATA FILES + ========= ========== ================================= ================ + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry + + +If the key is so long that it exceeds NAME_MAX with the decorations added on to +it, then it will be cut into pieces, the first few of which will be used to +make a nest of directories, and the last one of which will be the objects +inside the last directory. The names of the intermediate directories will have +'+' prepended: + + J1223/@23/+xy...z/+kl...m/Epqr + + +Note that keys are raw data, and not only may they exceed NAME_MAX in size, +they may also contain things like '/' and NUL characters, and so they may not +be suitable for turning directly into a filename. + +To handle this, CacheFiles will use a suitably printable filename directly and +"base-64" encode ones that aren't directly suitable. The two versions of +object filenames indicate the encoding: + + OBJECT TYPE PRINTABLE ENCODED + =============== =============== =============== + Index "I..." "J..." + Data "D..." "E..." + Special "S..." "T..." + +Intermediate directories are always "@" or "+" as appropriate. + + +Each object in the cache has an extended attribute label that holds the object +type ID (required to distinguish special objects) and the auxiliary data from +the netfs. The latter is used to detect stale objects in the cache and update +or retire them. + + +Note that CacheFiles will erase from the cache any file it doesn't recognise or +any file of an incorrect type (such as a FIFO file or a device file). + + +========================== +SECURITY MODEL AND SELINUX +========================== + +CacheFiles is implemented to deal properly with the LSM security features of +the Linux kernel and the SELinux facility. + +One of the problems that CacheFiles faces is that it is generally acting on +behalf of a process, and running in that process's context, and that includes a +security context that is not appropriate for accessing the cache - either +because the files in the cache are inaccessible to that process, or because if +the process creates a file in the cache, that file may be inaccessible to other +processes. + +The way CacheFiles works is to temporarily change the security context (fsuid, +fsgid and actor security label) that the process acts as - without changing the +security context of the process when it the target of an operation performed by +some other process (so signalling and suchlike still work correctly). + + +When the CacheFiles module is asked to bind to its cache, it: + + (1) Finds the security label attached to the root cache directory and uses + that as the security label with which it will create files. By default, + this is: + + cachefiles_var_t + + (2) Finds the security label of the process which issued the bind request + (presumed to be the cachefilesd daemon), which by default will be: + + cachefilesd_t + + and asks LSM to supply a security ID as which it should act given the + daemon's label. By default, this will be: + + cachefiles_kernel_t + + SELinux transitions the daemon's security ID to the module's security ID + based on a rule of this form in the policy. + + type_transition <daemon's-ID> kernel_t : process <module's-ID>; + + For instance: + + type_transition cachefilesd_t kernel_t : process cachefiles_kernel_t; + + +The module's security ID gives it permission to create, move and remove files +and directories in the cache, to find and access directories and files in the +cache, to set and access extended attributes on cache objects, and to read and +write files in the cache. + +The daemon's security ID gives it only a very restricted set of permissions: it +may scan directories, stat files and erase files and directories. It may +not read or write files in the cache, and so it is precluded from accessing the +data cached therein; nor is it permitted to create new files in the cache. + + +There are policy source files available in: + + http://people.redhat.com/~dhowells/fscache/cachefilesd-0.8.tar.bz2 + +and later versions. In that tarball, see the files: + + cachefilesd.te + cachefilesd.fc + cachefilesd.if + +They are built and installed directly by the RPM. + +If a non-RPM based system is being used, then copy the above files to their own +directory and run: + + make -f /usr/share/selinux/devel/Makefile + semodule -i cachefilesd.pp + +You will need checkpolicy and selinux-policy-devel installed prior to the +build. + + +By default, the cache is located in /var/fscache, but if it is desirable that +it should be elsewhere, than either the above policy files must be altered, or +an auxiliary policy must be installed to label the alternate location of the +cache. + +For instructions on how to add an auxiliary policy to enable the cache to be +located elsewhere when SELinux is in enforcing mode, please see: + + /usr/share/doc/cachefilesd-*/move-cache.txt + +When the cachefilesd rpm is installed; alternatively, the document can be found +in the sources.
fs/Kconfig +1 -0
@@ -631,6 +631,7 @@ config GENERIC_ACL menu "Caches" source "fs/fscache/Kconfig" +source "fs/cachefiles/Kconfig" endmenu
fs/Makefile +1 -0
@@ -116,6 +116,7 @@ obj-$(CONFIG_AFS_FS) += afs/ obj-$(CONFIG_BEFS_FS) += befs/ obj-$(CONFIG_HOSTFS) += hostfs/ obj-$(CONFIG_HPPFS) += hppfs/ +obj-$(CONFIG_CACHEFILES) += cachefiles/ obj-$(CONFIG_DEBUG_FS) += debugfs/ obj-$(CONFIG_OCFS2_FS) += ocfs2/ obj-$(CONFIG_GFS2_FS) += gfs2/
fs/cachefiles/Kconfig new file +33 -0
@@ -0,0 +1,33 @@ + +config CACHEFILES + tristate "Filesystem caching on files" + depends on FSCACHE + help + This permits use of a mounted filesystem as a cache for other + filesystems - primarily networking filesystems - thus allowing fast + local disk to enhance the speed of slower devices. + + See Documentation/filesystems/caching/cachefiles.txt for more + information. + +config CACHEFILES_DEBUG + bool "Debug CacheFiles" + depends on CACHEFILES + help + This permits debugging to be dynamically enabled in the filesystem + caching on files module. If this is set, the debugging output may be + enabled by setting bits in /sys/modules/cachefiles/parameter/debug or + by including a debugging specifier in /etc/cachefilesd.conf. + +config CACHEFILES_HISTOGRAM + bool "Gather latency information on CacheFiles" + depends on CACHEFILES && FSCACHE_PROC + help + + This option causes latency information to be gathered on CacheFiles + operation and exported through file: + + /proc/fs/fscache/cachefiles/histogram + + See Documentation/filesystems/caching/cachefiles.txt for more + information.
fs/cachefiles/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +# +# Makefile for caching in a mounted filesystem +# + +cachefiles-y := \ + cf-bind.o \ + cf-daemon.o \ + cf-interface.o \ + cf-key.o \ + cf-main.o \ + cf-namei.o \ + cf-rdwr.o \ + cf-security.o \ + cf-xattr.o + +cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += cf-proc.o + +obj-$(CONFIG_CACHEFILES) := cachefiles.o
fs/cachefiles/cf-bind.c new file +289 -0
289 lines not on this page · raw message
fs/cachefiles/cf-daemon.c new file +720 -0
720 lines not on this page · raw message
fs/cachefiles/cf-interface.c new file +444 -0
444 lines not on this page · raw message
fs/cachefiles/cf-internal.h new file +369 -0
369 lines not on this page · raw message
fs/cachefiles/cf-key.c new file +159 -0
159 lines not on this page · raw message
fs/cachefiles/cf-main.c new file +109 -0
109 lines not on this page · raw message
fs/cachefiles/cf-namei.c new file +743 -0
450 lines not on this page · raw message
fs/cachefiles/cf-proc.c new file +166 -0
166 lines not on this page · raw message
fs/cachefiles/cf-rdwr.c new file +849 -0
849 lines not on this page · raw message
fs/cachefiles/cf-security.c new file +94 -0
94 lines not on this page · raw message
fs/cachefiles/cf-xattr.c new file +292 -0
292 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH 16/24 NFS: Use local caching
In reply to David HowellsThe attached patch makes it possible for the NFS filesystem to make use of the network filesystem local caching service (FS-Cache).
To be able to use this, an updated mount program is required. This can be obtained from:
http://people.redhat.com/steved/fscache/util-linux/
To mount an NFS filesystem to use caching, add an "fsc" option to the mount:
mount warthog:/ /a -o fsc
---
fs/nfs/Makefile | 1 fs/nfs/client.c | 5 + fs/nfs/file.c | 51 ++++++ fs/nfs/fscache-def.c | 288 +++++++++++++++++++++++++++++++++++ fs/nfs/fscache.c | 372 +++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/fscache.h | 144 +++++++++++++++++ fs/nfs/inode.c | 48 +++++- fs/nfs/read.c | 28 +++ fs/nfs/sysctl.c | 44 +++++ include/linux/nfs_fs.h | 8 + include/linux/nfs_fs_sb.h | 7 + 11 files changed, 986 insertions(+), 10 deletions(-)
fs/nfs/Makefile +1 -0
@@ -16,4 +16,5 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ nfs4namespace.o nfs-$(CONFIG_NFS_DIRECTIO) += direct.o nfs-$(CONFIG_SYSCTL) += sysctl.o +nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-def.o nfs-objs := $(nfs-y)
fs/nfs/client.c +5 -0
@@ -41,6 +41,7 @@#include "delegation.h" #include "iostat.h" #include "internal.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_CLIENT
@@ -137,6 +138,8 @@ static struct nfs_client *nfs_alloc_client(const char *hostname, clp->cl_state =1 <<NFS4CLNT_LEASE_EXPIRED ;#endif +nfs_fscache_get_client_cookie (clp); +return clp; error_3:
@@ -168,6 +171,8 @@ static void nfs_free_client(struct nfs_client *clp)nfs4_shutdown_client (clp); +nfs_fscache_release_client_cookie (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);
fs/nfs/file.c +50 -1
93 lines not on this page · raw message
fs/nfs/fscache-def.c new file +288 -0
288 lines not on this page · raw message
fs/nfs/fscache.c new file +372 -0
372 lines not on this page · raw message
fs/nfs/fscache.h new file +144 -0
144 lines not on this page · raw message
fs/nfs/inode.c +41 -7
136 lines not on this page · raw message
fs/nfs/read.c +26 -2
@@ -18,12 +18,14 @@#include <linux/sunrpc/clnt.h> #include <linux/nfs_fs.h> #include <linux/nfs_page.h> +#include <linux/nfs_mount.h> #include <linux/smp_lock.h> #include <asm/system.h> #include "internal.h" #include "iostat.h" +#include "fscache.h" #define NFSDBG_FACILITY NFSDBG_PAGECACHE
@@ -114,8 +116,8 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data) } } -static int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, -struct page *page) +int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, +struct page *page) {LIST_HEAD (one_request);struct nfs_page *new;
@@ -142,6 +144,11 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,static void nfs_readpage_release (struct nfs_page *req) { +struct inode *d_inode = req->wb_context->path.dentry->d_inode; + +if (PageUptodate (req->wb_page)) +nfs_readpage_to_fscache (d_inode, req->wb_page,0 ); +unlock_page (req->wb_page); dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
@@ -500,8 +507,15 @@ int nfs_readpage(struct file *file, struct page *page) ctx =get_nfs_open_context ((struct nfs_open_context *) file->private_data); +if (!IS_SYNC (inode)) { + error =nfs_readpage_from_fscache (ctx, inode, page); +if (error ==0 ) + goto out; + } + error =nfs_readpage_async (ctx, inode, page); +out:put_nfs_open_context (ctx);return error; out_unlock:
@@ -578,6 +592,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, }else desc.ctx =get_nfs_open_context ((struct nfs_open_context *) filp->private_data); + +/* attempt to read as many of the pages as possible from the cache +* - this returns -ENOBUFS immediately if the cookie is negative +*/ + ret =nfs_readpages_from_fscache (desc.ctx, inode, mapping, + pages, &nr_pages); +if (ret ==0 ) + goto read_complete;/* all pages were read */ +if (rsize <PAGE_CACHE_SIZE )nfs_pageio_init (&pgio, inode, nfs_pagein_multi, rsize,0 );else
@@ -588,6 +611,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,nfs_pageio_complete (&pgio); npages = (pgio.pg_bytes_written +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ;nfs_add_stats (inode,NFSIOS_READPAGES , npages); +read_complete:put_nfs_open_context (desc.ctx); out:return ret;
fs/nfs/sysctl.c +44 -0
56 lines not on this page · raw message
include/linux/nfs_fs.h +8 -0
@@ -172,6 +172,9 @@ struct nfs_inode {int delegation_state;struct rw_semaphore rwsem;#endif /* CONFIG_NFS_V4*/ +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache; +#endif struct inode vfs_inode; };
@@ -185,6 +188,7 @@ struct nfs_inode {#define NFS_INO_INVALID_ACL 0x0010/* cached acls are invalid */ #define NFS_INO_REVAL_PAGECACHE 0x0020/* must revalidate pagecache */ #define NFS_INO_REVAL_FORCED 0x0040/* force revalidation ignoring a delegation */ +#define NFS_INO_INVALID_FSCACHE_ATTR 0x0080/* local cache attributes are invalid */ /* * Bit offsets in flags field
@@ -193,6 +197,7 @@ struct nfs_inode {#define NFS_INO_ADVISE_RDPLUS (1)/* advise readdirplus */ #define NFS_INO_STALE (2)/* possible stale inode */ #define NFS_INO_ACL_LRU_SET (3)/* Inode is on the LRU list */ +#define NFS_INO_FSCACHE (4)/* inode can be cached by FS-Cache */ static inline struct nfs_inode *NFS_I (struct inode *inode) {
@@ -218,6 +223,7 @@ static inline struct nfs_inode *NFS_I(struct inode *inode)#define NFS_FLAGS (inode) (NFS_I(inode)->flags)#define NFS_STALE (inode) (test_bit(NFS_INO_STALE, &NFS_FLAGS(inode))) +#define NFS_FSCACHE (inode) (test_bit(NFS_INO_FSCACHE, &NFS_FLAGS(inode)))#define NFS_FILEID (inode) (NFS_I(inode)->fileid)
@@ -464,6 +470,7 @@ extern int nfs_readpages(struct file *, struct address_space *, struct list_head *, unsigned);extern int nfs_readpage_result (struct rpc_task *,struct nfs_read_data *);extern void nfs_readdata_release (void *data); +extern int nfs_readpage_async (struct nfs_open_context *,struct inode *,struct page *);/* * Allocate nfs_read_data structures
@@ -554,6 +561,7 @@ extern void * nfs_root_data(void);#define NFSDBG_CALLBACK 0x0100#define NFSDBG_CLIENT 0x0200#define NFSDBG_MOUNT 0x0400 +#define NFSDBG_FSCACHE 0x0800#define NFSDBG_ALL 0xFFFF#ifdef __KERNEL__
include/linux/nfs_fs_sb.h +7 -0
@@ -3,6 +3,7 @@#include <linux/list.h> #include <linux/backing-dev.h> +#include <linux/fscache.h> struct nfs_iostats ;
@@ -65,6 +66,10 @@ struct nfs_client {char cl_ipaddr[16 ];unsigned char cl_id_uniquifier;#endif + +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache;/* client index cache cookie */ +#endif };/*
@@ -95,6 +100,8 @@ struct nfs_server {unsigned int acdirmin;unsigned int acdirmax;unsigned int namelen; +unsigned int options;/* extra options enabled by mount */ +#define NFS_OPTION_FSCACHE 0x00000001/* - local caching enabled */ struct nfs_fsid fsid;__u64 maxfilesize;/* maximum file size */
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 17/24 NFS: Configuration and mount option changes to enable local caching on NFS
In reply to David HowellsChanges to the kernel configuration defintions and to the NFS mount options to allow the local caching support added by the previous patch to be enabled.
---
fs/Kconfig | 8 ++++++++ fs/nfs/client.c | 14 ++++++++++---- fs/nfs/internal.h | 2 ++ fs/nfs/super.c | 40 ++++++++++++++++++++++++++++++++++------ 4 files changed, 54 insertions(+), 10 deletions(-)
fs/Kconfig +8 -0
@@ -1597,6 +1597,14 @@ config NFS_V4 If unsure, say N. +config NFS_FSCACHE + bool "Provide NFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y + help + Say Y here if you want NFS data to be cached locally on disc through + the general filesystem cache manager + config NFS_DIRECTIO bool "Allow direct I/O on NFS files" depends on NFS_FS
fs/nfs/client.c +10 -4
@@ -543,7 +543,8 @@ error:/* * Create a version 2 or 3 client */ -static int nfs_init_server (struct nfs_server *server,const struct nfs_mount_data *data) +static int nfs_init_server (struct nfs_server *server,const struct nfs_mount_data *data, +unsigned int extra_options) {struct nfs_client *clp;int error, nfsvers =2 ;
@@ -580,6 +581,7 @@ static int nfs_init_server(struct nfs_server *server, const struct nfs_mount_dat server->acregmax = data->acregmax *HZ ; server->acdirmin = data->acdirmin *HZ ; server->acdirmax = data->acdirmax *HZ ; + server->options = extra_options;/* Start lockd here, before we might error out */ error =nfs_start_lockd (server);
@@ -776,6 +778,7 @@ void nfs_free_server(struct nfs_server *server)* - keyed on server and FSID */ struct nfs_server *nfs_create_server (const struct nfs_mount_data *data, +unsigned extra_options,struct nfs_fh *mntfh) {struct nfs_server *server;
@@ -787,7 +790,7 @@ struct nfs_server *nfs_create_server(const struct nfs_mount_data *data,return ERR_PTR (-ENOMEM );/* Get a client representation */ - error =nfs_init_server (server, data); + error =nfs_init_server (server, data, extra_options);if (error <0 ) goto error;
@@ -911,7 +914,8 @@ error:* Create a version 4 volume record */ static int nfs4_init_server (struct nfs_server *server, -const struct nfs4_mount_data *data,rpc_authflavor_t authflavour) +const struct nfs4_mount_data *data,rpc_authflavor_t authflavour, +unsigned int extra_options) {int error;
@@ -930,6 +934,7 @@ static int nfs4_init_server(struct nfs_server *server, server->acregmax = data->acregmax *HZ ; server->acdirmin = data->acdirmin *HZ ; server->acdirmax = data->acdirmax *HZ ; + server->options = extra_options; error =nfs_init_server_rpcclient (server, authflavour);
@@ -948,6 +953,7 @@ struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *data,const char *mntpath, const char *ip_addr, rpc_authflavor_t authflavour, + unsigned int extra_options, struct nfs_fh *mntfh) { struct nfs_fattr fattr;
@@ -967,7 +973,7 @@ struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *data, goto error;/* set up the general RPC client */ - error =nfs4_init_server (server, data, authflavour); + error =nfs4_init_server (server, data, authflavour, extra_options);if (error <0 ) goto error;
fs/nfs/internal.h +2 -0
@@ -33,6 +33,7 @@ extern struct rpc_program nfs_program;extern void nfs_put_client (struct nfs_client *);extern struct nfs_client *nfs_find_client (const struct sockaddr_in *,int );extern struct nfs_server *nfs_create_server (const struct nfs_mount_data *, +unsigned int ,struct nfs_fh *); extern struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *, const char *,
@@ -40,6 +41,7 @@ extern struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *, const char *, const char *, rpc_authflavor_t, + unsigned int, struct nfs_fh *);extern struct nfs_server *nfs4_create_referral_server (struct nfs_clone_mount *,struct nfs_fh *);
fs/nfs/super.c +34 -6
@@ -67,6 +67,7 @@ struct nfs_parsed_mount_data { acdirmin, acdirmax;int namlen;unsigned int bsize; +unsigned int options;unsigned int auth_flavor_len;rpc_authflavor_t auth_flavors[1 ];char *client_address;
@@ -101,6 +102,7 @@ enum { Opt_acl, Opt_noacl, Opt_rdirplus, Opt_nordirplus, Opt_sharecache, Opt_nosharecache, + Opt_fscache, Opt_nofscache,/* Mount options that take integer arguments */ Opt_port,
@@ -149,6 +151,8 @@ static match_table_t nfs_mount_option_tokens = { { Opt_nordirplus, "nordirplus" }, { Opt_sharecache, "sharecache" }, { Opt_nosharecache, "nosharecache" }, + { Opt_fscache, "fsc" }, + { Opt_nofscache, "nofsc" }, { Opt_port, "port=%u" }, { Opt_rsize, "rsize=%u" },
@@ -495,6 +499,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,seq_printf (m,",timeo=%lu" ,10U * clp->retrans_timeo /HZ );seq_printf (m,",retrans=%u" , clp->retrans_count);seq_printf (m,",sec=%s" ,nfs_pseudoflavour_to_name (nfss->client->cl_auth->au_flavor)); +if (nfss->options &NFS_OPTION_FSCACHE ) +seq_printf (m,",fsc" ); }/*
@@ -725,6 +731,15 @@ static int nfs_parse_mount_options(char *raw,break ;case Opt_nosharecache: mnt->flags |=NFS_MOUNT_UNSHARED ; + mnt->options &= ~NFS_OPTION_FSCACHE ; +break ; +case Opt_fscache: +/* sharing is mandatory with fscache */ + mnt->options |=NFS_OPTION_FSCACHE ; + mnt->flags &= ~NFS_MOUNT_UNSHARED ; +break ; +case Opt_nofscache: + mnt->options &= ~NFS_OPTION_FSCACHE ;break ;case Opt_port:
@@ -1081,10 +1096,13 @@ out_err:*/ static int nfs_validate_mount_data (struct nfs_mount_data **options,struct nfs_fh *mntfh, -const char *dev_name) +const char *dev_name, +unsigned int *_extra_options) {struct nfs_mount_data *data = *options; + *_extra_options =0 ; +if (data ==NULL ) goto out_no_data;
@@ -1131,6 +1149,7 @@ static int nfs_validate_mount_data(struct nfs_mount_data **options, .acregmax = 60, .acdirmin = 30, .acdirmax = 60, + .options = 0, .mount_server.protocol = IPPROTO_UDP, .mount_server.program = NFS_MNT_PROGRAM, .nfs_server.protocol = IPPROTO_TCP,
@@ -1139,6 +1158,7 @@ static int nfs_validate_mount_data(struct nfs_mount_data **options,if (nfs_parse_mount_options ((char *) *options, &args) ==0 )return -EINVAL ; + *_extra_options = args.options; data =kzalloc (sizeof (*data),GFP_KERNEL );if (data ==NULL )
@@ -1381,6 +1401,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,struct nfs_fh mntfh;struct nfs_mount_data *data = raw_data;struct dentry *mntroot; +unsigned int extra_options;int (*compare_super)(struct super_block *,void *) = nfs_compare_super;struct nfs_sb_mountdata sb_mntdata = { .mntflags = flags,
@@ -1388,12 +1409,12 @@ static int nfs_get_sb(struct file_system_type *fs_type,int error;/* Validate the mount data */ - error =nfs_validate_mount_data (&data, &mntfh, dev_name); + error =nfs_validate_mount_data (&data, &mntfh, dev_name, &extra_options);if (error <0 ) goto out;/* Get a volume representation */ - server =nfs_create_server (data, &mntfh); + server =nfs_create_server (data, extra_options, &mntfh);if (IS_ERR (server)) { error =PTR_ERR (server); goto out;
@@ -1565,11 +1586,14 @@ static int nfs4_validate_mount_data(struct nfs4_mount_data **options, rpc_authflavor_t *authflavour, char **hostname, char **mntpath, - char **ip_addr) + char **ip_addr, + unsigned int *_extra_options) {struct nfs4_mount_data *data = *options;char *c; + *_extra_options =0 ; +if (data ==NULL ) goto out_no_data;
@@ -1625,11 +1649,13 @@ static int nfs4_validate_mount_data(struct nfs4_mount_data **options, .acregmax = 60, .acdirmin = 30, .acdirmax = 60, + .options = 0, .nfs_server.protocol = IPPROTO_TCP, };if (nfs_parse_mount_options ((char *) *options, &args) ==0 )return -EINVAL ; + *_extra_options = args.options;if (!nfs_verify_server_address ((struct sockaddr *) &args.nfs_server.address))
@@ -1736,6 +1762,7 @@ static int nfs4_get_sb(struct file_system_type *fs_type,rpc_authflavor_t authflavour;struct nfs_fh mntfh;struct dentry *mntroot; +unsigned extra_options;char *mntpath =NULL , *hostname =NULL , *ip_addr =NULL ;int (*compare_super)(struct super_block *,void *) = nfs_compare_super;struct nfs_sb_mountdata sb_mntdata = {
@@ -1745,13 +1772,14 @@ static int nfs4_get_sb(struct file_system_type *fs_type,/* Validate the mount data */ error =nfs4_validate_mount_data (&data, dev_name, &addr, &authflavour, - &hostname, &mntpath, &ip_addr); + &hostname, &mntpath, &ip_addr, + &extra_options);if (error <0 ) goto out;/* Get a volume representation */ server =nfs4_create_server (data, hostname, &addr, mntpath, ip_addr, - authflavour, &mntfh); + authflavour, extra_options, &mntfh);if (IS_ERR (server)) { error =PTR_ERR (server); goto out;
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 18/24 NFS: Display local caching state
In reply to David HowellsDisplay the local caching state in /proc/fs/nfsfs/volumes.
---
fs/nfs/client.c | 7 ++++--- fs/nfs/fscache.h | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
fs/nfs/client.c +4 -3
@@ -1319,7 +1319,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)/* display header on line 1 */ if (v == &nfs_volume_list) { -seq_puts (m,"NV SERVER PORT DEV FSID\n" ); +seq_puts (m,"NV SERVER PORT DEV FSID FSC\n" );return 0 ; }/* display one transport per line on subsequent lines */
@@ -1333,12 +1333,13 @@ static int nfs_volume_list_show(struct seq_file *m, void *v) (unsigned long long ) server->fsid.major, (unsigned long long) server->fsid.minor); -seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s\n" , +seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s %s\n" , clp->cl_nfsversion,NIPQUAD (clp->cl_addr.sin_addr),ntohs (clp->cl_addr.sin_port), dev, - fsid); + fsid, +nfs_server_fscache_state (server));return 0 ; }
fs/nfs/fscache.h +12 -0
@@ -56,6 +56,17 @@ extern void __nfs_fscache_invalidate_page(struct page *, struct inode *);extern int nfs_fscache_release_page (struct page *,gfp_t );/* +* indicate the client caching state as readable text +*/ +static inline const char *nfs_server_fscache_state (struct nfs_server *server) +{ +if (server->nfs_client->fscache && + (server->options &NFS_OPTION_FSCACHE )) +return "yes" ; +return "no " ; +} + +/* * release the caching state associated with a page if undergoing complete page * invalidation */
@@ -110,6 +121,7 @@ static inline void nfs_fscache_unregister(void) {}static inline void nfs_fscache_get_client_cookie (struct nfs_client *clp) {}static inline void nfs4_fscache_get_client_cookie (struct nfs_client *clp) {}static inline void nfs_fscache_release_client_cookie (struct nfs_client *clp) {} +static inline const char *nfs_server_fscache_state (struct nfs_server *server) {return "no " ; }static inline void nfs_fscache_init_fh_cookie (struct inode *inode) {}static inline void nfs_fscache_enable_fh_cookie (struct inode *inode) {}
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 19/24 AFS: Add TestSetPageError()
In reply to David HowellsAdd a TestSetPageError() macro to the suite of page flag manipulators. This can be used by AFS to prevent over-excision of rejected writes from the page cache.
---
include/linux/page-flags.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/page-flags.h +1 -0
@@ -130,6 +130,7 @@#define PageError (page) test_bit(PG_error, &(page)->flags)#define SetPageError (page) set_bit(PG_error, &(page)->flags)#define ClearPageError (page) clear_bit(PG_error, &(page)->flags) +#define TestSetPageError (page) test_and_set_bit(PG_error, &(page)->flags)#define PageReferenced (page) test_bit(PG_referenced, &(page)->flags)#define SetPageReferenced (page) set_bit(PG_referenced, &(page)->flags)
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 20/24 AFS: Add a function to excise a rejected write from the pagecache
In reply to David HowellsAdd a function - cancel_rejected_write() - to excise a rejected write from the pagecache. This function is related to the truncation family of routines. It permits the pages modified by a network filesystem client (such as AFS) to be excised and discarded from the pagecache if the attempt to write them back to the server fails.
The dirty and writeback states of the afflicted pages are cancelled and the pages themselves are detached for recycling. All PTEs referring to those pages are removed.
Note that the locking is tricky as it's very easy to deadlock against truncate() and other routines once the pages have been unlocked as part of the writeback process. To this end, the PG_error flag is set, then the PG_writeback flag is cleared, and only *then* can lock_page() be called.
---
include/linux/mm.h | 5 ++- mm/truncate.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-)
include/linux/mm.h +3 -2
@@ -1091,12 +1091,13 @@ extern int do_munmap(struct mm_struct *, unsigned long, size_t);extern unsigned long do_brk (unsigned long ,unsigned long ); -/* filemap.c */ -extern unsigned long page_unuse (struct page *); +/* truncate.c */ extern void truncate_inode_pages (struct address_space *,loff_t );extern void truncate_inode_pages_range (struct address_space *,loff_t lstart,loff_t lend); +extern void cancel_rejected_write (struct address_space *,pgoff_t ,pgoff_t ); +/* filemap.c */ /* generic vm_area_ops exported for stackable file systems */ extern int filemap_fault (struct vm_area_struct *,struct vm_fault *);
mm/truncate.c +83 -0
86 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 21/24 AFS: Improve handling of a rejected writeback
In reply to David HowellsImprove the handling of the case of a server rejecting an attempt to write back a cached write. AFS operates a write-back cache, so the following sequence of events can theoretically occur:
CLIENT 1 CLIENT 2
======================= =======================
cat data >/the/file
(sits in pagecache)
fs setacl -dir /the/dir/of/the/file \
-acl system:administrators rlidka
(write permission removed for client 1)
sync
(writeback attempt fails)
The way AFS attempts to handle this is:
(1) The affected region will be excised and discarded on the basis that it can't be written back, yet we don't want it lurking in the page cache either. The contents of the affected region will be reread from the server when called for again.
(2) The EOF size will be set to the current server-based file size - usually that which it was before the affected write was made - assuming no conflicting write has been appended, and assuming the affected write extended the file.
This patch makes the following changes:
(1) Zero-length short reads don't produce EBADMSG now just because the OpenAFS server puts a silly value as the size of the returned data. This prevents excised pages beyond the revised EOF being reinstantiated with a surprise PG_error.
(2) Writebacks can now be put into a 'rejected' state in which all further attempts to write them back will result in excision of the affected pages instead.
(3) Preparing a page for overwriting now reads the whole page instead of just those parts of it that aren't to be covered by the copy to be made. This handles the possibility that the copy might fail on EFAULT. Corollary to this, PG_update can now be set by afs_prepare_page() on behalf of afs_prepare_write() rather than setting it in afs_commit_write().
(4) In the case of a conflicting write, afs_prepare_write() will attempt to flush the write to the server, and will then wait for PG_writeback to go away - after unlocking the page. This helps prevent deadlock against the writeback-rejection handler. AOP_TRUNCATED_PAGE is then returned to the caller to signify that the page has been unlocked, and that it should be revalidated.
(5) The writeback-rejection handler now calls cancel_rejected_write() added by the previous patch to excise the affected pages rather than clearing the PG_uptodate flag on all the pages.
---
fs/afs/fsclient.c | 4 + fs/afs/internal.h | 1 fs/afs/write.c | 154 ++++++++++++++++++++++++++++------------------------- 3 files changed, 85 insertions(+), 74 deletions(-)
fs/afs/fsclient.c +3 -1
@@ -353,7 +353,9 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call, call->count =ntohl (call->tmp);_debug ("DATA length: %u" , call->count); -if (call->count >PAGE_SIZE ) +if ((s32 ) call->count <0 ) + call->count =0 ;/* access completely beyond EOF */ +else if (call->count >PAGE_SIZE )return -EBADMSG ; call->offset =0 ; call->unmarshall++;
fs/afs/internal.h +1 -0
@@ -156,6 +156,7 @@ struct afs_writeback {AFS_WBACK_PENDING ,/* write pending */ AFS_WBACK_CONFLICTING ,/* conflicting writes posted */ AFS_WBACK_WRITING ,/* writing back */ +AFS_WBACK_REJECTED ,/* the writeback was rejected */ AFS_WBACK_COMPLETE /* the writeback record has been unlinked */ } state __attribute__((packed)); };
fs/afs/write.c +81 -73
297 lines not on this page · raw message
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 22/24 AFS: Implement shared-writable mmap
In reply to David HowellsImplement shared-writable mmap for AFS.
The key with which to access the file is obtained from the VMA at the point where the PTE is made writable by the page_mkwrite() VMA op and cached in the affected page.
If there's an outstanding write on the page made with a different key, then page_mkwrite() will flush it before attaching a record of the new key.
---
fs/afs/file.c | 20 +++++++++++++++++++- fs/afs/internal.h | 1 + fs/afs/write.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletions(-)
fs/afs/file.c +19 -1
@@ -22,6 +22,7 @@ static int afs_readpage(struct file *file, struct page *page);static void afs_invalidatepage (struct page *page,unsigned long offset);static int afs_releasepage (struct page *page,gfp_t gfp_flags);static int afs_launder_page (struct page *page); +static int afs_mmap (struct file *file,struct vm_area_struct *vma);const struct file_operations afs_file_operations = { .open = afs_open,
@@ -31,7 +32,7 @@ const struct file_operations afs_file_operations = { .write = do_sync_write, .aio_read = generic_file_aio_read, .aio_write = afs_file_write, - .mmap = generic_file_readonly_mmap, + .mmap = afs_mmap, .splice_read = generic_file_splice_read, .fsync = afs_fsync, .lock = afs_lock,
@@ -56,6 +57,11 @@ const struct address_space_operations afs_fs_aops = { .writepages = afs_writepages, }; +static struct vm_operations_struct afs_file_vm_ops = { + .fault = filemap_fault, + .page_mkwrite = afs_page_mkwrite, +}; +/* * open an AFS file or directory and attach a key to it */
@@ -295,3 +301,15 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)_leave (" = 0" );return 0 ; } + +/* +* memory map part of an AFS file +*/ +static int afs_mmap (struct file *file,struct vm_area_struct *vma) +{ +_enter ("" ); + +file_accessed (file); + vma->vm_ops = &afs_file_vm_ops; +return 0 ; +}
fs/afs/internal.h +1 -0
@@ -743,6 +743,7 @@ extern ssize_t afs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);extern int afs_writeback_all (struct afs_vnode *);extern int afs_fsync (struct file *,struct dentry *,int ); +extern int afs_page_mkwrite (struct vm_area_struct *,struct page *);/*****************************************************************************/
fs/afs/write.c +35 -0
@@ -155,6 +155,8 @@ static int afs_prepare_page(struct afs_vnode *vnode, struct page *page,* prepare to perform part of a write to a page * - the caller holds the page locked, preventing it from being written out or * modified by anyone else +* - may be called from afs_page_mkwrite() to set up a page for modification +* through shared-writable mmap */ int afs_prepare_write (struct file *file,struct page *page,unsigned offset,unsigned to)
@@ -833,3 +835,36 @@ int afs_fsync(struct file *file, struct dentry *dentry, int datasync)_leave (" = %d" , ret);return ret; } + +/* +* notification that a previously read-only page is about to become writable +* - if it returns an error, the caller will deliver a bus error signal +* +* we use this to make a record of the key with which the writeback should be +* performed and to flush any outstanding writes made with a different key +* +* the key to be used is attached to the struct file pinned by the VMA +*/ +int afs_page_mkwrite (struct vm_area_struct *vma,struct page *page) +{ +struct afs_vnode *vnode =AFS_FS_I (vma->vm_file->f_mapping->host); +struct key *key = vma->vm_file->private_data; +int ret; + +_enter ("{{%x:%u},%x},{%lx}" , + vnode->fid.vid, vnode->fid.vnode,key_serial (key), page->index); + +do { +lock_page (page); +if (page->mapping == vma->vm_file->f_mapping) + ret =afs_prepare_write (vma->vm_file, page,0 , +PAGE_SIZE ); +else + ret =0 ;/* seems there was interference - let the +* caller deal with it */ +unlock_page (page); + }while (ret ==AOP_TRUNCATED_PAGE ); + +_leave (" = %d" , ret); +return ret; +}
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 23/24 AF_RXRPC: Save the operation ID for debugging
In reply to David HowellsSave the operation ID to be used with a call that we're making for display through /proc/net/rxrpc_calls. This helps debugging stuck operations as we then know what they are.
---
include/net/af_rxrpc.h | 1 + net/rxrpc/af_rxrpc.c | 3 +++ net/rxrpc/ar-internal.h | 1 + net/rxrpc/ar-proc.c | 7 ++++--- 4 files changed, 9 insertions(+), 3 deletions(-)
include/net/af_rxrpc.h +1 -0
@@ -38,6 +38,7 @@ extern void rxrpc_kernel_intercept_rx_messages(struct socket *,extern struct rxrpc_call *rxrpc_kernel_begin_call (struct socket *,struct sockaddr_rxrpc *,struct key *, +u32 ,unsigned long ,gfp_t ); extern int rxrpc_kernel_send_data(struct rxrpc_call *, struct msghdr *,
net/rxrpc/af_rxrpc.c +3 -0
@@ -251,6 +251,7 @@ static struct rxrpc_transport *rxrpc_name_to_transport(struct socket *sock,* @sock: The socket on which to make the call * @srx: The address of the peer to contact (defaults to socket setting) * @key: The security context to use (defaults to socket setting) +* @operation_ID: The operation ID for this call (debugging only) * @user_call_ID: The ID to use * * Allow a kernel service to begin a call on the nominated socket. This just
@@ -263,6 +264,7 @@ static struct rxrpc_transport *rxrpc_name_to_transport(struct socket *sock,struct rxrpc_call *rxrpc_kernel_begin_call (struct socket *sock,struct sockaddr_rxrpc *srx,struct key *key, +u32 operation_ID,unsigned long user_call_ID,gfp_t gfp) {
@@ -311,6 +313,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, call =rxrpc_get_client_call (rx, trans, bundle, user_call_ID, true, gfp);rxrpc_put_bundle (trans, bundle); + call->op_id = operation_ID; out:rxrpc_put_transport (trans);release_sock (&rx->sk);
net/rxrpc/ar-internal.h +1 -0
@@ -367,6 +367,7 @@ struct rxrpc_call {RXRPC_CALL_DEAD ,/* - call is dead */ } state;int debug_id;/* debug ID for printks */ +u32 op_id;/* operation ID (for debugging only) */ u8 channel;/* connection channel occupied by this call */ /* transmission-phase ACK management */
net/rxrpc/ar-proc.c +4 -3
@@ -53,8 +53,8 @@ static int rxrpc_call_seq_show(struct seq_file *seq, void *v)if (v == &rxrpc_calls) {seq_puts (seq,"Proto Local Remote " -" SvID ConnID CallID End Use State Abort " -" UserID\n" ); +" SvID ConnID CallID OpID End Use State " +" Abort UserID\n" );return 0 ; }
@@ -70,13 +70,14 @@ static int rxrpc_call_seq_show(struct seq_file *seq, void *v) ntohs(trans->peer->srx.transport.sin.sin_port)); seq_printf(seq, - "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" + "UDP %-22.22s %-22.22s %4x %08x %08x %08x %s %3u" " %-8.8s %08x %lx\n", lbuff, rbuff, ntohs(call->conn->service_id), ntohl(call->conn->cid), ntohl(call->call_id), + call->op_id, call->conn->in_clientflag ? "Svc" : "Clt", atomic_read(&call->usage), rxrpc_call_states[call->state],
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
David Howells
maintainerPATCH 24/24 FS-Cache: Make kAFS use FS-Cache
In reply to David HowellsThe attached patch makes the kAFS filesystem in fs/afs/ use FS-Cache, and through it any attached caches. The kAFS filesystem will use caching automatically if it's available.
---
fs/Kconfig | 8 + fs/afs/Makefile | 3 fs/afs/cache.c | 505 ++++++++++++++++++++++++++++++++++------------------ fs/afs/cache.h | 15 -- fs/afs/cell.c | 16 +- fs/afs/file.c | 212 +++++++++++++--------- fs/afs/fsclient.c | 32 ++- fs/afs/inode.c | 25 +-- fs/afs/internal.h | 53 ++--- fs/afs/main.c | 27 +-- fs/afs/mntpt.c | 4 fs/afs/rxrpc.c | 1 fs/afs/vlclient.c | 2 fs/afs/vlocation.c | 23 +- fs/afs/volume.c | 14 - fs/afs/write.c | 6 - 16 files changed, 563 insertions(+), 383 deletions(-)
fs/Kconfig +8 -0
@@ -2059,6 +2059,14 @@ config AFS_DEBUG If unsure, say N. +config AFS_FSCACHE + bool "Provide AFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on AFS_FS=m && FSCACHE || AFS_FS=y && FSCACHE=y + help + Say Y here if you want AFS data to be cached locally on disk through + the generic filesystem cache manager + config 9P_FS tristate "Plan 9 Resource Sharing Support (9P2000) (Experimental)" depends on INET && NET_9P && EXPERIMENTAL
fs/afs/Makefile +3 -0
@@ -2,7 +2,10 @@ # Makefile for Red Hat Linux AFS client. # +afs-cache-$(CONFIG_AFS_FSCACHE) := cache.o + kafs-objs := \ + $(afs-cache-y) \ callback.o \ cell.o \ cmservice.o \
fs/afs/cache.c +328 -177
576 lines not on this page · raw message
fs/afs/cache.h +2 -13
@@ -1,6 +1,6 @@/* AFS local cache management interface * -* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) * * This program is free software; you can redistribute it and/or
@@ -9,15 +9,4 @@* 2 of the License, or (at your option) any later version. */ -#ifndef AFS_CACHE_H -#define AFS_CACHE_H - -#undef AFS_CACHING_SUPPORT - -#include <linux/mm.h> -#ifdef AFS_CACHING_SUPPORT -#include <linux/cachefs.h> -#endif -#include "types.h" - -#endif /* AFS_CACHE_H */ +#include <linux/fscache.h>
fs/afs/cell.c +6 -10
@@ -145,12 +145,11 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)if (ret <0 ) goto error; -#ifdef AFS_CACHING_SUPPORT -/* put it up for caching */ -cachefs_acquire_cookie (afs_cache_netfs.primary_index, - &afs_vlocation_cache_index_def, - cell, - &cell->cache); +#ifdef CONFIG_AFS_FSCACHE +/* put it up for caching (this never returns an error) */ + cell->cache =fscache_acquire_cookie (afs_cache_netfs.primary_index, + &afs_cell_cache_index_def, + cell);#endif /* add to the cell lists */
@@ -353,10 +352,7 @@ static void afs_cell_destroy(struct afs_cell *cell)list_del_init (&cell->proc_link);up_write (&afs_proc_cells_sem); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (cell->cache,0 ); -#endif - +fscache_relinquish_cookie (cell->cache,0 );key_put (cell->anonymous_key);kfree (cell);
fs/afs/file.c +131 -81
298 lines not on this page · raw message
fs/afs/fsclient.c +23 -9
@@ -287,6 +287,7 @@ int afs_fs_fetch_file_status(struct afs_server *server, call->reply2 = volsync; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSFETCHSTATUS );/* marshall the parameters */ bp = call->request;
@@ -316,7 +317,7 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call,case 0 : call->offset =0 ; call->unmarshall++; -if (call->operation_ID !=FSFETCHDATA64 ) { +if (call->operation_ID !=htonl (FSFETCHDATA64 )) { call->unmarshall++; goto no_msw; }
@@ -464,7 +465,7 @@ static int afs_fs_fetch_data64(struct afs_server *server, call->reply3 = buffer; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); - call->operation_ID =FSFETCHDATA64 ; + call->operation_ID =htonl (FSFETCHDATA64 );/* marshall the parameters */ bp = call->request;
@@ -509,7 +510,7 @@ int afs_fs_fetch_data(struct afs_server *server, call->reply3 = buffer; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); - call->operation_ID =FSFETCHDATA ; + call->operation_ID =htonl (FSFETCHDATA );/* marshall the parameters */ bp = call->request;
@@ -577,6 +578,7 @@ int afs_fs_give_up_callbacks(struct afs_server *server, call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSGIVEUPCALLBACKS );/* marshall the parameters */ bp = call->request;
@@ -683,10 +685,11 @@ int afs_fs_create(struct afs_server *server, call->reply4 = newcb; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (S_ISDIR (mode) ?FSMAKEDIR :FSCREATEFILE );/* marshall the parameters */ bp = call->request; - *bp++ =htonl (S_ISDIR (mode) ?FSMAKEDIR :FSCREATEFILE ); + *bp++ = call->operation_ID; *bp++ =htonl (vnode->fid.vid); *bp++ =htonl (vnode->fid.vnode); *bp++ =htonl (vnode->fid.unique);
@@ -772,10 +775,11 @@ int afs_fs_remove(struct afs_server *server, call->reply = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (isdir ?FSREMOVEDIR :FSREMOVEFILE );/* marshall the parameters */ bp = call->request; - *bp++ =htonl (isdir ?FSREMOVEDIR :FSREMOVEFILE ); + *bp++ = call->operation_ID; *bp++ =htonl (vnode->fid.vid); *bp++ =htonl (vnode->fid.vnode); *bp++ =htonl (vnode->fid.unique);
@@ -857,6 +861,7 @@ int afs_fs_link(struct afs_server *server, call->reply2 = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSLINK );/* marshall the parameters */ bp = call->request;
@@ -954,6 +959,7 @@ int afs_fs_symlink(struct afs_server *server, call->reply3 = newstatus; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSSYMLINK );/* marshall the parameters */ bp = call->request;
@@ -1062,6 +1068,7 @@ int afs_fs_rename(struct afs_server *server, call->reply2 = new_dvnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSRENAME );/* marshall the parameters */ bp = call->request;
@@ -1178,6 +1185,7 @@ static int afs_fs_store_data64(struct afs_server *server, call->last_to = to; call->send_pages = true; call->store_version = vnode->status.data_version +1 ; + call->operation_ID =htonl (FSSTOREDATA64 );/* marshall the parameters */ bp = call->request;
@@ -1255,6 +1263,7 @@ int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb, call->last_to = to; call->send_pages = true; call->store_version = vnode->status.data_version +1 ; + call->operation_ID =htonl (FSSTOREDATA );/* marshall the parameters */ bp = call->request;
@@ -1303,7 +1312,8 @@ static int afs_deliver_fs_store_status(struct afs_call *call,/* unmarshall the reply once we've received all of it */ store_version =NULL ; -if (call->operation_ID ==FSSTOREDATA ) +if (call->operation_ID ==htonl (FSSTOREDATA ) || + call->operation_ID ==htonl (FSSTOREDATA64 )) store_version = &call->store_version; bp = call->buffer;
@@ -1365,7 +1375,7 @@ static int afs_fs_setattr_size64(struct afs_server *server, struct key *key, call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); call->store_version = vnode->status.data_version +1 ; - call->operation_ID =FSSTOREDATA ; + call->operation_ID =htonl (FSSTOREDATA64 );/* marshall the parameters */ bp = call->request;
@@ -1416,7 +1426,7 @@ static int afs_fs_setattr_size(struct afs_server *server, struct key *key, call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); call->store_version = vnode->status.data_version +1 ; - call->operation_ID =FSSTOREDATA ; + call->operation_ID =htonl (FSSTOREDATA );/* marshall the parameters */ bp = call->request;
@@ -1462,7 +1472,7 @@ int afs_fs_setattr(struct afs_server *server, struct key *key, call->reply = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); - call->operation_ID =FSSTORESTATUS ; + call->operation_ID =htonl (FSSTORESTATUS );/* marshall the parameters */ bp = call->request;
@@ -1742,6 +1752,7 @@ int afs_fs_get_volume_status(struct afs_server *server, call->reply3 = tmpbuf; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSGETVOLUMESTATUS );/* marshall the parameters */ bp = call->request;
@@ -1828,6 +1839,7 @@ int afs_fs_set_lock(struct afs_server *server, call->reply = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSSETLOCK );/* marshall the parameters */ bp = call->request;
@@ -1861,6 +1873,7 @@ int afs_fs_extend_lock(struct afs_server *server, call->reply = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSEXTENDLOCK );/* marshall the parameters */ bp = call->request;
@@ -1893,6 +1906,7 @@ int afs_fs_release_lock(struct afs_server *server, call->reply = vnode; call->service_id =FS_SERVICE ; call->port =htons (AFS_FS_PORT ); + call->operation_ID =htonl (FSRELEASELOCK );/* marshall the parameters */ bp = call->request;
fs/afs/inode.c +13 -12
@@ -61,6 +61,9 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)return -EBADMSG ; } +if (vnode->status.size != inode->i_size) +fscache_attr_changed (vnode->cache); + inode->i_nlink = vnode->status.nlink; inode->i_uid = vnode->status.owner; inode->i_gid =0 ;
@@ -149,15 +152,6 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,return inode; } -#ifdef AFS_CACHING_SUPPORT -/* set up caching before reading the status, as fetch-status reads the -* first page of symlinks to see if they're really mntpts */ -cachefs_acquire_cookie (vnode->volume->cache, -NULL , - vnode, - &vnode->cache); -#endif -if (!status) {/* it's a remotely extant inode */ set_bit (AFS_VNODE_CB_BROKEN , &vnode->flags);
@@ -183,6 +177,13 @@ struct inode *afs_iget(struct super_block *sb, struct key *key, } } +/* set up caching before mapping the status, as map-status reads the +* first page of symlinks to see if they're really mountpoints */ + inode->i_size = vnode->status.size; + vnode->cache =fscache_acquire_cookie (vnode->volume->cache, + &afs_vnode_cache_index_def, + vnode); + ret =afs_inode_map_status (vnode, key);if (ret <0 ) goto bad_inode;
@@ -196,6 +197,8 @@ struct inode *afs_iget(struct super_block *sb, struct key *key,/* failure */ bad_inode: +fscache_relinquish_cookie (vnode->cache,0 ); + vnode->cache =NULL ;make_bad_inode (inode);unlock_new_inode (inode);iput (inode);
@@ -342,10 +345,8 @@ void afs_clear_inode(struct inode *inode)ASSERT (list_empty (&vnode->writebacks));ASSERT (!vnode->cb_promised); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (vnode->cache,0 ); +fscache_relinquish_cookie (vnode->cache,0 ); vnode->cache =NULL ; -#endif mutex_lock (&vnode->permits_lock); permits = vnode->permits;
fs/afs/internal.h +21 -32
119 lines not on this page · raw message
fs/afs/main.c +7 -20
@@ -1,6 +1,6 @@/* AFS client file system * -* Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2002,5 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) * * This program is free software; you can redistribute it and/or
@@ -29,18 +29,6 @@ static char *rootcell;module_param (rootcell, charp,0 );MODULE_PARM_DESC (rootcell,"root AFS cell name and VL server IP addr list" ); -#ifdef AFS_CACHING_SUPPORT -static struct cachefs_netfs_operations afs_cache_ops = { - .get_page_cookie = afs_cache_get_page_cookie, -}; - -struct cachefs_netfs afs_cache_netfs = { - .name ="afs" , - .version =0 , - .ops = &afs_cache_ops, -}; -#endif -struct afs_uuid afs_uuid;/*
@@ -104,10 +92,9 @@ static int __init afs_init(void)if (ret <0 )return ret; -#ifdef AFS_CACHING_SUPPORT +#ifdef CONFIG_AFS_FSCACHE /* we want to be able to cache */ - ret =cachefs_register_netfs (&afs_cache_netfs, - &afs_cache_cell_index_def); + ret =fscache_register_netfs (&afs_cache_netfs);if (ret <0 ) goto error_cache;#endif
@@ -142,8 +129,8 @@ error_fs: error_open_socket: error_vl_update_init: error_cell_init: -#ifdef AFS_CACHING_SUPPORT -cachefs_unregister_netfs (&afs_cache_netfs); +#ifdef CONFIG_AFS_FSCACHE +fscache_unregister_netfs (&afs_cache_netfs); error_cache:#endif afs_callback_update_kill ();
@@ -175,8 +162,8 @@ static void __exit afs_exit(void)afs_vlocation_purge ();flush_scheduled_work ();afs_cell_purge (); -#ifdef AFS_CACHING_SUPPORT -cachefs_unregister_netfs (&afs_cache_netfs); +#ifdef CONFIG_AFS_FSCACHE +fscache_unregister_netfs (&afs_cache_netfs);#endif afs_proc_cleanup ();rcu_barrier ();
fs/afs/mntpt.c +2 -2
@@ -173,9 +173,9 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)if (PageError (page)) goto error; - buf =kmap (page); + buf =kmap_atomic (page,KM_USER0 );memcpy (devname, buf, size); -kunmap (page); +kunmap_atomic (buf,KM_USER0 );page_cache_release (page); page =NULL ;
fs/afs/rxrpc.c +1 -0
@@ -335,6 +335,7 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp,/* create a call */ rxcall =rxrpc_kernel_begin_call (afs_socket, &srx, call->key, +ntohl (call->operation_ID), (unsigned long ) call, gfp); call->key =NULL ;if (IS_ERR (rxcall)) {
fs/afs/vlclient.c +2 -0
@@ -170,6 +170,7 @@ int afs_vl_get_entry_by_name(struct in_addr *addr, call->reply = entry; call->service_id =VL_SERVICE ; call->port =htons (AFS_VL_PORT ); + call->operation_ID =htonl (VLGETENTRYBYNAME );/* marshall the parameters */ bp = call->request;
@@ -206,6 +207,7 @@ int afs_vl_get_entry_by_id(struct in_addr *addr, call->reply = entry; call->service_id =VL_SERVICE ; call->port =htons (AFS_VL_PORT ); + call->operation_ID =htonl (VLGETENTRYBYID );/* marshall the parameters */ bp = call->request;
fs/afs/vlocation.c +8 -15
@@ -281,10 +281,7 @@ static void afs_vlocation_apply_update(struct afs_vlocation *vl, vl->vldb = *vldb; -#ifdef AFS_CACHING_SUPPORT -/* update volume entry in local cache */ -cachefs_update_cookie (vl->cache); -#endif +fscache_update_cookie (vl->cache); }/*
@@ -304,12 +301,8 @@ static int afs_vlocation_fill_in_record(struct afs_vlocation *vl,memset (&vldb,0 ,sizeof (vldb));/* see if we have an in-cache copy (will set vl->valid if there is) */ -#ifdef AFS_CACHING_SUPPORT -cachefs_acquire_cookie (cell->cache, - &afs_volume_cache_index_def, - vlocation, - &vl->cache); -#endif + vl->cache =fscache_acquire_cookie (vl->cell->cache, + &afs_vlocation_cache_index_def, vl);if (vl->valid) {/* try to update a known volume in the cell VL databases by
@@ -420,6 +413,9 @@ fill_in_record:spin_unlock (&vl->lock);wake_up (&vl->waitq); +/* update volume entry in local cache */ +fscache_update_cookie (vl->cache); +/* schedule for regular updates */ afs_vlocation_queue_for_updates (vl); goto success;
@@ -465,7 +461,7 @@ found_in_memory:spin_unlock (&vl->lock); success: -_leave (" = %p" ,vl); +_leave (" = %p" , vl);return vl; error_abandon:
@@ -523,10 +519,7 @@ static void afs_vlocation_destroy(struct afs_vlocation *vl) {_enter ("%p" , vl); -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (vl->cache,0 ); -#endif - +fscache_relinquish_cookie (vl->cache,0 );afs_put_cell (vl->cell);kfree (vl); }
fs/afs/volume.c +4 -10
@@ -124,13 +124,9 @@ struct afs_volume *afs_volume_lookup(struct afs_mount_params *params) }/* attach the cache and volume location */ -#ifdef AFS_CACHING_SUPPORT -cachefs_acquire_cookie (vlocation->cache, - &afs_vnode_cache_index_def, - volume, - &volume->cache); -#endif - + volume->cache =fscache_acquire_cookie (vlocation->cache, + &afs_volume_cache_index_def, + volume);afs_get_vlocation (vlocation); volume->vlocation = vlocation;
@@ -194,9 +190,7 @@ void afs_put_volume(struct afs_volume *volume)up_write (&vlocation->cell->vl_sem);/* finish cleaning up the volume */ -#ifdef AFS_CACHING_SUPPORT -cachefs_relinquish_cookie (volume->cache,0 ); -#endif +fscache_relinquish_cookie (volume->cache,0 );afs_put_vlocation (vlocation);for (loop = volume->nservers -1 ; loop >=0 ; loop--)
fs/afs/write.c +4 -2
@@ -261,7 +261,6 @@ flush_conflicting_wb:_debug ("reuse" );afs_put_writeback (wb);set_page_private (page,0 ); -ClearPagePrivate (page); goto try_again; }
@@ -694,7 +693,6 @@ void afs_pages_written_back(struct afs_vnode *vnode, struct afs_call *call)end_page_writeback (page);if (page_private (page) == (unsigned long ) wb) {set_page_private (page,0 ); -ClearPagePrivate (page); wb->usage--; } }
@@ -854,6 +852,10 @@ int afs_page_mkwrite(struct vm_area_struct *vma, struct page *page)_enter ("{{%x:%u},%x},{%lx}" , vnode->fid.vid, vnode->fid.vnode,key_serial (key), page->index); +/* wait for the page to be written to the cache before we allow it to +* be modified */ +wait_on_page_fscache_write (page); + do { lock_page(page); if (page->mapping == vma->vm_file->f_mapping)
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.