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
e1b9d6af
Unverified
Commit
e1b9d6af
authored
Feb 03, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: make lxc_create_tmp_proc_mount() static
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
fdb57ab4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
72 deletions
+71
-72
conf.c
src/lxc/conf.c
+71
-0
utils.c
src/lxc/utils.c
+0
-71
utils.h
src/lxc/utils.h
+0
-1
No files found.
src/lxc/conf.c
View file @
e1b9d6af
...
@@ -2952,6 +2952,77 @@ again:
...
@@ -2952,6 +2952,77 @@ again:
return
freeid
;
return
freeid
;
}
}
/*
* Mount a proc under @rootfs if proc self points to a pid other than
* my own. This is needed to have a known-good proc mount for setting
* up LSMs both at container startup and attach.
*
* @rootfs : the rootfs where proc should be mounted
*
* Returns < 0 on failure, 0 if the correct proc was already mounted
* and 1 if a new proc was mounted.
*
* NOTE: not to be called from inside the container namespace!
*/
static
int
lxc_mount_proc_if_needed
(
const
char
*
rootfs
)
{
char
path
[
PATH_MAX
]
=
{
0
};
int
link_to_pid
,
linklen
,
mypid
,
ret
;
char
link
[
INTTYPE_TO_STRLEN
(
pid_t
)]
=
{
0
};
ret
=
snprintf
(
path
,
PATH_MAX
,
"%s/proc/self"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"The name of proc path is too long"
);
return
-
1
;
}
linklen
=
readlink
(
path
,
link
,
sizeof
(
link
));
ret
=
snprintf
(
path
,
PATH_MAX
,
"%s/proc"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"The name of proc path is too long"
);
return
-
1
;
}
/* /proc not mounted */
if
(
linklen
<
0
)
{
if
(
mkdir
(
path
,
0755
)
&&
errno
!=
EEXIST
)
return
-
1
;
goto
domount
;
}
else
if
(
linklen
>=
sizeof
(
link
))
{
link
[
linklen
-
1
]
=
'\0'
;
ERROR
(
"Readlink returned truncated content:
\"
%s
\"
"
,
link
);
return
-
1
;
}
mypid
=
lxc_raw_getpid
();
INFO
(
"I am %d, /proc/self points to
\"
%s
\"
"
,
mypid
,
link
);
if
(
lxc_safe_int
(
link
,
&
link_to_pid
)
<
0
)
return
-
1
;
/* correct procfs is already mounted */
if
(
link_to_pid
==
mypid
)
return
0
;
ret
=
umount2
(
path
,
MNT_DETACH
);
if
(
ret
<
0
)
SYSWARN
(
"Failed to umount
\"
%s
\"
with MNT_DETACH"
,
path
);
domount:
/* rootfs is NULL */
if
(
!
strcmp
(
rootfs
,
""
))
ret
=
mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
);
else
ret
=
safe_mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
,
rootfs
);
if
(
ret
<
0
)
return
-
1
;
INFO
(
"Mounted /proc in container for security transition"
);
return
1
;
}
/* NOTE: Must not be called from inside the container namespace! */
/* NOTE: Must not be called from inside the container namespace! */
static
int
lxc_create_tmp_proc_mount
(
struct
lxc_conf
*
conf
)
static
int
lxc_create_tmp_proc_mount
(
struct
lxc_conf
*
conf
)
{
{
...
...
src/lxc/utils.c
View file @
e1b9d6af
...
@@ -1208,77 +1208,6 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
...
@@ -1208,77 +1208,6 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
return
0
;
return
0
;
}
}
/*
* Mount a proc under @rootfs if proc self points to a pid other than
* my own. This is needed to have a known-good proc mount for setting
* up LSMs both at container startup and attach.
*
* @rootfs : the rootfs where proc should be mounted
*
* Returns < 0 on failure, 0 if the correct proc was already mounted
* and 1 if a new proc was mounted.
*
* NOTE: not to be called from inside the container namespace!
*/
int
lxc_mount_proc_if_needed
(
const
char
*
rootfs
)
{
char
path
[
PATH_MAX
]
=
{
0
};
int
link_to_pid
,
linklen
,
mypid
,
ret
;
char
link
[
INTTYPE_TO_STRLEN
(
pid_t
)]
=
{
0
};
ret
=
snprintf
(
path
,
PATH_MAX
,
"%s/proc/self"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"The name of proc path is too long"
);
return
-
1
;
}
linklen
=
readlink
(
path
,
link
,
sizeof
(
link
));
ret
=
snprintf
(
path
,
PATH_MAX
,
"%s/proc"
,
rootfs
);
if
(
ret
<
0
||
ret
>=
PATH_MAX
)
{
SYSERROR
(
"The name of proc path is too long"
);
return
-
1
;
}
/* /proc not mounted */
if
(
linklen
<
0
)
{
if
(
mkdir
(
path
,
0755
)
&&
errno
!=
EEXIST
)
return
-
1
;
goto
domount
;
}
else
if
(
linklen
>=
sizeof
(
link
))
{
link
[
linklen
-
1
]
=
'\0'
;
ERROR
(
"Readlink returned truncated content:
\"
%s
\"
"
,
link
);
return
-
1
;
}
mypid
=
lxc_raw_getpid
();
INFO
(
"I am %d, /proc/self points to
\"
%s
\"
"
,
mypid
,
link
);
if
(
lxc_safe_int
(
link
,
&
link_to_pid
)
<
0
)
return
-
1
;
/* correct procfs is already mounted */
if
(
link_to_pid
==
mypid
)
return
0
;
ret
=
umount2
(
path
,
MNT_DETACH
);
if
(
ret
<
0
)
SYSWARN
(
"Failed to umount
\"
%s
\"
with MNT_DETACH"
,
path
);
domount:
/* rootfs is NULL */
if
(
!
strcmp
(
rootfs
,
""
))
ret
=
mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
);
else
ret
=
safe_mount
(
"proc"
,
path
,
"proc"
,
0
,
NULL
,
rootfs
);
if
(
ret
<
0
)
return
-
1
;
INFO
(
"Mounted /proc in container for security transition"
);
return
1
;
}
int
open_devnull
(
void
)
int
open_devnull
(
void
)
{
{
int
fd
=
open
(
"/dev/null"
,
O_RDWR
);
int
fd
=
open
(
"/dev/null"
,
O_RDWR
);
...
...
src/lxc/utils.h
View file @
e1b9d6af
...
@@ -144,7 +144,6 @@ __hidden extern bool switch_to_ns(pid_t pid, const char *ns);
...
@@ -144,7 +144,6 @@ __hidden extern bool switch_to_ns(pid_t pid, const char *ns);
__hidden
extern
char
*
get_template_path
(
const
char
*
t
);
__hidden
extern
char
*
get_template_path
(
const
char
*
t
);
__hidden
extern
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
__hidden
extern
int
safe_mount
(
const
char
*
src
,
const
char
*
dest
,
const
char
*
fstype
,
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
unsigned
long
flags
,
const
void
*
data
,
const
char
*
rootfs
);
__hidden
extern
int
lxc_mount_proc_if_needed
(
const
char
*
rootfs
);
__hidden
extern
int
open_devnull
(
void
);
__hidden
extern
int
open_devnull
(
void
);
__hidden
extern
int
set_stdfds
(
int
fd
);
__hidden
extern
int
set_stdfds
(
int
fd
);
__hidden
extern
int
null_stdfds
(
void
);
__hidden
extern
int
null_stdfds
(
void
);
...
...
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