X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fsecure-mount.c;h=53863e3af886e300d57c6a8528733284e037efa1;hb=925e69ce006ee22fbc35b8328dcd4942d9215c96;hp=1a3bc19c46410d86618a25a17f19a96f96aa22cb;hpb=54960d2e4b81d3cb3845365c06e0eea6efae15f5;p=util-vserver.git diff --git a/src/secure-mount.c b/src/secure-mount.c index 1a3bc19..53863e3 100644 --- a/src/secure-mount.c +++ b/src/secure-mount.c @@ -82,6 +82,7 @@ struct Options { bool mount_all; RootFsOption rootfs; + char cur_dir_path[PATH_MAX]; int cur_dir_fd; int cur_rootdir_fd; }; @@ -97,6 +98,7 @@ struct Options { #define XFLAG_NOAUTO 0x01 #define XFLAG_FILE 0x02 +#define XFLAG_NOMTAB 0x04 static struct option const CMDLINE_OPTIONS[] = { @@ -172,6 +174,7 @@ static struct FstabOption { { "private", MS_PRIVATE, MS_PRIVATE, 0, false }, { "slave", MS_SLAVE, MS_SLAVE, 0, false }, { "shared", MS_SHARED, MS_SHARED, 0, false }, + { "nomtab", 0, 0, XFLAG_NOMTAB, false }, }; int wrapper_exit_code = 1; @@ -445,7 +448,7 @@ canHandleInternal(struct MountInfo const *mnt) } static bool -mountSingle(struct MountInfo const *mnt, struct Options const *opt) +mountSingle(struct MountInfo const *mnt, struct Options *opt) { assert(mnt->dst!=0); @@ -459,7 +462,18 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) perror("secure-mount: mount()"); return false; } - if ((mnt->flag & MS_BIND) && + if (strcmp(mnt->dst, "/") == 0) { + /* XXX: Hack */ + if (chdir(opt->cur_dir_path) == -1) { + perror("secure-mount: chdir(.)"); + return false; + } + close(opt->cur_dir_fd); + opt->cur_dir_fd = Eopen(".", O_RDONLY|O_DIRECTORY, 0); + Efcntl(opt->cur_dir_fd, F_SETFD, FD_CLOEXEC); + } + if (!vc_isSupported(vcFEATURE_BME) && + (mnt->flag & MS_BIND) && (mnt->mask & ~(MS_BIND|MS_REC))) { /* This is needed to put us in the new mountpoint */ if (!secureChdir(mnt->dst, opt)) @@ -476,7 +490,7 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt) else if (!callExternalMount(mnt)) return false; - if (!opt->ignore_mtab && + if (!opt->ignore_mtab && (mnt->xflag & XFLAG_NOMTAB)==0 && updateMtab(mnt, opt)==-1) { WRITE_MSG(2, "Failed to update mtab-file\n"); // no error @@ -607,7 +621,7 @@ adjustFileMount(struct MountInfo *mnt) } static bool -mountFstab(struct Options const *opt) +mountFstab(struct Options *opt) { bool res = false; int fd; @@ -687,6 +701,11 @@ initFDs(struct Options *opt) Efcntl(opt->cur_dir_fd, F_SETFD, FD_CLOEXEC); Efcntl(opt->cur_rootdir_fd, F_SETFD, FD_CLOEXEC); + + if (getcwd(opt->cur_dir_path, sizeof(opt->cur_dir_path)) == NULL) { + perror("secure-mount: getcwd()"); + exit(wrapper_exit_code); + } } static RootFsOption