Skip to content

Commit

Permalink
core: Refuse mount on symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
nefelim4ag authored and poettering committed Aug 14, 2014
1 parent 1bd27a4 commit 5261ba9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,23 @@ void warn_if_dir_nonempty(const char *unit, const char* where) {
NULL);
}

static int fail_if_symlink(const char *unit, const char* where) {
assert(where);

if (is_symlink(where) > 0) {
log_struct_unit(LOG_WARNING,
unit,
"MESSAGE=%s: Mount on symlink %s not allowed.",
unit, where,
"WHERE=%s", where,
MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
NULL);

return -ELOOP;
}
return 0;
}

static void mount_enter_unmounting(Mount *m) {
int r;

Expand Down Expand Up @@ -877,6 +894,10 @@ static void mount_enter_mounting(Mount *m) {
if (p && mount_is_bind(p))
mkdir_p_label(p->what, m->directory_mode);

r = fail_if_symlink(m->meta.id, m->where);
if (r < 0)
goto fail;

if (m->from_fragment)
r = exec_command_set(
m->control_command,
Expand Down
12 changes: 12 additions & 0 deletions src/shared/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6918,3 +6918,15 @@ int take_password_lock(const char *root) {

return fd;
}

int is_symlink(const char *path) {
struct stat info;

if (lstat(path, &info) < 0)
return -errno;

if (S_ISLNK(info.st_mode))
return 1;

return 0;
}
2 changes: 2 additions & 0 deletions src/shared/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,5 @@ char *tempfn_random(const char *p);
bool is_localhost(const char *hostname);

int take_password_lock(const char *root);

int is_symlink(const char *path);

0 comments on commit 5261ba9

Please sign in to comment.