* [PATCH] xfs: Correctly lock inode when removing suid and security marks
@ 2014-12-02 15:01 Jan Kara
2014-12-02 16:35 ` Brian Foster
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2014-12-02 15:01 UTC (permalink / raw)
To: xfs; +Cc: Jan Kara
Currently XFS calls file_remove_suid() without holding i_mutex. This is
wrong because that function can end up messing with file permissions and
security xattrs for which we need i_mutex held.
Fix the problem by grabbing iolock exclusively when we will need to
change anything in permissions / xattrs.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/xfs/xfs_file.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index eb596b419942..ad6636ac4943 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -521,6 +521,18 @@ restart:
if (error)
return error;
+ /* For changing security info in file_remove_suid() we need i_mutex */
+ if (!IS_NOSEC(inode) && *iolock == XFS_IOLOCK_SHARED) {
+ struct dentry *dentry = file->f_path.dentry;
+
+ if (should_remove_suid(dentry) ||
+ security_inode_need_killpriv(dentry)) {
+ xfs_rw_iunlock(ip, *iolock);
+ *iolock = XFS_IOLOCK_EXCL;
+ xfs_rw_ilock(ip, *iolock);
+ goto restart;
+ }
+ }
/*
* If the offset is beyond the size of the file, we need to zero any
* blocks that fall between the existing EOF and the start of this
--
1.8.1.4
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Correctly lock inode when removing suid and security marks
2014-12-02 15:01 [PATCH] xfs: Correctly lock inode when removing suid and security marks Jan Kara
@ 2014-12-02 16:35 ` Brian Foster
2014-12-02 20:47 ` Jan Kara
0 siblings, 1 reply; 4+ messages in thread
From: Brian Foster @ 2014-12-02 16:35 UTC (permalink / raw)
To: Jan Kara; +Cc: xfs
On Tue, Dec 02, 2014 at 04:01:29PM +0100, Jan Kara wrote:
> Currently XFS calls file_remove_suid() without holding i_mutex. This is
> wrong because that function can end up messing with file permissions and
> security xattrs for which we need i_mutex held.
>
> Fix the problem by grabbing iolock exclusively when we will need to
> change anything in permissions / xattrs.
>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
Hi Jan,
This doesn't compile... it looks like we need to include the security.h
header. FWIW, even then I get an undefined symbol error when compiling
as a module (security_inode_need_killpriv() does not appear to be
exported).
Brian
> fs/xfs/xfs_file.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index eb596b419942..ad6636ac4943 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -521,6 +521,18 @@ restart:
> if (error)
> return error;
>
> + /* For changing security info in file_remove_suid() we need i_mutex */
> + if (!IS_NOSEC(inode) && *iolock == XFS_IOLOCK_SHARED) {
> + struct dentry *dentry = file->f_path.dentry;
> +
> + if (should_remove_suid(dentry) ||
> + security_inode_need_killpriv(dentry)) {
> + xfs_rw_iunlock(ip, *iolock);
> + *iolock = XFS_IOLOCK_EXCL;
> + xfs_rw_ilock(ip, *iolock);
> + goto restart;
> + }
> + }
> /*
> * If the offset is beyond the size of the file, we need to zero any
> * blocks that fall between the existing EOF and the start of this
> --
> 1.8.1.4
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Correctly lock inode when removing suid and security marks
2014-12-02 16:35 ` Brian Foster
@ 2014-12-02 20:47 ` Jan Kara
2014-12-02 21:59 ` Dave Chinner
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kara @ 2014-12-02 20:47 UTC (permalink / raw)
To: Brian Foster; +Cc: Jan Kara, xfs
On Tue 02-12-14 11:35:48, Brian Foster wrote:
> On Tue, Dec 02, 2014 at 04:01:29PM +0100, Jan Kara wrote:
> > Currently XFS calls file_remove_suid() without holding i_mutex. This is
> > wrong because that function can end up messing with file permissions and
> > security xattrs for which we need i_mutex held.
> >
> > Fix the problem by grabbing iolock exclusively when we will need to
> > change anything in permissions / xattrs.
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
>
> Hi Jan,
>
> This doesn't compile... it looks like we need to include the security.h
> header. FWIW, even then I get an undefined symbol error when compiling
> as a module (security_inode_need_killpriv() does not appear to be
> exported).
Sorry, forgot to amend the include in the commit. Regarding export of
security_inode_need_killpriv() - right, I had security XFS compiled in so I
didn't notice. Before I go and fix this up in the obvious way, does anyone
have better idea how to fix this than to second guess what
file_remove_suid() does? Maybe a VFS helper like file_needs_remove_suid()
will be cleaner than what I did?
Honza
> > fs/xfs/xfs_file.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> > index eb596b419942..ad6636ac4943 100644
> > --- a/fs/xfs/xfs_file.c
> > +++ b/fs/xfs/xfs_file.c
> > @@ -521,6 +521,18 @@ restart:
> > if (error)
> > return error;
> >
> > + /* For changing security info in file_remove_suid() we need i_mutex */
> > + if (!IS_NOSEC(inode) && *iolock == XFS_IOLOCK_SHARED) {
> > + struct dentry *dentry = file->f_path.dentry;
> > +
> > + if (should_remove_suid(dentry) ||
> > + security_inode_need_killpriv(dentry)) {
> > + xfs_rw_iunlock(ip, *iolock);
> > + *iolock = XFS_IOLOCK_EXCL;
> > + xfs_rw_ilock(ip, *iolock);
> > + goto restart;
> > + }
> > + }
> > /*
> > * If the offset is beyond the size of the file, we need to zero any
> > * blocks that fall between the existing EOF and the start of this
> > --
> > 1.8.1.4
> >
> > _______________________________________________
> > xfs mailing list
> > xfs@oss.sgi.com
> > http://oss.sgi.com/mailman/listinfo/xfs
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xfs: Correctly lock inode when removing suid and security marks
2014-12-02 20:47 ` Jan Kara
@ 2014-12-02 21:59 ` Dave Chinner
0 siblings, 0 replies; 4+ messages in thread
From: Dave Chinner @ 2014-12-02 21:59 UTC (permalink / raw)
To: Jan Kara; +Cc: Brian Foster, xfs
On Tue, Dec 02, 2014 at 09:47:56PM +0100, Jan Kara wrote:
> On Tue 02-12-14 11:35:48, Brian Foster wrote:
> > On Tue, Dec 02, 2014 at 04:01:29PM +0100, Jan Kara wrote:
> > > Currently XFS calls file_remove_suid() without holding i_mutex. This is
> > > wrong because that function can end up messing with file permissions and
> > > security xattrs for which we need i_mutex held.
> > >
> > > Fix the problem by grabbing iolock exclusively when we will need to
> > > change anything in permissions / xattrs.
> > >
> > > Signed-off-by: Jan Kara <jack@suse.cz>
> > > ---
> >
> > Hi Jan,
> >
> > This doesn't compile... it looks like we need to include the security.h
> > header. FWIW, even then I get an undefined symbol error when compiling
> > as a module (security_inode_need_killpriv() does not appear to be
> > exported).
> Sorry, forgot to amend the include in the commit. Regarding export of
> security_inode_need_killpriv() - right, I had security XFS compiled in so I
> didn't notice. Before I go and fix this up in the obvious way, does anyone
> have better idea how to fix this than to second guess what
> file_remove_suid() does? Maybe a VFS helper like file_needs_remove_suid()
> will be cleaner than what I did?
Helper seems like a sane idea - that way the filesystems can use
them as a matched pair if need be...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-02 22:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 15:01 [PATCH] xfs: Correctly lock inode when removing suid and security marks Jan Kara
2014-12-02 16:35 ` Brian Foster
2014-12-02 20:47 ` Jan Kara
2014-12-02 21:59 ` Dave Chinner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox