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
68eeee2f
Unverified
Commit
68eeee2f
authored
Dec 04, 2017
by
Christian Brauner
Committed by
GitHub
Dec 04, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1979 from marcosps/issue_494
lxc_unshare: Add uid_mapping when creating userns
parents
7ded3c18
344c9d81
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
+57
-2
conf.c
src/lxc/conf.c
+1
-1
conf.h
src/lxc/conf.h
+3
-0
lxc_unshare.c
src/lxc/tools/lxc_unshare.c
+53
-1
No files found.
src/lxc/conf.c
View file @
68eeee2f
...
@@ -2431,7 +2431,7 @@ struct lxc_conf *lxc_conf_init(void)
...
@@ -2431,7 +2431,7 @@ struct lxc_conf *lxc_conf_init(void)
return
new
;
return
new
;
}
}
static
int
write_id_mapping
(
enum
idtype
idtype
,
pid_t
pid
,
const
char
*
buf
,
int
write_id_mapping
(
enum
idtype
idtype
,
pid_t
pid
,
const
char
*
buf
,
size_t
buf_size
)
size_t
buf_size
)
{
{
char
path
[
MAXPATHLEN
];
char
path
[
MAXPATHLEN
];
...
...
src/lxc/conf.h
View file @
68eeee2f
...
@@ -361,6 +361,9 @@ struct lxc_conf {
...
@@ -361,6 +361,9 @@ struct lxc_conf {
char
*
inherit_ns
[
LXC_NS_MAX
];
char
*
inherit_ns
[
LXC_NS_MAX
];
};
};
int
write_id_mapping
(
enum
idtype
idtype
,
pid_t
pid
,
const
char
*
buf
,
size_t
buf_size
);
#ifdef HAVE_TLS
#ifdef HAVE_TLS
extern
__thread
struct
lxc_conf
*
current_config
;
extern
__thread
struct
lxc_conf
*
current_config
;
#else
#else
...
...
src/lxc/tools/lxc_unshare.c
View file @
68eeee2f
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include <signal.h>
#include <signal.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/eventfd.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
...
@@ -93,24 +94,37 @@ static bool lookup_user(const char *optarg, uid_t *uid)
...
@@ -93,24 +94,37 @@ static bool lookup_user(const char *optarg, uid_t *uid)
return
true
;
return
true
;
}
}
struct
start_arg
{
struct
start_arg
{
char
***
args
;
char
***
args
;
int
*
flags
;
int
*
flags
;
uid_t
*
uid
;
uid_t
*
uid
;
bool
setuid
;
bool
setuid
;
int
want_default_mounts
;
int
want_default_mounts
;
int
wait_fd
;
const
char
*
want_hostname
;
const
char
*
want_hostname
;
};
};
static
int
do_start
(
void
*
arg
)
static
int
do_start
(
void
*
arg
)
{
{
int
ret
;
uint64_t
wait_val
;
struct
start_arg
*
start_arg
=
arg
;
struct
start_arg
*
start_arg
=
arg
;
char
**
args
=
*
start_arg
->
args
;
char
**
args
=
*
start_arg
->
args
;
int
flags
=
*
start_arg
->
flags
;
int
flags
=
*
start_arg
->
flags
;
uid_t
uid
=
*
start_arg
->
uid
;
uid_t
uid
=
*
start_arg
->
uid
;
int
want_default_mounts
=
start_arg
->
want_default_mounts
;
int
want_default_mounts
=
start_arg
->
want_default_mounts
;
const
char
*
want_hostname
=
start_arg
->
want_hostname
;
const
char
*
want_hostname
=
start_arg
->
want_hostname
;
int
wait_fd
=
start_arg
->
wait_fd
;
if
(
start_arg
->
setuid
)
{
/* waiting until uid maps is set */
ret
=
read
(
wait_fd
,
&
wait_val
,
sizeof
(
wait_val
));
if
(
ret
==
-
1
)
{
close
(
wait_fd
);
fprintf
(
stderr
,
"read eventfd failed
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
if
((
flags
&
CLONE_NEWNS
)
&&
want_default_mounts
)
if
((
flags
&
CLONE_NEWNS
)
&&
want_default_mounts
)
lxc_setup_fs
();
lxc_setup_fs
();
...
@@ -143,6 +157,7 @@ int main(int argc, char *argv[])
...
@@ -143,6 +157,7 @@ int main(int argc, char *argv[])
int
flags
=
0
,
daemonize
=
0
;
int
flags
=
0
,
daemonize
=
0
;
uid_t
uid
=
0
;
/* valid only if (flags & CLONE_NEWUSER) */
uid_t
uid
=
0
;
/* valid only if (flags & CLONE_NEWUSER) */
pid_t
pid
;
pid_t
pid
;
uint64_t
wait_val
=
1
;
struct
my_iflist
*
tmpif
,
*
my_iflist
=
NULL
;
struct
my_iflist
*
tmpif
,
*
my_iflist
=
NULL
;
struct
start_arg
start_arg
=
{
struct
start_arg
start_arg
=
{
.
args
=
&
args
,
.
args
=
&
args
,
...
@@ -241,12 +256,49 @@ int main(int argc, char *argv[])
...
@@ -241,12 +256,49 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
start_arg
.
setuid
)
{
start_arg
.
wait_fd
=
eventfd
(
0
,
EFD_CLOEXEC
);
if
(
start_arg
.
wait_fd
<
0
)
{
fprintf
(
stderr
,
"failed to create eventfd
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
pid
=
lxc_clone
(
do_start
,
&
start_arg
,
flags
);
pid
=
lxc_clone
(
do_start
,
&
start_arg
,
flags
);
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
fprintf
(
stderr
,
"failed to clone
\n
"
);
fprintf
(
stderr
,
"failed to clone
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
start_arg
.
setuid
)
{
/* enough space to accommodate uids */
char
*
umap
=
(
char
*
)
alloca
(
100
);
/* create new uid mapping using current UID and the one
* specified as parameter
*/
ret
=
snprintf
(
umap
,
100
,
"%d %d 1
\n
"
,
*
(
start_arg
.
uid
),
getuid
());
if
(
ret
<
0
||
ret
>=
100
)
{
close
(
start_arg
.
wait_fd
);
fprintf
(
stderr
,
"snprintf failed"
);
exit
(
EXIT_FAILURE
);
}
ret
=
write_id_mapping
(
ID_TYPE_UID
,
pid
,
umap
,
strlen
(
umap
));
if
(
ret
<
0
)
{
close
(
start_arg
.
wait_fd
);
fprintf
(
stderr
,
"uid mapping failed
\n
"
);
exit
(
EXIT_FAILURE
);
}
ret
=
write
(
start_arg
.
wait_fd
,
&
wait_val
,
sizeof
(
wait_val
));
if
(
ret
<
0
)
{
close
(
start_arg
.
wait_fd
);
fprintf
(
stderr
,
"write to eventfd failed
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
if
(
my_iflist
)
{
if
(
my_iflist
)
{
for
(
tmpif
=
my_iflist
;
tmpif
;
tmpif
=
tmpif
->
mi_next
)
{
for
(
tmpif
=
my_iflist
;
tmpif
;
tmpif
=
tmpif
->
mi_next
)
{
if
(
lxc_netdev_move_by_name
(
tmpif
->
mi_ifname
,
pid
,
NULL
)
<
0
)
if
(
lxc_netdev_move_by_name
(
tmpif
->
mi_ifname
,
pid
,
NULL
)
<
0
)
...
...
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