Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cmd/snap-confine: prevent cwd restore permission bypass #6642

Merged
merged 30 commits into from
Apr 10, 2019
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fcfef2
cmd/snap-confine: prevent cwd restore permission bypass
zyga Mar 22, 2019
4128481
Merge branch 'fix/suse-audit-5' into fix/suse-audit-2
zyga Mar 25, 2019
29397b7
Merge branch 'fix/suse-audit-5' into fix/suse-audit-2
zyga Mar 25, 2019
ce983c2
cmd/snap-confine: add missing fd subdirectory
zyga Mar 25, 2019
d6ec606
cmd/snap-confine: fix typo "than"
zyga Mar 25, 2019
6a35141
Merge branch 'master' into fix/suse-audit-2
zyga Mar 25, 2019
9f55031
cmd/snap-confine: use O_DIRECTORY for opening cwd
zyga Mar 25, 2019
6920052
cmd/snap-confine: reword paragraph entry
zyga Mar 25, 2019
2336a77
cmd/snap-confine: remove redundant paragraph
zyga Mar 25, 2019
0fe6571
cmd/snap-confine: use definite article for the void dir
zyga Mar 25, 2019
5ce302e
cmd/snap-confine: start cwd in outer namespace
zyga Mar 25, 2019
a9da766
cmd/snap-confine: always use fchdir + inner_cwd_fd
zyga Mar 25, 2019
7d63105
cmd/snap-confine: explicit ENOENT handling
zyga Mar 25, 2019
c373fa6
cmd/snap-confine: reindent new code
zyga Mar 25, 2019
47a5be8
cmd/snap-confine: comment when changing state
zyga Mar 25, 2019
9ba734a
cmd/snap-confine: move to void on permission errors
zyga Mar 26, 2019
7098613
tests: remove trailing whitespace
zyga Mar 26, 2019
758c968
packaging,tests: ensure that /var/lib/snapd/void is mode 111
zyga Mar 28, 2019
29660f6
cmd/snap-confine: explain motivation for inode check
zyga Mar 28, 2019
ddaf146
tests: rename pwd to cwd
zyga Apr 4, 2019
773d1d8
tests: remove core18 workaround
zyga Apr 4, 2019
e82323d
tests: show permissions on failure
zyga Apr 4, 2019
803da81
Merge branch 'master' of github.com:snapcore/snapd into fix/suse-audit-2
zyga Apr 4, 2019
07cd4fa
tests: system-data/root should be 0755
zyga Apr 4, 2019
04e343b
cmd/snap-confine: goto void on E{PERM,ACCESS} orig dir
zyga Apr 4, 2019
b05a2aa
tests: use mkdir -m without -p
zyga Apr 4, 2019
47018f0
cmd/snap-confine: create the void directory on demand
zyga Apr 8, 2019
44a0f52
tests: move early check for void dir
zyga Apr 8, 2019
6c81b9b
cmd/snap-confine: move definition of void_dir_fd
zyga Apr 8, 2019
c9edbe5
Merge remote-tracking branch 'origin/master' into fix/suse-audit-2
zyga Apr 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cmd/snap-confine: start cwd in outer namespace
Inspect the current working directory in the initial mount namespace.
While this doesn't change anything it is more natural and more resilient
to breakage in case kernel changes semantics of fstatfs invoked across
unshare/setns.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Mar 25, 2019
commit 5ce302e36170897ee16fd9898a9d7a7cf020e05c
24 changes: 15 additions & 9 deletions cmd/snap-confine/snap-confine.c
Original file line number Diff line number Diff line change
@@ -106,6 +106,7 @@ static void sc_maybe_fixup_udev(void)
typedef struct sc_preserved_process_state {
mode_t orig_umask;
int orig_cwd_fd;
struct stat file_info_orig_cwd;
} sc_preserved_process_state;

/**
@@ -128,10 +129,14 @@ static void sc_preserve_and_sanitize_process_state(sc_preserved_process_state *
* directory. This is an O_PATH file descriptor. The descriptor is
* used as explained below. */
proc_state->orig_cwd_fd =
openat(AT_FDCWD, ".", O_PATH | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
openat(AT_FDCWD, ".",
O_PATH | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (proc_state->orig_cwd_fd < 0) {
die("cannot open path of the current working directory");
}
if (fstat(proc_state->orig_cwd_fd, &proc_state->file_info_orig_cwd) < 0) {
die("cannot stat path of the current working directory");
}
if (chdir("/") < 0) {
die("cannot move to /");
}
@@ -180,7 +185,8 @@ static void sc_restore_process_state(const sc_preserved_process_state *
* execution environment. This may normally fail if the path no longer
* exists here, this is not a fatal error. */
int inner_cwd_fd SC_CLEANUP(sc_cleanup_close) = -1;
inner_cwd_fd = open(orig_cwd, O_PATH | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
inner_cwd_fd =
open(orig_cwd, O_PATH | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (inner_cwd_fd < 0 && errno != ENOENT) {
die("cannot open path of the original working directory %s (%d)", orig_cwd, errno);
}
@@ -195,19 +201,19 @@ static void sc_restore_process_state(const sc_preserved_process_state *
}
debug("cannot represent original working directory %s",
orig_cwd);
debug("the process has been placed in the special void directory");
debug
("the process has been placed in the special void directory");
} else {
/* The original working directory exists in the execution environment
* which lets us check if it points to the same inode as before. */
struct stat file_info_outer, file_info_inner;
if (fstat(proc_state->orig_cwd_fd, &file_info_outer) < 0) {
die("cannot stat path of working directory in the host environment");
}
struct stat file_info_inner;
if (fstat(inner_cwd_fd, &file_info_inner) < 0) {
die("cannot stat path of working directory in the execution environment");
}
if (file_info_outer.st_dev == file_info_inner.st_dev &&
file_info_outer.st_ino == file_info_inner.st_ino) {
if (proc_state->file_info_orig_cwd.st_dev ==
file_info_inner.st_dev
&& proc_state->file_info_orig_cwd.st_ino ==
file_info_inner.st_ino) {
/* The path of the original working directory points to the same
* inode as before. Use fchdir to change to that directory.
*