-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fdio: Use O_TMPFILE + rename-overwrite for regfile copies #80
Conversation
I was working on rpm-ostree unified core, and hit the fact that `glnx_file_copy_at()` had the same bug with `fsetxattr()` and files whose mode is <= `0400` (e.g. `000` in the case of `/etc/shadow`) that libostree did a while ago. This situation is masked for privileged (i.e. `CAP_DAC_OVERRIDE`) code. Looking at this, I think it's cleaner to convert to `O_TMPFILE` here, since that code already handles setting the tmpfile to mode `0600`. Now, this *is* a behavior change in the corner case of existing files which are symbolic links. Previously we'd do an `open(O_TRUNC)` which would follow the link. But in the big picture, I think the use cases for `open(O_TRUNC)` are really rare - I audited all callers of this in ostree/rpm-ostree/flatpak, and all of them will be fine with this behavior change. For example, the ostree `/etc` merge code already explicitly unlinks the target beforehand. Other cases like supporting `repo/pubring.gpg` in an ostree repo being a symlink...eh, just no. Making this change allows us to convert to new style, and brings all of the general benefits of using `O_TMPFILE` too.
Prep for unified core work. This was failing due to a bug in libglnx <GNOME/libglnx#80> but I think this change is also correct. There's no good reason for us to copy xattrs like the SELinux label here - rather we want the labels to be reset during commit.
@@ -858,11 +858,15 @@ glnx_regfile_copy_bytes (int fdf, int fdt, off_t max_bytes) | |||
* @cancellable: cancellable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit/not new to this patch: the src_stbuf
parameter isn't in the docstring.
} | ||
|
||
/* Always chmod after setting xattrs, in case the file has mode 0400 or less, | ||
* like /etc/shadow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm missing something here. Does setting xattrs reset the mode? Can you link to the ostree issue in the commit message or the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically if a file is mode 000
(or in general doesn't have write perms), one can write()
to it but not fsetxattr()
. ostreedev/ostree@3348baf is related and so is 452c371
I thought there was a better commit but I can't find it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words we need to fchmod()
after we do the xattrs, and the file needs to be writable before that, which our O_TMPFILE
code ensures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh gotcha, wasn't aware of that. Maybe make it more explicit in the comment? Otherwise, LGTM!
Updated for both issues and pushed, thanks! |
Prep for unified core work. This was failing due to a bug in libglnx <GNOME/libglnx#80> but I think this change is also correct. There's no good reason for us to copy xattrs like the SELinux label here - rather we want the labels to be reset during commit.
Prep for unified core work. This was failing due to a bug in libglnx <GNOME/libglnx#80> but I think this change is also correct. There's no good reason for us to copy xattrs like the SELinux label here - rather we want the labels to be reset during commit. I did a tree-wide grep for other users and the only other case that is odd is the treecompose `add-files`; I'd say we should change this but out of (a likely excess of) conservatism I just left a "FIXME" for now.
Prep for unified core work. This was failing due to a bug in libglnx <GNOME/libglnx#80> but I think this change is also correct. There's no good reason for us to copy xattrs like the SELinux label here - rather we want the labels to be reset during commit. I did a tree-wide grep for other users and the only other case that is odd is the treecompose `add-files`; I'd say we should change this but out of (a likely excess of) conservatism I just left a "FIXME" for now. Closes: #1008 Approved by: jlebon
I was working on rpm-ostree unified core, and hit the fact that
glnx_file_copy_at()
had the same bug withfsetxattr()
and files whose modeis <=
0400
(e.g.000
in the case of/etc/shadow
) that libostree did awhile ago. This situation is masked for privileged (i.e.
CAP_DAC_OVERRIDE
)code.
Looking at this, I think it's cleaner to convert to
O_TMPFILE
here,since that code already handles setting the tmpfile to mode
0600
. Now,this is a behavior change in the corner case of existing files which
are symbolic links. Previously we'd do an
open(O_TRUNC)
which would followthe link.
But in the big picture, I think the use cases for
open(O_TRUNC)
are reallyrare - I audited all callers of this in ostree/rpm-ostree/flatpak, and all of
them will be fine with this behavior change. For example, the ostree
/etc
merge code already explicitly unlinks the target beforehand. Other cases like
supporting
repo/pubring.gpg
in an ostree repo being a symlink...eh, just no.Making this change allows us to convert to new style, and brings all of the
general benefits of using
O_TMPFILE
too.