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
9f6302e3
Unverified
Commit
9f6302e3
authored
Apr 02, 2020
by
Stéphane Graber
Committed by
GitHub
Apr 02, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3348 from brauner/2020-04-02/fixes
fixes
parents
85ec52bd
2ed0ea48
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
33 deletions
+35
-33
attach.c
src/lxc/attach.c
+4
-2
start.c
src/lxc/start.c
+4
-2
utils.c
src/lxc/utils.c
+26
-27
utils.h
src/lxc/utils.h
+1
-2
No files found.
src/lxc/attach.c
View file @
9f6302e3
...
@@ -875,9 +875,11 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -875,9 +875,11 @@ static int attach_child_main(struct attach_clone_payload *payload)
if
(
new_gid
==
ns_root_gid
)
if
(
new_gid
==
ns_root_gid
)
new_gid
=
LXC_INVALID_GID
;
new_gid
=
LXC_INVALID_GID
;
/* Make sure that the processes STDIO is correctly owned by the user that we are switching to */
/* Make sure that the processes STDIO is correctly owned by the user that we are switching to */
fix_stdio_permissions
(
new_uid
);
ret
=
fix_stdio_permissions
(
new_uid
);
if
(
ret
)
WARN
(
"Failed to ajust stdio permissions"
);
if
(
!
lxc_switch_uid_gid
(
new_uid
,
new_gid
))
if
(
!
lxc_switch_uid_gid
(
new_uid
,
new_gid
))
goto
on_error
;
goto
on_error
;
...
...
src/lxc/start.c
View file @
9f6302e3
...
@@ -1363,9 +1363,11 @@ static int do_start(void *data)
...
@@ -1363,9 +1363,11 @@ static int do_start(void *data)
if
(
new_gid
==
nsgid
)
if
(
new_gid
==
nsgid
)
new_gid
=
LXC_INVALID_GID
;
new_gid
=
LXC_INVALID_GID
;
/* Make sure that the processes STDIO is correctly owned by the user that we are switching to */
/* Make sure that the processes STDIO is correctly owned by the user that we are switching to */
fix_stdio_permissions
(
new_uid
);
ret
=
fix_stdio_permissions
(
new_uid
);
if
(
ret
)
WARN
(
"Failed to ajust stdio permissions"
);
/* If we are in a new user namespace we already dropped all groups when
/* 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
* we switched to root in the new user namespace further above. Only
...
...
src/lxc/utils.c
View file @
9f6302e3
...
@@ -1336,7 +1336,7 @@ bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
...
@@ -1336,7 +1336,7 @@ bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
int
ret
=
0
;
int
ret
=
0
;
if
(
gid
!=
LXC_INVALID_GID
)
{
if
(
gid
!=
LXC_INVALID_GID
)
{
ret
=
set
gid
(
gid
);
ret
=
set
resgid
(
gid
,
gid
,
gid
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
return
false
;
return
false
;
...
@@ -1345,7 +1345,7 @@ bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
...
@@ -1345,7 +1345,7 @@ bool lxc_switch_uid_gid(uid_t uid, gid_t gid)
}
}
if
(
uid
!=
LXC_INVALID_UID
)
{
if
(
uid
!=
LXC_INVALID_UID
)
{
ret
=
set
uid
(
uid
);
ret
=
set
resuid
(
uid
,
uid
,
uid
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
return
false
;
return
false
;
...
@@ -1861,47 +1861,46 @@ bool lxc_can_use_pidfd(int pidfd)
...
@@ -1861,47 +1861,46 @@ bool lxc_can_use_pidfd(int pidfd)
return
log_trace
(
true
,
"Kernel supports pidfds"
);
return
log_trace
(
true
,
"Kernel supports pidfds"
);
}
}
void
fix_stdio_permissions
(
uid_t
uid
)
int
fix_stdio_permissions
(
uid_t
uid
)
{
{
int
std_fds
[
3
]
=
{
STDIN_FILENO
,
STDOUT_FILENO
,
STDERR_FILENO
};
__do_close
int
devnull_fd
=
-
EBADF
;
int
devnull_fd
=
-
1
;
int
fret
=
0
;
int
std_fds
[]
=
{
STDIN_FILENO
,
STDOUT_FILENO
,
STDERR_FILENO
};
int
ret
;
int
ret
;
int
i
=
0
;
struct
stat
st
,
st_null
;
struct
stat
st
;
struct
stat
null_st
;
devnull_fd
=
open_devnull
();
devnull_fd
=
open_devnull
();
if
(
devnull_fd
<
0
)
{
if
(
devnull_fd
<
0
)
ERROR
(
"Open /dev/null failed
"
);
return
log_warn_errno
(
-
1
,
errno
,
"Failed to open
\"
/dev/null
\"
"
);
goto
out
;
}
ret
=
fstat
(
devnull_fd
,
&
st_null
);
if
(
ret
)
ret
=
fstat
(
devnull_fd
,
&
null_st
);
return
log_warn_errno
(
-
errno
,
errno
,
"Failed to stat
\"
/dev/null
\"
"
);
for
(
;
i
<
3
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ARRAY_SIZE
(
std_fds
)
;
i
++
)
{
ret
=
fstat
(
std_fds
[
i
],
&
st
);
ret
=
fstat
(
std_fds
[
i
],
&
st
);
if
(
ret
!=
0
)
{
if
(
ret
)
{
ERROR
(
"Failed to get fd %d stat"
,
std_fds
[
i
]);
SYSWARN
(
"Failed to stat standard I/O file descriptor %d"
,
std_fds
[
i
]);
fret
=
-
1
;
continue
;
continue
;
}
}
if
(
st
.
st_rdev
==
null_st
.
st_rdev
)
{
if
(
st
.
st_rdev
==
st_null
.
st_rdev
)
continue
;
continue
;
}
ret
=
fchown
(
std_fds
[
i
],
uid
,
st
.
st_gid
);
ret
=
fchown
(
std_fds
[
i
],
uid
,
st
.
st_gid
);
if
(
ret
!=
0
)
{
if
(
ret
)
{
ERROR
(
"Failed to change fd %d owner"
,
std_fds
[
i
]);
SYSWARN
(
"Failed to chown standard I/O file descriptor %d to uid %d and gid %d"
,
std_fds
[
i
],
uid
,
st
.
st_gid
);
fret
=
-
1
;
}
}
ret
=
fchmod
(
std_fds
[
i
],
0700
);
ret
=
fchmod
(
std_fds
[
i
],
0700
);
if
(
ret
!=
0
)
{
if
(
ret
)
{
ERROR
(
"Failed to change fd %d mode"
,
std_fds
[
i
]);
SYSWARN
(
"Failed to chmod standard I/O file descriptor %d"
,
std_fds
[
i
]);
fret
=
-
1
;
}
}
}
}
out:
return
fret
;
if
(
devnull_fd
>=
0
)
{
close
(
devnull_fd
);
}
}
}
src/lxc/utils.h
View file @
9f6302e3
...
@@ -239,7 +239,6 @@ extern int lxc_rm_rf(const char *dirname);
...
@@ -239,7 +239,6 @@ extern int lxc_rm_rf(const char *dirname);
extern
int
lxc_setup_keyring
(
char
*
keyring_label
);
extern
int
lxc_setup_keyring
(
char
*
keyring_label
);
extern
bool
lxc_can_use_pidfd
(
int
pidfd
);
extern
bool
lxc_can_use_pidfd
(
int
pidfd
);
/* Fix the permissions of init PID's STDIO within the container to the specified user */
extern
int
fix_stdio_permissions
(
uid_t
uid
);
extern
void
fix_stdio_permissions
(
uid_t
uid
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_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