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
e3fe3512
Unverified
Commit
e3fe3512
authored
Feb 08, 2018
by
Christian Brauner
Committed by
GitHub
Feb 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2142 from hallyn/2018-02-08/priv
2018 02 08/priv
parents
5596585d
e0010464
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
38 additions
and
27 deletions
+38
-27
lxccontainer.c
src/lxc/lxccontainer.c
+13
-8
network.c
src/lxc/network.c
+2
-2
start.c
src/lxc/start.c
+2
-2
aufs.c
src/lxc/storage/aufs.c
+4
-4
btrfs.c
src/lxc/storage/btrfs.c
+2
-2
overlay.c
src/lxc/storage/overlay.c
+6
-6
storage.c
src/lxc/storage/storage.c
+3
-3
utils.h
src/lxc/utils.h
+6
-0
No files found.
src/lxc/lxccontainer.c
View file @
e3fe3512
...
...
@@ -2678,7 +2678,7 @@ static bool has_snapshots(struct lxc_container *c)
static
bool
do_destroy_container
(
struct
lxc_conf
*
conf
)
{
int
ret
;
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
userns_exec_full
(
conf
,
storage_destroy_wrapper
,
conf
,
"storage_destroy_wrapper"
);
if
(
ret
<
0
)
...
...
@@ -2800,7 +2800,7 @@ static bool container_destroy(struct lxc_container *c,
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
goto
out
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_1
(
conf
,
lxc_unlink_exec_wrapper
,
path
,
"lxc_unlink_exec_wrapper"
);
else
...
...
@@ -2819,7 +2819,7 @@ static bool container_destroy(struct lxc_container *c,
ret
=
snprintf
(
path
,
len
,
"%s/%s"
,
p1
,
c
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
len
)
goto
out
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_full
(
conf
,
lxc_rmdir_onedev_wrapper
,
path
,
"lxc_rmdir_onedev_wrapper"
);
else
...
...
@@ -3602,7 +3602,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
}
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
if
(
chown_mapped_root
(
newpath
,
c
->
lxc_conf
)
<
0
)
{
ERROR
(
"Error chowning %s to container root"
,
newpath
);
goto
out
;
...
...
@@ -3680,7 +3680,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
data
.
c1
=
c2
;
data
.
flags
=
flags
;
data
.
hookargs
=
hookargs
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_full
(
c
->
lxc_conf
,
clone_update_rootfs_wrapper
,
&
data
,
"clone_update_rootfs_wrapper"
);
else
...
...
@@ -4355,6 +4355,7 @@ static bool add_remove_device_node(struct lxc_container *c, const char *src_path
static
bool
do_lxcapi_add_device_node
(
struct
lxc_container
*
c
,
const
char
*
src_path
,
const
char
*
dest_path
)
{
// cannot mknod if we're not privileged wrt init_user_ns
if
(
am_host_unpriv
())
{
ERROR
(
NOT_SUPPORTED_ERROR
,
__FUNCTION__
);
return
false
;
...
...
@@ -4366,7 +4367,7 @@ WRAP_API_2(bool, lxcapi_add_device_node, const char *, const char *)
static
bool
do_lxcapi_remove_device_node
(
struct
lxc_container
*
c
,
const
char
*
src_path
,
const
char
*
dest_path
)
{
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ERROR
(
NOT_SUPPORTED_ERROR
,
__FUNCTION__
);
return
false
;
}
...
...
@@ -4382,7 +4383,7 @@ static bool do_lxcapi_attach_interface(struct lxc_container *c,
pid_t
init_pid
;
int
ret
=
0
;
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ERROR
(
NOT_SUPPORTED_ERROR
,
__FUNCTION__
);
return
false
;
}
...
...
@@ -4421,7 +4422,11 @@ static bool do_lxcapi_detach_interface(struct lxc_container *c,
int
ret
;
pid_t
pid
,
pid_outside
;
if
(
am_host_unpriv
())
{
/*
* TODO - if this is a physical device, then we need am_host_unpriv.
* But for other types guest privilege suffices.
*/
if
(
am_guest_unpriv
())
{
ERROR
(
NOT_SUPPORTED_ERROR
,
__FUNCTION__
);
return
false
;
}
...
...
src/lxc/network.c
View file @
e3fe3512
...
...
@@ -2449,7 +2449,7 @@ int lxc_network_move_created_netdev_priv(const char *lxcpath, const char *lxcnam
char
ifname
[
IFNAMSIZ
];
struct
lxc_list
*
iterator
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
return
0
;
lxc_list_for_each
(
iterator
,
network
)
{
...
...
@@ -2487,7 +2487,7 @@ int lxc_create_network_unpriv(const char *lxcpath, const char *lxcname,
{
struct
lxc_list
*
iterator
;
if
(
!
am_
ho
st_unpriv
())
if
(
!
am_
gue
st_unpriv
())
return
0
;
lxc_list_for_each
(
iterator
,
network
)
{
...
...
src/lxc/start.c
View file @
e3fe3512
...
...
@@ -654,11 +654,11 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
memset
(
handler
,
0
,
sizeof
(
*
handler
));
/* Note that am_
ho
st_unpriv() checks the effective uid. We probably don't
/* Note that am_
gue
st_unpriv() checks the effective uid. We probably don't
* care if we are real root only if we are running as root so this
* should be fine.
*/
handler
->
am_root
=
!
am_
ho
st_unpriv
();
handler
->
am_root
=
!
am_
gue
st_unpriv
();
handler
->
data_sock
[
0
]
=
handler
->
data_sock
[
1
]
=
-
1
;
handler
->
conf
=
conf
;
handler
->
lxcpath
=
lxcpath
;
...
...
src/lxc/storage/aufs.c
View file @
e3fe3512
...
...
@@ -89,7 +89,7 @@ int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
if
(
mkdir_p
(
new
->
dest
,
0755
)
<
0
)
return
-
1
;
if
(
am_
ho
st_unpriv
()
&&
chown_mapped_root
(
new
->
dest
,
conf
)
<
0
)
if
(
am_
gue
st_unpriv
()
&&
chown_mapped_root
(
new
->
dest
,
conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
new
->
dest
);
if
(
strcmp
(
orig
->
type
,
"dir"
)
==
0
)
{
...
...
@@ -116,7 +116,7 @@ int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
free
(
delta
);
return
-
1
;
}
if
(
am_
ho
st_unpriv
()
&&
chown_mapped_root
(
delta
,
conf
)
<
0
)
if
(
am_
gue
st_unpriv
()
&&
chown_mapped_root
(
delta
,
conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
delta
);
// the src will be 'aufs:lowerdir:upperdir'
...
...
@@ -157,13 +157,13 @@ int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
free
(
ndelta
);
return
-
1
;
}
if
(
am_
ho
st_unpriv
()
&&
chown_mapped_root
(
ndelta
,
conf
)
<
0
)
if
(
am_
gue
st_unpriv
()
&&
chown_mapped_root
(
ndelta
,
conf
)
<
0
)
WARN
(
"Failed to update ownership of %s"
,
ndelta
);
struct
rsync_data_char
rdata
;
rdata
.
src
=
odelta
;
rdata
.
dest
=
ndelta
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_full
(
conf
,
lxc_rsync_delta_wrapper
,
&
rdata
,
"lxc_rsync_delta_wrapper"
);
else
...
...
src/lxc/storage/btrfs.c
View file @
e3fe3512
...
...
@@ -434,7 +434,7 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
/* rsync the contents from source to target */
data
.
orig
=
orig
;
data
.
new
=
new
;
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
userns_exec_full
(
conf
,
lxc_storage_rsync_exec_wrapper
,
&
data
,
"lxc_storage_rsync_exec_wrapper"
);
if
(
ret
<
0
)
{
...
...
@@ -466,7 +466,7 @@ bool btrfs_create_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
if
(
ret
<
0
&&
errno
!=
ENOENT
)
return
false
;
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
struct
rsync_data_char
args
;
args
.
src
=
orig
->
src
;
...
...
src/lxc/storage/overlay.c
View file @
e3fe3512
...
...
@@ -73,7 +73,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return
-
1
;
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
new
->
dest
,
conf
);
if
(
ret
<
0
)
WARN
(
"Failed to update ownership of %s"
,
new
->
dest
);
...
...
@@ -120,7 +120,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return
-
1
;
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
delta
,
conf
);
if
(
ret
<
0
)
WARN
(
"Failed to update ownership of %s"
,
delta
);
...
...
@@ -153,7 +153,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return
-
1
;
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
work
,
conf
);
if
(
ret
<
0
)
WARN
(
"Failed to update ownership of %s"
,
work
);
...
...
@@ -224,7 +224,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return
-
1
;
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
ndelta
,
conf
);
if
(
ret
<
0
)
WARN
(
"Failed to update ownership of %s"
,
...
...
@@ -265,7 +265,7 @@ int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char
return
-
1
;
}
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
work
,
conf
);
if
(
ret
<
0
)
WARN
(
"Failed to update ownership of %s"
,
work
);
...
...
@@ -960,7 +960,7 @@ static int ovl_do_rsync(const char *src, const char *dest,
rdata
.
src
=
(
char
*
)
src
;
rdata
.
dest
=
(
char
*
)
dest
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_full
(
conf
,
lxc_rsync_exec_wrapper
,
&
rdata
,
"lxc_rsync_exec_wrapper"
);
else
...
...
src/lxc/storage/storage.c
View file @
e3fe3512
...
...
@@ -406,7 +406,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
if
(
!
bdevtype
&&
!
keepbdevtype
&&
snap
&&
!
strcmp
(
orig
->
type
,
"dir"
))
bdevtype
=
"overlay"
;
if
(
am_
ho
st_unpriv
()
&&
!
unpriv_snap_allowed
(
orig
,
bdevtype
,
snap
,
maybe_snap
))
{
if
(
am_
gue
st_unpriv
()
&&
!
unpriv_snap_allowed
(
orig
,
bdevtype
,
snap
,
maybe_snap
))
{
ERROR
(
"Unsupported snapshot type
\"
%s
\"
for unprivileged users"
,
bdevtype
?
bdevtype
:
"(null)"
);
goto
on_error_put_orig
;
...
...
@@ -505,7 +505,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
else
src_no_prefix
=
lxc_storage_get_path
(
new
->
src
,
new
->
type
);
if
(
am_
ho
st_unpriv
())
{
if
(
am_
gue
st_unpriv
())
{
ret
=
chown_mapped_root
(
src_no_prefix
,
c
->
lxc_conf
);
if
(
ret
<
0
)
WARN
(
"Failed to chown
\"
%s
\"
"
,
new
->
src
);
...
...
@@ -518,7 +518,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
/* rsync the contents from source to target */
data
.
orig
=
orig
;
data
.
new
=
new
;
if
(
am_
ho
st_unpriv
())
if
(
am_
gue
st_unpriv
())
ret
=
userns_exec_full
(
c
->
lxc_conf
,
lxc_storage_rsync_exec_wrapper
,
&
data
,
"lxc_storage_rsync_exec_wrapper"
);
...
...
src/lxc/utils.h
View file @
e3fe3512
...
...
@@ -435,6 +435,12 @@ extern int lxc_strmunmap(void *addr, size_t length);
/* initialize rand with urandom */
extern
int
randseed
(
bool
);
/* are we unprivileged with respect to our namespaces */
inline
static
bool
am_guest_unpriv
(
void
)
{
return
geteuid
()
!=
0
;
}
/* are we unprivileged with respect to init_user_ns */
inline
static
bool
am_host_unpriv
(
void
)
{
FILE
*
f
;
...
...
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