From: "Ernesto A. Fernández" <ernesto.mnd.fernandez@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: "Chris Mason" <clm@fb.com>, "Josef Bacik" <jbacik@fb.com>,
"David Sterba" <dsterba@suse.com>,
"Ernesto A. Fernández" <ernesto.mnd.fernandez@gmail.com>
Subject: [PATCH v2] btrfs: preserve i_mode if __btrfs_set_acl() fails
Date: Sat, 29 Jul 2017 23:18:39 -0300 [thread overview]
Message-ID: <20170730021838.GA4565@debian.home> (raw)
In-Reply-To: <20170729002626.GA6759@debian.home>
When changing a file's acl mask, btrfs_set_acl() will first set the
group bits of i_mode to the value of the mask, and only then set the
actual extended attribute representing the new acl.
If the second part fails (due to lack of space, for example) and the
file had no acl attribute to begin with, the system will from now on
assume that the mask permission bits are actual group permission bits,
potentially granting access to the wrong users.
Prevent this by starting the journal transaction before calling
__btrfs_set_acl and only changing the inode mode after the acl is set
successfully.
Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
---
Changes in v2:
- Take the code that checks if we are setting a default acl on something
that is not a dir, remove it from the __btrfs_set_acl function, and
place it in btrfs_set_acl instead. This should fix the issue pointed out
by Josef Bacik, that I was sometimes updating the inode even when there
was no change.
- Don't call BUG_ON when the inode failed to update. Also requested by
Josef Bacik. It should be noted that __btrfs_setxattr was already
calling BUG_ON before my patch; that has not been changed.
fs/btrfs/acl.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 8d8370d..f62e8ac 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -27,6 +27,7 @@
#include "ctree.h"
#include "btrfs_inode.h"
#include "xattr.h"
+#include "transaction.h"
struct posix_acl *btrfs_get_acl(struct inode *inode, int type)
{
@@ -80,8 +81,6 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
name = XATTR_NAME_POSIX_ACL_ACCESS;
break;
case ACL_TYPE_DEFAULT:
- if (!S_ISDIR(inode->i_mode))
- return acl ? -EINVAL : 0;
name = XATTR_NAME_POSIX_ACL_DEFAULT;
break;
default:
@@ -113,14 +112,38 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
{
+ struct btrfs_root *root = BTRFS_I(inode)->root;
+ struct btrfs_trans_handle *trans;
int ret;
+ umode_t mode = inode->i_mode;
+ if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
+ return acl ? -EINVAL : 0;
if (type == ACL_TYPE_ACCESS && acl) {
- ret = posix_acl_update_mode(inode, &inode->i_mode, &acl);
+ ret = posix_acl_update_mode(inode, &mode, &acl);
if (ret)
return ret;
}
- return __btrfs_set_acl(NULL, inode, acl, type);
+
+ if (btrfs_root_readonly(root))
+ return -EROFS;
+
+ trans = btrfs_start_transaction(root, 2);
+ if (IS_ERR(trans))
+ return PTR_ERR(trans);
+
+ ret = __btrfs_set_acl(trans, inode, acl, type);
+ if (ret)
+ goto out;
+
+ inode->i_mode = mode;
+ inode_inc_iversion(inode);
+ inode->i_ctime = current_time(inode);
+ set_bit(BTRFS_INODE_COPY_EVERYTHING, &BTRFS_I(inode)->runtime_flags);
+ ret = btrfs_update_inode(trans, root, inode);
+out:
+ btrfs_end_transaction(trans);
+ return ret;
}
/*
--
2.1.4
next prev parent reply other threads:[~2017-07-30 2:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-29 0:26 [PATCH] btrfs: preserve i_mode if __btrfs_set_acl() fails Ernesto A. Fernández
2017-07-29 0:48 ` Josef Bacik
2017-07-29 5:04 ` Ernesto A. Fernández
2017-07-30 2:18 ` Ernesto A. Fernández [this message]
2017-08-02 6:18 ` [PATCH v3] " Ernesto A. Fernández
2017-08-14 16:05 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170730021838.GA4565@debian.home \
--to=ernesto.mnd.fernandez@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=jbacik@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).