Skip to content

Commit 94dffca

Browse files
authored
cmd/snap-update-ns: ensure that a /tmp/.X11-unix created inside the mount ns has expected permissions (#17001)
The /tmp/.X11-unix target path created inside the snap's mount ns is hidden when the mount added by the x11 interface is executed. However, to keep things consistent we should ensure that it is created with a reasonable mode, which matches what a typical /tmp/.X11-unix directory would have. Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
1 parent d84a50b commit 94dffca

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

cmd/snap-update-ns/system.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ func (upCtx *SystemProfileUpdateContext) Assumptions() *Assumptions {
9191
// permission only matters if the plug-side app constructs its mount
9292
// namespace before the slot-side app is launched.
9393
as.AddModeHint("/var/lib/snapd/hostfs/tmp/snap-private-tmp/snap.*/tmp/.X11-unix", 0777|os.ModeSticky)
94+
// This is to ensure the mount target directory /tmp/.X11-unix inside the
95+
// mount namespace is created with the same permissions as a typical host
96+
// /tmp/.X11-unix. When x11 interface is connected, the target path is
97+
// shadowed by a bind mount from the host, so the actual mode is only
98+
// visible when said interface is disconnected after being connected earlier
99+
// with the mount namespace being preserved.
100+
as.AddModeHint("/tmp/.X11-unix", 0777|os.ModeSticky)
94101
// This is to ensure private shared-memory directories have
95102
// the right permissions.
96103
as.AddModeHint("/dev/shm/snap.*", 0777|os.ModeSticky)

cmd/snap-update-ns/system_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func (s *systemSuite) TestAssumptions(c *C) {
8282
c.Check(as.ModeForPath("/var/lib/snapd/hostfs/tmp/snap-private-tmp/snap.x11-server/tmp"), Equals, os.FileMode(0777)|os.ModeSticky)
8383
c.Check(as.ModeForPath("/var/lib/snapd/hostfs/tmp/snap-private-tmp/snap.x11-server/foo"), Equals, os.FileMode(0755))
8484
c.Check(as.ModeForPath("/var/lib/snapd/hostfs/tmp/snap-private-tmp/snap.x11-server/tmp/.X11-unix"), Equals, os.FileMode(0777)|os.ModeSticky)
85+
c.Check(as.ModeForPath("/tmp/.X11-unix"), Equals, os.FileMode(0777)|os.ModeSticky)
8586
c.Check(as.ModeForPath("/dev/shm/snap.some-snap"), Equals, os.FileMode(0777)|os.ModeSticky)
8687

8788
// Instances can, in addition, access /snap/$SNAP_INSTANCE_NAME

0 commit comments

Comments
 (0)