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
0c816b34
Unverified
Commit
0c816b34
authored
Feb 13, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rexec: remove needless /proc/cmdline parsing
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
33257e97
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
68 deletions
+8
-68
rexec.c
src/lxc/rexec.c
+5
-65
rexec.h
src/lxc/rexec.h
+1
-1
lxc_attach.c
src/lxc/tools/lxc_attach.c
+2
-2
No files found.
src/lxc/rexec.c
View file @
0c816b34
...
...
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "file_utils.h"
...
...
@@ -39,58 +40,6 @@
#define LXC_MEMFD_REXEC_SEALS \
(F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE)
static
int
push_vargs
(
char
*
data
,
int
data_length
,
char
***
output
)
{
int
num
=
0
;
char
*
cur
=
data
;
if
(
!
data
||
*
output
)
return
-
1
;
*
output
=
must_realloc
(
NULL
,
sizeof
(
**
output
));
while
(
cur
<
data
+
data_length
)
{
num
++
;
*
output
=
must_realloc
(
*
output
,
(
num
+
1
)
*
sizeof
(
**
output
));
(
*
output
)[
num
-
1
]
=
cur
;
cur
+=
strlen
(
cur
)
+
1
;
}
(
*
output
)[
num
]
=
NULL
;
return
num
;
}
static
int
parse_exec_params
(
char
***
argv
,
char
***
envp
)
{
int
ret
;
char
*
cmdline
=
NULL
,
*
env
=
NULL
;
size_t
cmdline_size
,
env_size
;
cmdline
=
file_to_buf
(
"/proc/self/cmdline"
,
&
cmdline_size
);
if
(
!
cmdline
)
goto
on_error
;
env
=
file_to_buf
(
"/proc/self/environ"
,
&
env_size
);
if
(
!
env
)
goto
on_error
;
ret
=
push_vargs
(
cmdline
,
cmdline_size
,
argv
);
if
(
ret
<=
0
)
goto
on_error
;
ret
=
push_vargs
(
env
,
env_size
,
envp
);
if
(
ret
<=
0
)
goto
on_error
;
return
0
;
on_error:
free
(
env
);
free
(
cmdline
);
return
-
1
;
}
static
int
is_memfd
(
void
)
{
int
fd
,
saved_errno
,
seals
;
...
...
@@ -142,10 +91,9 @@ on_error:
errno
=
saved_errno
;
}
int
lxc_rexec
(
const
char
*
memfd_name
)
int
lxc_rexec
(
c
har
*
argv
[],
c
onst
char
*
memfd_name
)
{
int
ret
;
char
**
argv
=
NULL
,
**
envp
=
NULL
;
ret
=
is_memfd
();
if
(
ret
<
0
&&
ret
==
-
ENOTRECOVERABLE
)
{
...
...
@@ -157,15 +105,7 @@ int lxc_rexec(const char *memfd_name)
return
0
;
}
ret
=
parse_exec_params
(
&
argv
,
&
envp
);
if
(
ret
<
0
)
{
fprintf
(
stderr
,
"%s - Failed to parse command line parameters
\n
"
,
strerror
(
errno
));
return
-
1
;
}
lxc_rexec_as_memfd
(
argv
,
envp
,
memfd_name
);
lxc_rexec_as_memfd
(
argv
,
environ
,
memfd_name
);
fprintf
(
stderr
,
"%s - Failed to rexec as memfd
\n
"
,
strerror
(
errno
));
return
-
1
;
}
...
...
@@ -177,9 +117,9 @@ int lxc_rexec(const char *memfd_name)
* container are in the same user namespace or have set up an identity id
* mapping: CVE-2019-5736.
*/
__attribute__
((
constructor
))
static
void
liblxc_rexec
(
void
)
__attribute__
((
constructor
))
static
void
liblxc_rexec
(
int
argc
,
char
*
argv
[]
)
{
if
(
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
"liblxc"
))
{
if
(
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
argv
,
"liblxc"
))
{
fprintf
(
stderr
,
"Failed to re-execute liblxc via memory file descriptor
\n
"
);
_exit
(
EXIT_FAILURE
);
}
...
...
src/lxc/rexec.h
View file @
0c816b34
...
...
@@ -21,6 +21,6 @@
#ifndef __LXC_REXEC_H
#define __LXC_REXEC_H
extern
int
lxc_rexec
(
const
char
*
memfd_name
);
extern
int
lxc_rexec
(
c
har
*
argv
[],
c
onst
char
*
memfd_name
);
#endif
/* __LXC_REXEC_H */
src/lxc/tools/lxc_attach.c
View file @
0c816b34
...
...
@@ -57,9 +57,9 @@ lxc_log_define(lxc_attach, lxc);
* mapping: CVE-2019-5736.
*/
#ifdef ENFORCE_MEMFD_REXEC
__attribute__
((
constructor
))
static
void
lxc_attach_rexec
(
void
)
__attribute__
((
constructor
))
static
void
lxc_attach_rexec
(
int
argc
,
char
*
argv
[]
)
{
if
(
!
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
"lxc-attach"
))
{
if
(
!
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
argv
,
"lxc-attach"
))
{
fprintf
(
stderr
,
"Failed to re-execute lxc-attach via memory file descriptor
\n
"
);
_exit
(
EXIT_FAILURE
);
}
...
...
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