After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 728006 - optionally make use of S_IMMUTABLE
optionally make use of S_IMMUTABLE
Status: RESOLVED FIXED
Product: ostree
Classification: Infrastructure
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: OSTree maintainer(s)
OSTree maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-04-11 00:07 UTC by Colin Walters
Modified: 2014-06-09 18:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
deploy: Set the immutable bit on the deployment root (8.72 KB, patch)
2014-05-30 14:59 UTC, Colin Walters
none Details | Review
deploy: Set the immutable bit on the deployment root (9.26 KB, patch)
2014-05-30 16:12 UTC, Colin Walters
committed Details | Review
ostree-remount: Check for / being *mounted* read-only, not necessarily writable (1.50 KB, patch)
2014-06-03 21:39 UTC, Colin Walters
committed Details | Review
libostree: Silently ignore EPERM when setting EXT2_IMMUTABLE_FL (2.19 KB, patch)
2014-06-04 22:26 UTC, Colin Walters
committed Details | Review

Description Colin Walters 2014-04-11 00:07:03 UTC
See sealing discussion:

http://lwn.net/Articles/593918/

Now I dinged Nix for using S_IMMUTABLE, but maybe it is better to go belt-and-suspenders on this.

The downside is that we have to remove the bit temporarily when making a hardlink, but that's not difficult to do.

It still would be nice if the kernel had a S_IMMUTABLE_CONTENT or so.
Comment 1 Colin Walters 2014-05-09 12:56:41 UTC
See also http://marc.info/?l=linux-fsdevel&m=139963046823575&w=2
Comment 2 Colin Walters 2014-05-30 14:59:13 UTC
Created attachment 277562 [details] [review]
deploy: Set the immutable bit on the deployment root

This prevents people from creating new directories there and expecting
them to be persisted.  The OSTree model has all local state to be in
/etc and /var.

This introduces a compile-time dependency on libe2fsprogs.
Comment 3 Colin Walters 2014-05-30 15:22:56 UTC
This is just an initial step; a further step we could take now would be to make subdirectories immutable (/usr, /usr/etc) in particular would be good targets.
Comment 4 Colin Walters 2014-05-30 16:12:22 UTC
Created attachment 277571 [details] [review]
deploy: Set the immutable bit on the deployment root

We need to check for ENOTTY for ioctl(), not EOPNOTSUPP.  However I
left in the EOPNOTSUPP just in case.
Comment 5 Matthew Heon 2014-06-03 17:23:03 UTC
Review of attachment 277571 [details] [review]:

Overall, code looks fine, no obvious defects I can find. Patch applies and builds cleanly. 

It would be worth a double-check to make sure that all common root filesystems support immutable - I know the EXT family does, but it's possible there's a strange one (one of the SSD/Flash optimized FSes, perhaps?) that does not.

The change of root to immutable is definitely sensible in an OSTree managed system. I was initially convinced it was a bad idea to enable by default, but I can't think of any logical reasons for that. The only real reason I can think of to create a directory in root on an OSTree system would be to make a temporary folder, maybe to mount a volume, and best practice would be to do those elsewhere regardless.
Comment 6 Colin Walters 2014-06-03 17:44:12 UTC
Thanks for the review!  I did check the kernel source
to make sure it was supported by the important filesystems;
"git grep FS_IOC_GETFLAGS"

Attachment 277571 [details] pushed as b4d21e9 - deploy: Set the immutable bit on the deployment root
Comment 7 Colin Walters 2014-06-03 21:16:18 UTC
This regressed /var being remounted writable.  See:
https://git.gnome.org/browse/ostree/tree/src/switchroot/ostree-remount.c#n46

We need a more intelligent check here.  Parsing the mount options?
Comment 8 Colin Walters 2014-06-03 21:39:36 UTC
Created attachment 277834 [details] [review]
ostree-remount: Check for / being *mounted* read-only, not necessarily writable

The previous S_IMMUTABLE commit broke ostree-remount; / is now not
actually writable.  All we really wanted to know though was whether it
was *mounted* writable, so check that via statvfs() which is cleaner
anyways (i.e. not via access() which kernel people hate).
Comment 9 Jasper St. Pierre (not reading bugmail) 2014-06-03 22:48:45 UTC
Review of attachment 277834 [details] [review]:

Looks good.
Comment 10 Colin Walters 2014-06-04 00:23:55 UTC
Attachment 277834 [details] pushed as cb43d29 - ostree-remount: Check for / being *mounted* read-only, not necessarily writable
Comment 11 Colin Walters 2014-06-04 22:18:40 UTC
Another regression: When /tmp is a regular filesystem, and we're running ostree as non-root (as the installed tests do), we want to ignore EPERM.

I didn't notice this on my laptop because it's RHEL7 Workstation default of tmpfs-on-/tmp, but the current gnome-continuous build server is RHEL6, and I'm seeing:

http://build.gnome.org/continuous/buildmaster/builds/2014/06/04/38/integrationtest/work-gnome-continuous-x86_64-runtime/installed-test-results/ostree_test-admin-deploy-switch.test/output.txt
Comment 12 Colin Walters 2014-06-04 22:26:42 UTC
Created attachment 277910 [details] [review]
libostree: Silently ignore EPERM when setting EXT2_IMMUTABLE_FL

In the case of running ostree as non-root on a regular filesystem (not
tmpfs which doesn't support immutable), we should just silently do
nothing if we encounter EPERM.  Cache the result to avoid spam in
strace.
Comment 13 Jasper St. Pierre (not reading bugmail) 2014-06-09 18:15:34 UTC
Review of attachment 277910 [details] [review]:

OK.
Comment 14 Colin Walters 2014-06-09 18:44:29 UTC
Attachment 277910 [details] pushed as e31daf4 - libostree: Silently ignore EPERM when setting EXT2_IMMUTABLE_FL