Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
d53d0a01
Commit
d53d0a01
authored
Nov 25, 2016
by
Stéphane Graber
Committed by
GitHub
Nov 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1315 from brauner/2016-11-23/memfd_create
conf, criu: add make_anonymous_mount_file()
parents
3f37ede2
5ef5c9a3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
53 deletions
+124
-53
configure.ac
configure.ac
+2
-2
conf.c
src/lxc/conf.c
+120
-49
conf.h
src/lxc/conf.h
+1
-1
criu.c
src/lxc/criu.c
+1
-1
No files found.
configure.ac
View file @
d53d0a01
...
@@ -625,10 +625,10 @@ AC_CHECK_DECLS([PR_SET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
...
@@ -625,10 +625,10 @@ AC_CHECK_DECLS([PR_SET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
AC_CHECK_DECLS([PR_GET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
AC_CHECK_DECLS([PR_GET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
# Check for some headers
# Check for some headers
AC_CHECK_HEADERS([sys/signalfd.h pty.h ifaddrs.h sys/capability.h sys/personality.h utmpx.h sys/timerfd.h])
AC_CHECK_HEADERS([sys/signalfd.h pty.h ifaddrs.h sys/capability.h sys/
memfd.h sys/
personality.h utmpx.h sys/timerfd.h])
# Check for some syscalls functions
# Check for some syscalls functions
AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid])
AC_CHECK_FUNCS([setns pivot_root sethostname unshare rand_r confstr faccessat gettid
memfd_create
])
# Check for some functions
# Check for some functions
AC_CHECK_LIB(pthread, main)
AC_CHECK_LIB(pthread, main)
...
...
src/lxc/conf.c
View file @
d53d0a01
...
@@ -24,20 +24,33 @@
...
@@ -24,20 +24,33 @@
#define _GNU_SOURCE
#define _GNU_SOURCE
#include "config.h"
#include "config.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <inttypes.h>
#include <libgen.h>
#include <pwd.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <string.h>
#include <string.h>
#include <
dirent
.h>
#include <
time
.h>
#include <unistd.h>
#include <unistd.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <linux/loop.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/types.h>
#include <pwd.h>
#include <sys/utsname.h>
#include <grp.h>
#include <sys/wait.h>
#include <time.h>
#ifdef HAVE_STATVFS
#ifdef HAVE_STATVFS
#include <sys/statvfs.h>
#include <sys/statvfs.h>
...
@@ -49,37 +62,25 @@
...
@@ -49,37 +62,25 @@
#include <../include/openpty.h>
#include <../include/openpty.h>
#endif
#endif
#include <linux/loop.h>
#ifdef HAVE_LINUX_MEMFD_H
#include <linux/memfd.h>
#include <sys/types.h>
#endif
#include <sys/utsname.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <sys/prctl.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <libgen.h>
#include "bdev.h"
#include "network.h"
#include "error.h"
#include "af_unix.h"
#include "af_unix.h"
#include "parse.h"
#include "bdev.h"
#include "utils.h"
#include "caps.h"
/* for lxc_caps_last_cap() */
#include "cgroup.h"
#include "conf.h"
#include "conf.h"
#include "error.h"
#include "log.h"
#include "log.h"
#include "caps.h"
/* for lxc_caps_last_cap() */
#include "lxcaufs.h"
#include "lxcaufs.h"
#include "lxcoverlay.h"
#include "cgroup.h"
#include "lxclock.h"
#include "lxclock.h"
#include "lxcoverlay.h"
#include "lxcseccomp.h"
#include "namespace.h"
#include "namespace.h"
#include "network.h"
#include "parse.h"
#include "utils.h"
#include "lsm/lsm.h"
#include "lsm/lsm.h"
#if HAVE_SYS_CAPABILITY_H
#if HAVE_SYS_CAPABILITY_H
...
@@ -96,8 +97,6 @@
...
@@ -96,8 +97,6 @@
#include <mntent.h>
#include <mntent.h>
#endif
#endif
#include "lxcseccomp.h"
lxc_log_define
(
lxc_conf
,
lxc
);
lxc_log_define
(
lxc_conf
,
lxc
);
#define LINELEN 4096
#define LINELEN 4096
...
@@ -135,10 +134,10 @@ lxc_log_define(lxc_conf, lxc);
...
@@ -135,10 +134,10 @@ lxc_log_define(lxc_conf, lxc);
static
int
pivot_root
(
const
char
*
new_root
,
const
char
*
put_old
)
static
int
pivot_root
(
const
char
*
new_root
,
const
char
*
put_old
)
{
{
#ifdef __NR_pivot_root
#ifdef __NR_pivot_root
return
syscall
(
__NR_pivot_root
,
new_root
,
put_old
);
return
syscall
(
__NR_pivot_root
,
new_root
,
put_old
);
#else
#else
errno
=
ENOSYS
;
errno
=
ENOSYS
;
return
-
1
;
return
-
1
;
#endif
#endif
}
}
#else
#else
...
@@ -150,10 +149,10 @@ extern int pivot_root(const char * new_root, const char * put_old);
...
@@ -150,10 +149,10 @@ extern int pivot_root(const char * new_root, const char * put_old);
static
int
sethostname
(
const
char
*
name
,
size_t
len
)
static
int
sethostname
(
const
char
*
name
,
size_t
len
)
{
{
#ifdef __NR_sethostname
#ifdef __NR_sethostname
return
syscall
(
__NR_sethostname
,
name
,
len
);
return
syscall
(
__NR_sethostname
,
name
,
len
);
#else
#else
errno
=
ENOSYS
;
errno
=
ENOSYS
;
return
-
1
;
return
-
1
;
#endif
#endif
}
}
#endif
#endif
...
@@ -167,6 +166,59 @@ return -1;
...
@@ -167,6 +166,59 @@ return -1;
#define MS_PRIVATE (1<<18)
#define MS_PRIVATE (1<<18)
#endif
#endif
/* memfd_create() */
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
#endif
#ifndef MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING 0x0002U
#endif
#ifndef HAVE_MEMFD_CREATE
static
int
memfd_create
(
const
char
*
name
,
unsigned
int
flags
)
{
#ifndef __NR_memfd_create
#if defined __i386__
#define __NR_memfd_create 356
#elif defined __x86_64__
#define __NR_memfd_create 319
#elif defined __arm__
#define __NR_memfd_create 385
#elif defined __aarch64__
#define __NR_memfd_create 279
#elif defined __s390__
#define __NR_memfd_create 350
#elif defined __powerpc__
#define __NR_memfd_create 360
#elif defined __sparc__
#define __NR_memfd_create 348
#elif defined __blackfin__
#define __NR_memfd_create 390
#elif defined __ia64__
#define __NR_memfd_create 1340
#elif defined _MIPS_SIM
#if _MIPS_SIM == _MIPS_SIM_ABI32
#define __NR_memfd_create 4354
#endif
#if _MIPS_SIM == _MIPS_SIM_NABI32
#define __NR_memfd_create 6318
#endif
#if _MIPS_SIM == _MIPS_SIM_ABI64
#define __NR_memfd_create 5314
#endif
#endif
#endif
#ifdef __NR_memfd_create
return
syscall
(
__NR_memfd_create
,
name
,
flags
);
#else
errno
=
ENOSYS
;
return
-
1
;
#endif
}
#else
extern
int
memfd_create
(
const
char
*
name
,
unsigned
int
flags
);
#endif
char
*
lxchook_names
[
NUM_LXC_HOOKS
]
=
{
char
*
lxchook_names
[
NUM_LXC_HOOKS
]
=
{
"pre-start"
,
"pre-mount"
,
"mount"
,
"autodev"
,
"start"
,
"stop"
,
"post-stop"
,
"clone"
,
"destroy"
};
"pre-start"
,
"pre-mount"
,
"mount"
,
"autodev"
,
"start"
,
"stop"
,
"post-stop"
,
"clone"
,
"destroy"
};
...
@@ -1950,34 +2002,53 @@ static int setup_mount(const struct lxc_rootfs *rootfs, const char *fstab,
...
@@ -1950,34 +2002,53 @@ static int setup_mount(const struct lxc_rootfs *rootfs, const char *fstab,
return
ret
;
return
ret
;
}
}
FILE
*
write
_mount_file
(
struct
lxc_list
*
mount
)
FILE
*
make_anonymous
_mount_file
(
struct
lxc_list
*
mount
)
{
{
FILE
*
file
;
int
ret
;
struct
lxc_list
*
iterator
;
char
*
mount_entry
;
char
*
mount_entry
;
struct
lxc_list
*
iterator
;
FILE
*
file
;
int
fd
=
-
1
;
fd
=
memfd_create
(
"lxc_mount_file"
,
MFD_CLOEXEC
);
if
(
fd
<
0
)
{
if
(
errno
!=
ENOSYS
)
return
NULL
;
file
=
tmpfile
();
file
=
tmpfile
();
}
else
{
file
=
fdopen
(
fd
,
"r+"
);
}
if
(
!
file
)
{
if
(
!
file
)
{
ERROR
(
"Could not create temporary file: %s."
,
strerror
(
errno
));
if
(
fd
!=
-
1
)
close
(
fd
);
ERROR
(
"Could not create mount entry file: %s."
,
strerror
(
errno
));
return
NULL
;
return
NULL
;
}
}
lxc_list_for_each
(
iterator
,
mount
)
{
lxc_list_for_each
(
iterator
,
mount
)
{
mount_entry
=
iterator
->
elem
;
mount_entry
=
iterator
->
elem
;
fprintf
(
file
,
"%s
\n
"
,
mount_entry
);
ret
=
fprintf
(
file
,
"%s
\n
"
,
mount_entry
);
if
(
ret
<
strlen
(
mount_entry
))
WARN
(
"Could not write mount entry to anonymous mount file."
);
}
if
(
fseek
(
file
,
0
,
SEEK_SET
)
<
0
)
{
fclose
(
file
);
return
NULL
;
}
}
rewind
(
file
);
return
file
;
return
file
;
}
}
static
int
setup_mount_entries
(
const
struct
lxc_rootfs
*
rootfs
,
struct
lxc_list
*
mount
,
static
int
setup_mount_entries
(
const
struct
lxc_rootfs
*
rootfs
,
const
char
*
lxc_name
,
const
char
*
lxc_path
)
struct
lxc_list
*
mount
,
const
char
*
lxc_name
,
const
char
*
lxc_path
)
{
{
FILE
*
file
;
FILE
*
file
;
int
ret
;
int
ret
;
file
=
write
_mount_file
(
mount
);
file
=
make_anonymous
_mount_file
(
mount
);
if
(
!
file
)
if
(
!
file
)
return
-
1
;
return
-
1
;
...
...
src/lxc/conf.h
View file @
d53d0a01
...
@@ -452,6 +452,6 @@ extern int parse_mntopts(const char *mntopts, unsigned long *mntflags,
...
@@ -452,6 +452,6 @@ extern int parse_mntopts(const char *mntopts, unsigned long *mntflags,
extern
void
tmp_proc_unmount
(
struct
lxc_conf
*
lxc_conf
);
extern
void
tmp_proc_unmount
(
struct
lxc_conf
*
lxc_conf
);
void
remount_all_slave
(
void
);
void
remount_all_slave
(
void
);
extern
void
suggest_default_idmap
(
void
);
extern
void
suggest_default_idmap
(
void
);
FILE
*
write
_mount_file
(
struct
lxc_list
*
mount
);
FILE
*
make_anonymous
_mount_file
(
struct
lxc_list
*
mount
);
struct
lxc_list
*
sort_cgroup_settings
(
struct
lxc_list
*
cgroup_settings
);
struct
lxc_list
*
sort_cgroup_settings
(
struct
lxc_list
*
cgroup_settings
);
#endif
#endif
src/lxc/criu.c
View file @
d53d0a01
...
@@ -330,7 +330,7 @@ static void exec_criu(struct criu_opts *opts)
...
@@ -330,7 +330,7 @@ static void exec_criu(struct criu_opts *opts)
DECLARE_ARG
(
opts
->
user
->
action_script
);
DECLARE_ARG
(
opts
->
user
->
action_script
);
}
}
mnts
=
write
_mount_file
(
&
opts
->
c
->
lxc_conf
->
mount_list
);
mnts
=
make_anonymous
_mount_file
(
&
opts
->
c
->
lxc_conf
->
mount_list
);
if
(
!
mnts
)
if
(
!
mnts
)
goto
err
;
goto
err
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment