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
aeb0b9bf
Unverified
Commit
aeb0b9bf
authored
Feb 11, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tree-wide: rework mount api support checks
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
c0886b82
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
31 deletions
+61
-31
cgfsng.c
src/lxc/cgroups/cgfsng.c
+2
-2
conf.c
src/lxc/conf.c
+7
-7
mount_utils.c
src/lxc/mount_utils.c
+50
-0
mount_utils.h
src/lxc/mount_utils.h
+2
-22
No files found.
src/lxc/cgroups/cgfsng.c
View file @
aeb0b9bf
...
@@ -1799,7 +1799,7 @@ static int __cg_mount_direct(int type, struct hierarchy *h,
...
@@ -1799,7 +1799,7 @@ static int __cg_mount_direct(int type, struct hierarchy *h,
fstype
=
"cgroup"
;
fstype
=
"cgroup"
;
}
}
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
fd_fs
=
fs_prepare
(
fstype
,
-
EBADF
,
""
,
0
,
0
);
fd_fs
=
fs_prepare
(
fstype
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for %s"
,
fstype
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for %s"
,
fstype
);
...
@@ -1945,7 +1945,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
...
@@ -1945,7 +1945,7 @@ __cgfsng_ops static bool cgfsng_mount(struct cgroup_ops *ops,
* relying on RESOLVE_BENEATH so we need to skip the leading "/" in the
* relying on RESOLVE_BENEATH so we need to skip the leading "/" in the
* DEFAULT_CGROUP_MOUNTPOINT define.
* DEFAULT_CGROUP_MOUNTPOINT define.
*/
*/
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create new filesystem context for tmpfs"
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to create new filesystem context for tmpfs"
);
...
...
src/lxc/conf.c
View file @
aeb0b9bf
...
@@ -844,7 +844,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
...
@@ -844,7 +844,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
"Failed to unlink %d(%s)"
,
"Failed to unlink %d(%s)"
,
rootfs
->
dfd_dev
,
tty_name
);
rootfs
->
dfd_dev
,
tty_name
);
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
fd_bind_mount
(
tty
->
pty
,
""
,
ret
=
fd_bind_mount
(
tty
->
pty
,
""
,
PROTECT_OPATH_FILE
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
PROTECT_LOOKUP_BENEATH_XDEV
,
...
@@ -881,7 +881,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
...
@@ -881,7 +881,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
"Failed to create tty mount target %d(%s)"
,
"Failed to create tty mount target %d(%s)"
,
rootfs
->
dfd_dev
,
rootfs
->
buf
);
rootfs
->
dfd_dev
,
rootfs
->
buf
);
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
fd_bind_mount
(
tty
->
pty
,
""
,
ret
=
fd_bind_mount
(
tty
->
pty
,
""
,
PROTECT_OPATH_FILE
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
PROTECT_LOOKUP_BENEATH_XDEV
,
...
@@ -1074,7 +1074,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
...
@@ -1074,7 +1074,7 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
goto
reset_umask
;
goto
reset_umask
;
}
}
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
fd_fs
=
fs_prepare
(
"tmpfs"
,
-
EBADF
,
""
,
0
,
0
);
if
(
fd_fs
<
0
)
if
(
fd_fs
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for tmpfs"
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to prepare filesystem context for tmpfs"
);
...
@@ -1216,7 +1216,7 @@ static int lxc_fill_autodev(struct lxc_rootfs *rootfs)
...
@@ -1216,7 +1216,7 @@ static int lxc_fill_autodev(struct lxc_rootfs *rootfs)
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret_errno
(
EIO
);
return
ret_errno
(
EIO
);
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
fd_bind_mount
(
rootfs
->
dfd_host
,
rootfs
->
buf
,
ret
=
fd_bind_mount
(
rootfs
->
dfd_host
,
rootfs
->
buf
,
PROTECT_OPATH_FILE
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
PROTECT_LOOKUP_BENEATH_XDEV
,
...
@@ -1716,7 +1716,7 @@ static int lxc_setup_dev_console(struct lxc_rootfs *rootfs,
...
@@ -1716,7 +1716,7 @@ static int lxc_setup_dev_console(struct lxc_rootfs *rootfs,
if
(
ret
<
0
)
if
(
ret
<
0
)
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
lxc_bind_mount_console
(
console
,
rootfs
->
dfd_dev
,
"console"
);
ret
=
lxc_bind_mount_console
(
console
,
rootfs
->
dfd_dev
,
"console"
);
}
else
{
}
else
{
ret
=
strnprintf
(
rootfs
->
buf
,
sizeof
(
rootfs
->
buf
),
"%s/dev/console"
,
rootfs_path
);
ret
=
strnprintf
(
rootfs
->
buf
,
sizeof
(
rootfs
->
buf
),
"%s/dev/console"
,
rootfs_path
);
...
@@ -1779,7 +1779,7 @@ static int lxc_setup_ttydir_console(struct lxc_rootfs *rootfs,
...
@@ -1779,7 +1779,7 @@ static int lxc_setup_ttydir_console(struct lxc_rootfs *rootfs,
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
return
log_error_errno
(
-
errno
,
errno
,
"Failed to set mode
\"
0%o
\"
to
\"
%s
\"
"
,
S_IXUSR
|
S_IXGRP
,
console
->
name
);
/* bind mount console->name to '/dev/<ttydir>/console' */
/* bind mount console->name to '/dev/<ttydir>/console' */
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
strnprintf
(
rootfs
->
buf
,
sizeof
(
rootfs
->
buf
),
"%s/console"
,
ttydir
);
ret
=
strnprintf
(
rootfs
->
buf
,
sizeof
(
rootfs
->
buf
),
"%s/console"
,
ttydir
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
...
@@ -1793,7 +1793,7 @@ static int lxc_setup_ttydir_console(struct lxc_rootfs *rootfs,
...
@@ -1793,7 +1793,7 @@ static int lxc_setup_ttydir_console(struct lxc_rootfs *rootfs,
DEBUG
(
"Mounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
DEBUG
(
"Mounted
\"
%s
\"
onto
\"
%s
\"
"
,
console
->
name
,
lxcpath
);
/* bind mount '/dev/<ttydir>/console' to '/dev/console' */
/* bind mount '/dev/<ttydir>/console' to '/dev/console' */
if
(
new
_mount_api
())
{
if
(
can_use
_mount_api
())
{
ret
=
fd_bind_mount
(
rootfs
->
dfd_dev
,
rootfs
->
buf
,
ret
=
fd_bind_mount
(
rootfs
->
dfd_dev
,
rootfs
->
buf
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
rootfs
->
dfd_dev
,
"console"
,
rootfs
->
dfd_dev
,
"console"
,
...
...
src/lxc/mount_utils.c
View file @
aeb0b9bf
...
@@ -438,3 +438,53 @@ unsigned long add_required_remount_flags(const char *s, const char *d,
...
@@ -438,3 +438,53 @@ unsigned long add_required_remount_flags(const char *s, const char *d,
return
flags
;
return
flags
;
#endif
#endif
}
}
bool
can_use_mount_api
(
void
)
{
static
int
supported
=
-
1
;
if
(
supported
==
-
1
)
{
__do_close
int
fd
=
-
EBADF
;
fd
=
openat2
(
-
EBADF
,
""
,
NULL
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
fd
=
fsmount
(
-
EBADF
,
0
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
fd
=
fsconfig
(
-
EBADF
,
-
EINVAL
,
NULL
,
NULL
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
fd
=
fsopen
(
NULL
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
fd
=
move_mount
(
-
EBADF
,
NULL
,
-
EBADF
,
NULL
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
fd
=
open_tree
(
-
EBADF
,
NULL
,
0
);
if
(
fd
>
0
||
errno
==
ENOSYS
)
{
supported
=
0
;
return
false
;
}
supported
=
1
;
TRACE
(
"Kernel supports mount api"
);
}
return
supported
==
1
;
}
src/lxc/mount_utils.h
View file @
aeb0b9bf
...
@@ -185,28 +185,6 @@ __hidden extern int fd_bind_mount(int dfd_from, const char *path_from,
...
@@ -185,28 +185,6 @@ __hidden extern int fd_bind_mount(int dfd_from, const char *path_from,
__u64
o_flags_to
,
__u64
resolve_flags_to
,
__u64
o_flags_to
,
__u64
resolve_flags_to
,
unsigned
int
attr_flags
,
bool
recursive
);
unsigned
int
attr_flags
,
bool
recursive
);
/*
* We use openat2() as indicator whether or not the new mount api is supported.
* First, because openat2() has been introduced after all syscalls from the new
* mount api we currently use and second because our hardened mount logic
* relies on openat2() to safely resolve paths.
*/
static
inline
bool
new_mount_api
(
void
)
{
__do_close
int
fd
=
-
EBADF
;
static
int
supported
=
-
1
;
if
(
supported
==
-
1
)
{
fd
=
openat2
(
-
EBADF
,
""
,
NULL
,
0
);
if
(
fd
<
0
&&
errno
!=
ENOSYS
)
supported
=
1
;
else
supported
=
0
;
}
return
supported
==
1
;
}
__hidden
extern
int
calc_remount_flags_new
(
int
dfd_from
,
const
char
*
path_from
,
__hidden
extern
int
calc_remount_flags_new
(
int
dfd_from
,
const
char
*
path_from
,
__u64
o_flags_from
,
__u64
o_flags_from
,
__u64
resolve_flags_from
,
__u64
resolve_flags_from
,
...
@@ -223,4 +201,6 @@ __hidden extern unsigned long add_required_remount_flags(const char *s,
...
@@ -223,4 +201,6 @@ __hidden extern unsigned long add_required_remount_flags(const char *s,
const
char
*
d
,
const
char
*
d
,
unsigned
long
flags
);
unsigned
long
flags
);
__hidden
extern
bool
can_use_mount_api
(
void
);
#endif
/* __LXC_MOUNT_UTILS_H */
#endif
/* __LXC_MOUNT_UTILS_H */
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