From: Chris Mason <clm@fb.com>
To: Filipe Manana <fdmanana@suse.com>
Cc: <linux-btrfs@vger.kernel.org>, <oliva@gnu.org>,
Filipe Manana <fdmanana@suse.com>
Subject: Re: [PATCH] Btrfs: make xattr replace operations atomic
Date: Fri, 7 Nov 2014 15:54:53 -0500 [thread overview]
Message-ID: <1415393693.1712.0@mail.thefacebook.com> (raw)
In-Reply-To: <1415392765-1877-1-git-send-email-fdmanana@suse.com>
On Fri, Nov 7, 2014 at 3:39 PM, Filipe Manana <fdmanana@suse.com> wrote:
> Replacing a xattr consists of doing a lookup for its existing value,
> delete
> the current value from the respective leaf, release the search path
> and then
> finally insert the new value. This leaves a time window where readers
> (getxattr,
> listxattrs) won't see any value for the xattr. Xattrs are used to
> store ACLs,
> so this has security implications.
>
> This change also fixes 2 other existing issues which were:
>
> *) Deleting the old xattr value without verifying first if the new
> xattr will
> fit in the existing leaf item (in case multiple xattrs are packed
> in the
> same item due to name hash collision);
>
> *) Returning -EEXIST when the flag XATTR_CREATE is given and the
> xattr doesn't
> exist but we have have an existing item that packs muliple xattrs
> with
> the same name hash as the input xattr. In this case we should
> return ENOSPC.
>
> A test case for xfstests follows soon.
>
> Thanks to Alexandre Oliva for reporting the non-atomicity of the
> xattr replace
> implementation.
Thanks Filipe, one problem:
> +
> + if (size > old_data_len) {
> + if (btrfs_leaf_free_space(root, leaf) <
> + (size - old_data_len)) {
> + ret = -ENOSPC;
> + goto out;
> + }
> }
This means replacing an xattr item can fail if the leaf doesn't happen
to have free space. btrfs_search_slot already has code meant to extend
the item, even if the item you're searching for is already found. (see
the call to split_leaf with extend == 1).
So what you want to do is find out the current size of the item, and
call btrfs search_slot again with that size + the extra needed for the
new name. From there you should be able to call btrfs_extend_item like
you currently are.
-chris
next prev parent reply other threads:[~2014-11-07 20:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 20:39 [PATCH] Btrfs: make xattr replace operations atomic Filipe Manana
2014-11-07 20:54 ` Chris Mason [this message]
2014-11-07 21:34 ` Filipe David Manana
2014-11-08 1:01 ` [PATCH v2] " Filipe Manana
2014-11-08 1:26 ` Robert White
2014-11-08 7:17 ` Filipe David Manana
2014-11-08 13:01 ` [PATCH v3] " Filipe Manana
2014-11-09 8:38 ` [PATCH v4] " Filipe Manana
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=1415393693.1712.0@mail.thefacebook.com \
--to=clm@fb.com \
--cc=fdmanana@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=oliva@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.