Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[patch 15/15] vfs: splice remove_suid() cleanup

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


miklos at szeredi

May 5, 2008, 2:54 AM

Post #1 of 3 (556 views)
Permalink
[patch 15/15] vfs: splice remove_suid() cleanup

From: Miklos Szeredi <mszeredi [at] suse>

generic_file_splice_write() duplicates remove_suid() just because it
doesn't hold i_mutex. But it grabs i_mutex inside splice_from_pipe()
anyway, so this is rather pointless.

Move locking to generic_file_splice_write() and call remove_suid() and
__splice_from_pipe() instead.

Signed-off-by: Miklos Szeredi <mszeredi [at] suse>
CC: Jens Axboe <jens.axboe [at] oracle>
---
fs/splice.c | 29 +++++++++++++----------------
include/linux/fs.h | 1 -
mm/filemap.c | 2 +-
3 files changed, 14 insertions(+), 18 deletions(-)

Index: linux-2.6/fs/splice.c
===================================================================
--- linux-2.6.orig/fs/splice.c 2008-05-05 11:29:20.000000000 +0200
+++ linux-2.6/fs/splice.c 2008-05-05 11:29:29.000000000 +0200
@@ -811,24 +811,19 @@ generic_file_splice_write(struct pipe_in
{
struct address_space *mapping = out->f_mapping;
struct inode *inode = mapping->host;
- int killsuid, killpriv;
+ struct splice_desc sd = {
+ .total_len = len,
+ .flags = flags,
+ .pos = *ppos,
+ .u.file = out,
+ };
ssize_t ret;
- int err = 0;

- killpriv = security_inode_need_killpriv(out->f_path.dentry);
- killsuid = should_remove_suid(out->f_path.dentry);
- if (unlikely(killsuid || killpriv)) {
- mutex_lock(&inode->i_mutex);
- if (killpriv)
- err = security_inode_killpriv(out->f_path.dentry);
- if (!err && killsuid)
- err = __remove_suid(out->f_path.dentry, killsuid);
- mutex_unlock(&inode->i_mutex);
- if (err)
- return err;
- }
-
- ret = splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_file);
+ inode_double_lock(inode, pipe->inode);
+ ret = remove_suid(out->f_path.dentry);
+ if (likely(!ret))
+ ret = __splice_from_pipe(pipe, &sd, pipe_to_file);
+ inode_double_unlock(inode, pipe->inode);
if (ret > 0) {
unsigned long nr_pages;

@@ -840,6 +835,8 @@ generic_file_splice_write(struct pipe_in
* sync it.
*/
if (unlikely((out->f_flags & O_SYNC) || IS_SYNC(inode))) {
+ int err;
+
mutex_lock(&inode->i_mutex);
err = generic_osync_inode(inode, mapping,
OSYNC_METADATA|OSYNC_DATA);
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h 2008-05-05 11:29:28.000000000 +0200
+++ linux-2.6/include/linux/fs.h 2008-05-05 11:29:29.000000000 +0200
@@ -1822,7 +1822,6 @@ extern void iget_failed(struct inode *);
extern void clear_inode(struct inode *);
extern void destroy_inode(struct inode *);
extern struct inode *new_inode(struct super_block *);
-extern int __remove_suid(struct dentry *, int);
extern int should_remove_suid(struct dentry *);
extern int remove_suid(struct dentry *);

Index: linux-2.6/mm/filemap.c
===================================================================
--- linux-2.6.orig/mm/filemap.c 2008-05-05 11:29:20.000000000 +0200
+++ linux-2.6/mm/filemap.c 2008-05-05 11:29:29.000000000 +0200
@@ -1655,7 +1655,7 @@ int should_remove_suid(struct dentry *de
}
EXPORT_SYMBOL(should_remove_suid);

-int __remove_suid(struct dentry *dentry, int kill)
+static int __remove_suid(struct dentry *dentry, int kill)
{
struct iattr newattrs;


--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


hch at infradead

May 5, 2008, 4:11 AM

Post #2 of 3 (492 views)
Permalink
Re: [patch 15/15] vfs: splice remove_suid() cleanup [In reply to]

On Mon, May 05, 2008 at 11:54:56AM +0200, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi [at] suse>
>
> generic_file_splice_write() duplicates remove_suid() just because it
> doesn't hold i_mutex. But it grabs i_mutex inside splice_from_pipe()
> anyway, so this is rather pointless.
>
> Move locking to generic_file_splice_write() and call remove_suid() and
> __splice_from_pipe() instead.

Looks good to me. I wonder whether we should kill splice_from_pipe
entirely and always leave the locking to the caller.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


jens.axboe at oracle

May 7, 2008, 12:20 AM

Post #3 of 3 (476 views)
Permalink
Re: [patch 15/15] vfs: splice remove_suid() cleanup [In reply to]

On Mon, May 05 2008, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi [at] suse>
>
> generic_file_splice_write() duplicates remove_suid() just because it
> doesn't hold i_mutex. But it grabs i_mutex inside splice_from_pipe()
> anyway, so this is rather pointless.
>
> Move locking to generic_file_splice_write() and call remove_suid() and
> __splice_from_pipe() instead.
>
> Signed-off-by: Miklos Szeredi <mszeredi [at] suse>
> CC: Jens Axboe <jens.axboe [at] oracle>

Looks good to me, applied.

--
Jens Axboe

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.