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
b77578a4
Unverified
Commit
b77578a4
authored
Nov 24, 2017
by
Yifeng Tan
Committed by
Christian Brauner
Dec 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start.c: always switch uid and gid
Signed-off-by:
Yifeng Tan
<
tanyifeng1@huawei.com
>
Reviewed-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ca83bebe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
22 deletions
+23
-22
start.c
src/lxc/start.c
+23
-22
No files found.
src/lxc/start.c
View file @
b77578a4
...
...
@@ -797,10 +797,14 @@ void lxc_abort(const char *name, struct lxc_handler *handler)
static
int
do_start
(
void
*
data
)
{
int
ret
;
struct
lxc_list
*
iterator
;
struct
lxc_handler
*
handler
=
data
;
int
devnull_fd
=
-
1
,
ret
;
char
path
[
PATH_MAX
];
struct
lxc_handler
*
handler
=
data
;
bool
have_cap_setgid
;
uid_t
new_uid
;
gid_t
new_gid
;
int
devnull_fd
=
-
1
;
if
(
sigprocmask
(
SIG_SETMASK
,
&
handler
->
oldmask
,
NULL
))
{
SYSERROR
(
"Failed to set signal mask."
);
...
...
@@ -1034,30 +1038,27 @@ static int do_start(void *data)
/* The container has been setup. We can now switch to an unprivileged
* uid/gid.
*/
if
(
handler
->
conf
->
is_execute
)
{
bool
have_cap_setgid
;
uid_t
new_uid
=
handler
->
conf
->
init_uid
;
gid_t
new_gid
=
handler
->
conf
->
init_gid
;
/* If we are in a new user namespace we already dropped all
* groups when we switched to root in the new user namespace
* further above. Only drop groups if we can, so ensure that we
* have necessary privilege.
*/
#if HAVE_LIBCAP
have_cap_setgid
=
lxc_proc_cap_is_set
(
CAP_SETGID
,
CAP_EFFECTIVE
);
#else
have_cap_setgid
=
false
;
#endif
if
(
lxc_list_empty
(
&
handler
->
conf
->
id_map
)
&&
have_cap_setgid
)
{
if
(
lxc_setgroups
(
0
,
NULL
)
<
0
)
goto
out_warn_father
;
}
new_uid
=
handler
->
conf
->
init_uid
;
new_gid
=
handler
->
conf
->
init_gid
;
if
(
lxc_switch_uid_gid
(
new_uid
,
new_gid
)
<
0
)
/* If we are in a new user namespace we already dropped all
* groups when we switched to root in the new user namespace
* further above. Only drop groups if we can, so ensure that we
* have necessary privilege.
*/
#if HAVE_LIBCAP
have_cap_setgid
=
lxc_proc_cap_is_set
(
CAP_SETGID
,
CAP_EFFECTIVE
);
#else
have_cap_setgid
=
false
;
#endif
if
(
lxc_list_empty
(
&
handler
->
conf
->
id_map
)
&&
have_cap_setgid
)
{
if
(
lxc_setgroups
(
0
,
NULL
)
<
0
)
goto
out_warn_father
;
}
if
(
lxc_switch_uid_gid
(
new_uid
,
new_gid
)
<
0
)
goto
out_warn_father
;
/* After this call, we are in error because this ops should not return
* as it execs.
*/
...
...
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