Skip to content

Commit 1cb1675

Browse files
committed
lxcfs: introduce new option --allow-write-on-cgroup
During our private discussion, Stéphane proposed to add a new option to explicitly allow write() syscall for cgroupfs. For a compatibility sake, I kept writes allowed if lxcfs daemon version is very old (has no support for versionized struct lxcfs_opts), but for all new versions by default writing is forbidden. It's worth mentioning that cgroup code in LXCFS is not widely used, because it was written before cgroup namespace era and not actual these days. Signed-off-by: Alexander Mikhalitsyn <[email protected]>
1 parent ce8e6e9 commit 1cb1675

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

src/bindings.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct lxcfs_opts {
116116
* and the use of bool instead of explicited __u32 and __u64 we can't.
117117
*/
118118
__u32 version;
119+
bool allow_write_on_cgroup;
119120
};
120121

121122
typedef enum lxcfs_opt_t {

src/cgroup_fuse.c

+4
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ __lxcfs_fuse_ops int cg_write(const char *path, const char *buf, size_t size,
17761776
off_t offset, struct fuse_file_info *fi)
17771777
{
17781778
struct fuse_context *fc = fuse_get_context();
1779+
const struct lxcfs_opts *opts = fc->private_data;
17791780
char *localbuf = NULL;
17801781
struct cgfs_files *k = NULL;
17811782
struct file_info *f = INTTYPE_TO_PTR(fi->fh);
@@ -1792,6 +1793,9 @@ __lxcfs_fuse_ops int cg_write(const char *path, const char *buf, size_t size,
17921793
return -EIO;
17931794
}
17941795

1796+
if (liblxcfs_has_versioned_opts() && opts && opts->version > 1 && !opts->allow_write_on_cgroup)
1797+
return -EACCES;
1798+
17951799
if (offset)
17961800
return 0;
17971801

src/lxcfs.c

+28-23
Original file line numberDiff line numberDiff line change
@@ -1179,17 +1179,18 @@ static void usage(void)
11791179
lxcfs_info("Usage: lxcfs <directory>\n");
11801180
lxcfs_info("lxcfs is a FUSE-based proc, sys and cgroup virtualizing filesystem\n");
11811181
lxcfs_info("Options :");
1182-
lxcfs_info(" -d, --debug Run lxcfs with debugging enabled");
1183-
lxcfs_info(" -f, --foreground Run lxcfs in the foreground");
1184-
lxcfs_info(" -h, --help Print help");
1185-
lxcfs_info(" -l, --enable-loadavg Enable loadavg virtualization");
1186-
lxcfs_info(" -o Options to pass directly through fuse");
1187-
lxcfs_info(" -p, --pidfile=FILE Path to use for storing lxcfs pid");
1188-
lxcfs_info(" Default pidfile is %s/lxcfs.pid", RUNTIME_PATH);
1189-
lxcfs_info(" -u, --disable-swap Disable swap virtualization");
1190-
lxcfs_info(" -v, --version Print lxcfs version");
1191-
lxcfs_info(" --enable-cfs Enable CPU virtualization via CPU shares");
1192-
lxcfs_info(" --enable-pidfd Use pidfd for process tracking");
1182+
lxcfs_info(" -d, --debug Run lxcfs with debugging enabled");
1183+
lxcfs_info(" -f, --foreground Run lxcfs in the foreground");
1184+
lxcfs_info(" -h, --help Print help");
1185+
lxcfs_info(" -l, --enable-loadavg Enable loadavg virtualization");
1186+
lxcfs_info(" -o Options to pass directly through fuse");
1187+
lxcfs_info(" -p, --pidfile=FILE Path to use for storing lxcfs pid");
1188+
lxcfs_info(" Default pidfile is %s/lxcfs.pid", RUNTIME_PATH);
1189+
lxcfs_info(" -u, --disable-swap Disable swap virtualization");
1190+
lxcfs_info(" -v, --version Print lxcfs version");
1191+
lxcfs_info(" --enable-cfs Enable CPU virtualization via CPU shares");
1192+
lxcfs_info(" --enable-pidfd Use pidfd for process tracking");
1193+
lxcfs_info(" --allow-write-on-cgroup Allow write() syscall on cgroup lxcfs subtree");
11931194
exit(EXIT_FAILURE);
11941195
}
11951196

@@ -1229,17 +1230,18 @@ static int set_pidfile(char *pidfile)
12291230
}
12301231

12311232
static const struct option long_options[] = {
1232-
{"debug", no_argument, 0, 'd' },
1233-
{"disable-swap", no_argument, 0, 'u' },
1234-
{"enable-loadavg", no_argument, 0, 'l' },
1235-
{"foreground", no_argument, 0, 'f' },
1236-
{"help", no_argument, 0, 'h' },
1237-
{"version", no_argument, 0, 'v' },
1238-
1239-
{"enable-cfs", no_argument, 0, 0 },
1240-
{"enable-pidfd", no_argument, 0, 0 },
1241-
1242-
{"pidfile", required_argument, 0, 'p' },
1233+
{"debug", no_argument, 0, 'd' },
1234+
{"disable-swap", no_argument, 0, 'u' },
1235+
{"enable-loadavg", no_argument, 0, 'l' },
1236+
{"foreground", no_argument, 0, 'f' },
1237+
{"help", no_argument, 0, 'h' },
1238+
{"version", no_argument, 0, 'v' },
1239+
1240+
{"enable-cfs", no_argument, 0, 0 },
1241+
{"enable-pidfd", no_argument, 0, 0 },
1242+
{"allow-write-on-cgroup", no_argument, 0, 0 },
1243+
1244+
{"pidfile", required_argument, 0, 'p' },
12431245
{ },
12441246
};
12451247

@@ -1309,7 +1311,8 @@ int main(int argc, char *argv[])
13091311
opts->swap_off = false;
13101312
opts->use_pidfd = false;
13111313
opts->use_cfs = false;
1312-
opts->version = 1;
1314+
opts->version = 2;
1315+
opts->allow_write_on_cgroup = false;
13131316

13141317
while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
13151318
switch (c) {
@@ -1318,6 +1321,8 @@ int main(int argc, char *argv[])
13181321
opts->use_pidfd = true;
13191322
else if (strcmp(long_options[idx].name, "enable-cfs") == 0)
13201323
opts->use_cfs = true;
1324+
else if (strcmp(long_options[idx].name, "allow-write-on-cgroup") == 0)
1325+
opts->allow_write_on_cgroup = true;
13211326
else
13221327
usage();
13231328
break;

0 commit comments

Comments
 (0)