lib/repo: For bare-user, mask content object modes with 0775

Having every object in a bare-user repo (and checkouts) be executable
is ugly.  I can't think of a good reason to do that; they should only
be executable if their input is.  This does
for `bare-user` what we did for `bare-user-only` in
https://github.com/ostreedev/ostree/pull/909
It's also a stronger version of what we do with `checkout -U` in suppressing
suid - here we also strip world-writable files and the sticky bit (even though
that's meaningless today, it might not be in the future).

Closes: https://github.com/ostreedev/ostree/issues/907

Closes: #908
Approved by: alexlarsson
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-06-08 06:50:16 +00:00
1 parent d3900f90f4
commit 5913b22944
4 files changed
+68 -12

No files matched your search

+11 -11
View File
@@ -283,19 +283,19 @@ commit_loose_object_trusted (OstreeRepo *self,
if (objtype == OSTREE_OBJECT_TYPE_FILE &&
self->mode == OSTREE_REPO_MODE_BARE_USER)
{
if (!object_is_symlink)
{
/* We need to apply at least some mode bits, because the repo file was created
with mode 644, and we need e.g. exec bits to be right when we do a user-mode
checkout. To make this work we apply all user bits and the read bits for
group/other. Furthermore, setting user xattrs requires write access, so
this makes sure it's at least writable by us. (O_TMPFILE uses mode 0 by default) */
if (fchmod (fd, mode | 0744) < 0)
return glnx_throw_errno (error);
}
if (!write_file_metadata_to_xattr (fd, uid, gid, mode, xattrs, error))
return FALSE;
if (!object_is_symlink)
{
/* Note that previously this path added `| 0755` which made every
* file executable, see
* https://github.com/ostreedev/ostree/issues/907
*/
const mode_t content_mode = (mode & (S_IFREG | 0775));
if (fchmod (fd, content_mode) < 0)
return glnx_throw_errno_prefix (error, "fchmod");
}
}
else if (objtype == OSTREE_OBJECT_TYPE_FILE &&
self->mode == OSTREE_REPO_MODE_BARE_USER_ONLY