Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
cmd/snap-update-ns: create missing mount points automatically. #4008
Merged
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
921ad9b
cmd/snap-update-ns: expand tests to mock os.{Lstat,MkdirAll,Chown}
zyga dc32ac4
cmd/snap-update-ns: create missing mount points
zyga 59c20b8
cmd/snap-confine: allow snap-update-ns to mkdir under $SNAP_DATA
zyga dcb715c
Merge branch 'master' of github.com:snapcore/snapd into feature/chang…
zyga b38baed
cmd/snap-update-ns: add SecureMkdirAll
zyga 1a953f5
cmd/snap-update-ns: explain why we are using SecureMkdirAll
zyga 4085659
cmd/snap-update-ns: improve tests
zyga e875914
cmd/libsnap: tweak comments
zyga 9787ce6
cmd/snap-update-ns: fix typo
zyga 02337df
cmd/snap-update-ns: add freezer support code
zyga bf710f9
cmd/snap-update-ns: allow snap-update-ns to freeze and thaw
zyga aaf59b3
cmd/snap-update-ns: update apparmor profile for SecureMkdirAt
zyga 244efa3
cmd/snap-update-ns: freeze snap processes during update
zyga d1d9963
cmd/snap-update-ns: create bind mount source directory automatically
zyga a6e00a0
tests: add test for content interface mkdir capability
zyga d4fb3f8
cmd/snap-update-ns: reject mounting affecting symlinks
zyga f6fad40
cmd/snap-update-ns: update stale comment
zyga 5870e35
cmd/snap-update-ns: add tests for the freezer code
zyga e759463
cmd/snap-update-ns: chown created directory segments
zyga 29b7bfc
Merge branch 'master' of github.com:snapcore/snapd into feature/chang…
zyga bb48fb1
Merge branch 'master' into feature/change-simple-mkdir
zyga 08cd312
cmd/snap-update-ns: fix typo
zyga 9ea7f84
interfaces/mount: add OptsToCommonFlags
zyga 9b187b4
cmd/snap-update-ns: minimize diff with upcoming overlayfs
zyga 9c825ed
cmd/snap-confine: constrain profile to write directories
zyga 9bbd55b
cmd/snap-update-ns: drop TODO comment
zyga 3f03c5c
cmd/snap-update-ns: document freezeSnapProcesses
zyga 74c7b66
cmd/snap-update-ns: fail if we cannot actually freeze processes
zyga 14a3e0f
cmd/snap-update-ns: thaw partially frozen processes when failing
zyga 08189e1
cmd/snap-update-ns: increase FREEZING timeout to 3s
zyga e27e692
cmd/snap-update-ns: correct wrong comment
zyga c7f1cc4
cmd/snap-update-ns: disallow creating relative directories
zyga 73a4214
cmd/snap-update-ns: use stronger comment about freeze state
zyga d5c0d1a
Merge branch 'master' of github.com:snapcore/snapd into feature/chang…
zyga 112703a
cmd/snap-update-ns: close and ensure all FDs are closed
zyga bc5f97d
cmd/snap-update-ns: use colon to spearate error messages
zyga bcd5fdf
cmd/snap-update-ns: clarify attack surface
zyga c251b0d
cmd/snap-update-ns: rewrite comment
zyga 1a4d212
cmd/snap-update-ns: use defer instead of hand-held close
zyga 45cd226
cmd/snap-update-ns: drop the Impl suffix
zyga 5e373cd
cmd/snap-update-ns: switch to filepath
zyga 433abfa
cmd/snap-update-ns: clarify why we support only abs paths
zyga 07b54a1
cmd/snap-update-ns: use O_PATH for secureMkdirAt
zyga 0fb6f44
cmd/snap-update-ns: use strings.FieldsFunc instead of Split
zyga b43daa0
Revert "cmd/snap-update-ns: use O_PATH for secureMkdirAt"
zyga e32ac7b
Merge branch 'master' of github.com:snapcore/snapd into feature/chang…
zyga
Jump to file or symbol
Failed to load files and symbols.
| @@ -21,7 +21,8 @@ package main | ||
| import ( | ||
| "fmt" | ||
| - "path" | ||
| + "os" | ||
| + "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "syscall" | ||
| @@ -53,26 +54,40 @@ func (c Change) String() string { | ||
| return fmt.Sprintf("%s (%s)", c.Action, c.Entry) | ||
| } | ||
| -var ( | ||
| - sysMount = syscall.Mount | ||
| - sysUnmount = syscall.Unmount | ||
| -) | ||
| - | ||
| -const unmountNoFollow = 8 | ||
| - | ||
| // Perform executes the desired mount or unmount change using system calls. | ||
| // Filesystems that depend on helper programs or multiple independent calls to | ||
| // the kernel (--make-shared, for example) are unsupported. | ||
| func (c *Change) Perform() error { | ||
| - switch c.Action { | ||
| - case Mount: | ||
| - flags, err := mount.OptsToFlags(c.Entry.Options) | ||
| - if err != nil { | ||
| + if c.Action == Mount { | ||
| + mode := os.FileMode(0755) | ||
| + uid := 0 | ||
| + gid := 0 | ||
| + // Create target mount directory if needed. | ||
| + if err := ensureMountPoint(c.Entry.Dir, mode, uid, gid); err != nil { | ||
| return err | ||
| } | ||
| - return sysMount(c.Entry.Name, c.Entry.Dir, c.Entry.Type, uintptr(flags), "") | ||
| + // If this is a bind mount then create the source directory as well. | ||
| + // This allows snaps to share a subset of their data easily. | ||
| + flags, _ := mount.OptsToCommonFlags(c.Entry.Options) | ||
| + if flags&syscall.MS_BIND != 0 { | ||
| + if err := ensureMountPoint(c.Entry.Name, mode, uid, gid); err != nil { | ||
| + return err | ||
| + } | ||
| + } | ||
| + } | ||
| + return c.lowLevelPerform() | ||
| +} | ||
| + | ||
| +// lowLevelPerform is simple bridge from Change to mount / unmount syscall. | ||
| +func (c *Change) lowLevelPerform() error { | ||
| + switch c.Action { | ||
| + case Mount: | ||
| + flags, unparsed := mount.OptsToCommonFlags(c.Entry.Options) | ||
| + return sysMount(c.Entry.Name, c.Entry.Dir, c.Entry.Type, uintptr(flags), strings.Join(unparsed, ",")) | ||
zyga
Contributor
|
||
| case Unmount: | ||
| - return sysUnmount(c.Entry.Dir, unmountNoFollow) | ||
| + return sysUnmount(c.Entry.Dir, UMOUNT_NOFOLLOW) | ||
| + case Keep: | ||
| + return nil | ||
| } | ||
| return fmt.Errorf("cannot process mount change, unknown action: %q", c.Action) | ||
| } | ||
| @@ -94,10 +109,10 @@ func NeededChanges(currentProfile, desiredProfile *mount.Profile) []Change { | ||
| // easily test if a given directory is a subdirectory with | ||
| // strings.HasPrefix coupled with an extra slash character. | ||
| for i := range current { | ||
| - current[i].Dir = path.Clean(current[i].Dir) | ||
| + current[i].Dir = filepath.Clean(current[i].Dir) | ||
| } | ||
| for i := range desired { | ||
| - desired[i].Dir = path.Clean(desired[i].Dir) | ||
| + desired[i].Dir = filepath.Clean(desired[i].Dir) | ||
| } | ||
| // Sort both lists by directory name with implicit trailing slash. | ||
Oops, something went wrong.
It feels weird that we aren't doing any validation on unparsed. I realize that the fstab files are controlled by snapd, so not strictly a blocker, but this seems to be leaving us open to introducing a future bug if assumptions change. Can you explain the motivation for this? (Eg, the sysMount this is replacing used
"", but now you are usingstrings.Join(unparsed, ",").