zfs_vnops_os.c: Do not allow a duplicate attribute of same name#17593
zfs_vnops_os.c: Do not allow a duplicate attribute of same name#17593rmacklem wants to merge 1 commit intoopenzfs:masterfrom
Conversation
Without this patch, if an attribute in user namespace is created while xattr=sa, it is possible to create an attribute of the same name via named attributes after xattr=dir. This patch adds code to check for the duplicate in the sa block and deleted it when an attribute of the same name is created in the named attribute directory. Fixes: 2957eab Signed-off-by: Rick Macklem <rmacklem@uoguelph.ca>
amotin
left a comment
There was a problem hiding this comment.
One possible issue I have noticed is that unlike other extattr operations doing similar things, here you are taking the z_xattr_lock inside zfs_delxattr_sa_dircreate() after zfs_create() succeeded. I can see that it is better than nothing, but it seems not atomic, and some other thread may still see two copies of the attribute for a short time. But I am not deep/fresh enough on this code to say if anything better can be done. I approve this if there is no other way, but take it with a grain of salt.
|
On Tue, Aug 5, 2025 at 7:36 AM Alexander Motin ***@***.***> wrote:
CAUTION: This email originated from outside of the University of Guelph. Do not click links or open attachments unless you recognize the sender and know the content is safe. If in doubt, forward suspicious emails to ***@***.***
@amotin approved this pull request.
One possible issue I have noticed is that unlike other extattr operations doing similar things, here you are taking the z_xattr_lock inside zfs_delxattr_sa_dircreate() after zfs_create() succeeded. I can see that it is better than nothing, but it seems not atomic, and some other thread may still see two copies of the attribute for a short time. But I am not deep/fresh enough on this code to say if anything better can be done. I approve this if there is no other way, but take it with a grain of salt.
Yes, I think you are correct.
There are a couple of possible ways to fix this...
- Move the acquisition of the lock to before the create.
(It appears that is what happens for zfs_setextattr(),
so it might be ok. There is a case where lookup of the
directory is done with the lock held, so I doubt there
is a LOR?)
#2 - Just reverse the order of the zfs_listextattr_sa()
and zfs_listextattr_dir() calls in zfs_listextattr_impl().
(The dir call should block until the named attr dir is
unlocked and that will guarantee that it does not
find the "sa" one.)
I'd like to spend more time looking at this and doing some testing.
Is it ok to leave this for a separate commit? rick
…
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
If you have a good reason to hurry with this, then I don't have strong objections. Sure I would would prefer a proper patch from the beginning, but the world is not perfect. |
|
Ok, I'll try and update the pull request in 2-3 days.
Thanks for looking at it and spotting the problem, rick
…On Tue, Aug 5, 2025 at 3:22 PM Alexander Motin ***@***.***> wrote:
CAUTION: This email originated from outside of the University of Guelph. Do not click links or open attachments unless you recognize the sender and know the content is safe. If in doubt, forward suspicious emails to ***@***.***
amotin left a comment (openzfs/zfs#17593)
Is it ok to leave this for a separate commit?
If you have a good reason to hurry with this, then I don't have strong objections. Sure I would would prefer a proper patch from the beginning, but the world is not perfect.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
I am going to close this pull request. It was lucky you In zfs_listextattr_dir(), it locks z_xattr_lock first and then the I can't think of a way to handle this safely, so I think the It is safe for the old extattr stuff because those VOPs I will keep looking for a "safe" way to avoid duplicates, |
|
On Tue, Aug 5, 2025 at 3:22 PM Alexander Motin ***@***.***> wrote:
CAUTION: This email originated from outside of the University of Guelph.
Do not click links or open attachments unless you recognize the sender and
know the content is safe. If in doubt, forward suspicious emails to
***@***.***
*amotin* left a comment (openzfs/zfs#17593)
<#17593 (comment)>
Is it ok to leave this for a separate commit?
If you have a good reason to hurry with this, then I don't have strong
objections. Sure I would would prefer a proper patch from the beginning,
but the world is not perfect.
As I think you've seen, I've closed the pull request. I now see
that the z_xattr_lock would cause a LOR and possible deadlock.
I haven't figured out any way to code around this LOR/deadlock
since the vnode for the named attribute directory may already
be locked when VOP_LOOKUP() and VOP_CREATE() is called.
However, I also haven't figured out why z_xattr_lock exists at all.
The vnode locking serializes calls to zfs_listextattr() and friends
on a per-file basis. All that z_xattr_lock seems to do is make that
serialization global (but not always, since it can be acquired read/shared).
I'll need to look at this more. If z_xattr_lock is just cruft carried over
from the Linux port and could be deleted, then my patch would be easy
to fix. (It would need to acquire an exclusive lock on the file in
zfs_freebsd_create() for the case where the argument is the named attribute
directory.
For now, I am documenting the behaviour in FreeBSD's named_attribute(7)
man page.
Thanks for spotting this, rick
—
… Reply to this email directly, view it on GitHub
<#17593 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/APNAL2QKSN3WJRZQKRQAW3T3MEVAVAVCNFSM6AAAAACDDQMJNKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCNJWHAYTIMJRGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Without this patch, if an attribute in user namespace is created while
xattr=sa, it is possible to create an attribute of the same name via named attribute whenxattr=dir.This patch adds code to check for the duplicate in the sa block and deleted it when an attribute of the same name is created in the named attribute directory.
Fixes: #17540
Motivation and Context
Without this patch, if an attribute in user namespace is created while the
xattrproperty is set to "sa", it is possible to create an attribute of the same name via named attributes after thexattrproperty is changed to "dir".Description
The code in
zfs_deleteextattr_sa()was factored out intozfs_deleteextattr_sa_impl(), so that it could be called without thevop_deleteextattr_argsargument. Thenzfs_deleteextattr_sa_impl()is used by a new function calledzfs_delxattr_sa_dircreate()to delete any "sa" attribute of the same name. Thenzfs_delxattr_sa_dircreate()is called fromzfs_freebsd_create()when a named attribute is being created.How Has This Been Tested?
On an up-to-date FreeBSD system with #17540 applied, an attribute was created via setextattr(1) when the file system's
xattrproperty was set toxattr=sa.Then, the
xattrproperty was switched to "dir" and creation of a named attribute of the same name was done via:Without this patch,
<attribute-name>is listed twice, whereas it is only listed once if the above is done with this patch applied.Types of changes
Checklist:
Signed-off-by.