mm: move readahead syscall to mm/readahead.c
Subsystems (3)
PATCH 1/2 mm: move readahead syscall to mm/readahead.c
From: Cong Wang <[email protected]>
It is better to define readahead(2) in mm/readahead.c than in mm/filemap.c.
Cc Fengguang Wu <[email protected]>
Cc Al Viro <[email protected]>
Signed-off-by Cong Wang <[email protected]>
--- mm/filemap.c | 39 --------------------------------------- mm/readahead.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 39 deletions(-)
mm/filemap.c +0 -39
@@ -29,7 +29,6 @@#include <linux/pagevec.h> #include <linux/blkdev.h> #include <linux/security.h> -#include <linux/syscalls.h> #include <linux/cpuset.h> #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */ #include <linux/memcontrol.h>
@@ -1478,44 +1477,6 @@ out: }EXPORT_SYMBOL (generic_file_aio_read); -static ssize_t -do_readahead (struct address_space *mapping,struct file *filp, -pgoff_t index,unsigned long nr) -{ -if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage) -return -EINVAL ; - -force_page_cache_readahead (mapping, filp, index, nr); -return 0 ; -} - -SYSCALL_DEFINE (readahead)(int fd,loff_t offset,size_t count) -{ -ssize_t ret; -struct file *file; - - ret = -EBADF ; - file =fget (fd); -if (file) { -if (file->f_mode &FMODE_READ ) { -struct address_space *mapping = file->f_mapping; -pgoff_t start = offset >>PAGE_CACHE_SHIFT ; -pgoff_t end = (offset + count -1 ) >>PAGE_CACHE_SHIFT ; -unsigned long len = end - start +1 ; - ret =do_readahead (mapping, file, start, len); - } -fput (file); - } -return ret; -} -#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS -asmlinkage long SyS_readahead (long fd,loff_t offset,long count) -{ -return SYSC_readahead ((int ) fd, offset, (size_t ) count); -} -SYSCALL_ALIAS (sys_readahead, SyS_readahead); -#endif -#ifdef CONFIG_MMU /** * page_cache_read - adds requested page to the page cache if not already there
mm/readahead.c +40 -0
@@ -17,6 +17,8 @@#include <linux/task_io_accounting_ops.h> #include <linux/pagevec.h> #include <linux/pagemap.h> +#include <linux/syscalls.h> +#include <linux/file.h> /* * Initialise a struct file's readahead state. Assumes that the caller has
@@ -562,3 +564,41 @@ page_cache_async_readahead(struct address_space *mapping,ondemand_readahead (mapping, ra, filp, true, offset, req_size); }EXPORT_SYMBOL_GPL (page_cache_async_readahead); + +static ssize_t +do_readahead (struct address_space *mapping,struct file *filp, +pgoff_t index,unsigned long nr) +{ +if (!mapping || !mapping->a_ops || !mapping->a_ops->readpage) +return -EINVAL ; + +force_page_cache_readahead (mapping, filp, index, nr); +return 0 ; +} + +SYSCALL_DEFINE (readahead)(int fd,loff_t offset,size_t count) +{ +ssize_t ret; +struct file *file; + + ret = -EBADF ; + file =fget (fd); +if (file) { +if (file->f_mode &FMODE_READ ) { +struct address_space *mapping = file->f_mapping; +pgoff_t start = offset >>PAGE_CACHE_SHIFT ; +pgoff_t end = (offset + count -1 ) >>PAGE_CACHE_SHIFT ; +unsigned long len = end - start +1 ; + ret =do_readahead (mapping, file, start, len); + } +fput (file); + } +return ret; +} +#ifdef CONFIG_HAVE_SYSCALL_WRAPPERS +asmlinkage long SyS_readahead (long fd,loff_t offset,long count) +{ +return SYSC_readahead ((int ) fd, offset, (size_t ) count); +} +SYSCALL_ALIAS (sys_readahead, SyS_readahead); +#endif
Signature · 8 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 fs: move file_remove_suid() to fs/inode.c
From: Cong Wang <[email protected]>
file_remove_suid() is a generic function operates on struct file, it almost has no relations with file mapping, so move it to fs/inode.c.
Cc Alexander Viro <[email protected]>
Signed-off-by Cong Wang <[email protected]>
--- fs/inode.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ mm/filemap.c | 65 ---------------------------------------------------------- 2 files changed, 65 insertions(+), 65 deletions(-)
fs/inode.c +65 -0
@@ -1524,6 +1524,71 @@ void touch_atime(struct path *path) }EXPORT_SYMBOL (touch_atime); +/* +* The logic we want is +* +* if suid or (sgid and xgrp) +* remove privs +*/ +int should_remove_suid (struct dentry *dentry) +{ +umode_t mode = dentry->d_inode->i_mode; +int kill =0 ; + +/* suid always must be killed */ +if (unlikely (mode &S_ISUID )) + kill =ATTR_KILL_SUID ; + +/* +* sgid without any exec bits is just a mandatory locking mark; leave +* it alone. If some exec bits are set, it's a real sgid; kill it. +*/ +if (unlikely ((mode &S_ISGID ) && (mode &S_IXGRP ))) + kill |=ATTR_KILL_SGID ; + +if (unlikely (kill && !capable (CAP_FSETID ) &&S_ISREG (mode))) +return kill; + +return 0 ; +} +EXPORT_SYMBOL (should_remove_suid); + +static int __remove_suid (struct dentry *dentry,int kill) +{ +struct iattr newattrs; + + newattrs.ia_valid =ATTR_FORCE | kill; +return notify_change (dentry, &newattrs); +} + +int file_remove_suid (struct file *file) +{ +struct dentry *dentry = file->f_path.dentry; +struct inode *inode = dentry->d_inode; +int killsuid; +int killpriv; +int error =0 ; + +/* Fast path for nothing security related */ +if (IS_NOSEC (inode)) +return 0 ; + + killsuid =should_remove_suid (dentry); + killpriv =security_inode_need_killpriv (dentry); + +if (killpriv <0 ) +return killpriv; +if (killpriv) + error =security_inode_killpriv (dentry); +if (!error && killsuid) + error =__remove_suid (dentry, killsuid); +if (!error && (inode->i_sb->s_flags &MS_NOSEC )) + inode->i_flags |=S_NOSEC ; + +return error; +} +EXPORT_SYMBOL (file_remove_suid); +/** * file_update_time - update mtime and ctime time * @file: file accessed
mm/filemap.c +0 -65
71 lines not on this page · raw message
Signature · 8 lines
1.7.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>