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
b091c341
Unverified
Commit
b091c341
authored
Feb 12, 2019
by
Stéphane Graber
Committed by
GitHub
Feb 12, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2846 from brauner/2019-02-12/CVE-2019-5736
rexec: make rexecution opt-in for library callers
parents
b88ccedc
d3a9befc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
3 deletions
+49
-3
Makefile.am
src/lxc/Makefile.am
+3
-1
rexec.c
src/lxc/rexec.c
+2
-2
rexec.h
src/lxc/rexec.h
+26
-0
lxc_attach.c
src/lxc/tools/lxc_attach.c
+18
-0
No files found.
src/lxc/Makefile.am
View file @
b091c341
...
@@ -25,6 +25,7 @@ noinst_HEADERS = api_extensions.h \
...
@@ -25,6 +25,7 @@ noinst_HEADERS = api_extensions.h \
monitor.h
\
monitor.h
\
namespace.h
\
namespace.h
\
raw_syscalls.h
\
raw_syscalls.h
\
rexec.h
\
start.h
\
start.h
\
state.h
\
state.h
\
storage/btrfs.h
\
storage/btrfs.h
\
...
@@ -180,7 +181,7 @@ liblxc_la_SOURCES += ../include/strlcat.c ../include/strlcat.h
...
@@ -180,7 +181,7 @@ liblxc_la_SOURCES += ../include/strlcat.c ../include/strlcat.h
endif
endif
if
ENFORCE_MEMFD_REXEC
if
ENFORCE_MEMFD_REXEC
liblxc_la_SOURCES
+=
rexec.c
liblxc_la_SOURCES
+=
rexec.c
rexec.h
endif
endif
AM_CFLAGS
=
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
AM_CFLAGS
=
-DLXCROOTFSMOUNT
=
\"
$(LXCROOTFSMOUNT)
\"
\
...
@@ -307,6 +308,7 @@ LDADD = liblxc.la \
...
@@ -307,6 +308,7 @@ LDADD = liblxc.la \
if
ENABLE_TOOLS
if
ENABLE_TOOLS
lxc_attach_SOURCES
=
tools/lxc_attach.c
\
lxc_attach_SOURCES
=
tools/lxc_attach.c
\
rexec.c rexec.h
\
tools/arguments.c tools/arguments.h
tools/arguments.c tools/arguments.h
lxc_autostart_SOURCES
=
tools/lxc_autostart.c
\
lxc_autostart_SOURCES
=
tools/lxc_autostart.c
\
tools/arguments.c tools/arguments.h
tools/arguments.c tools/arguments.h
...
...
src/lxc/rexec.c
View file @
b091c341
...
@@ -142,7 +142,7 @@ on_error:
...
@@ -142,7 +142,7 @@ on_error:
errno
=
saved_errno
;
errno
=
saved_errno
;
}
}
static
int
lxc_rexec
(
const
char
*
memfd_name
)
int
lxc_rexec
(
const
char
*
memfd_name
)
{
{
int
ret
;
int
ret
;
char
**
argv
=
NULL
,
**
envp
=
NULL
;
char
**
argv
=
NULL
,
**
envp
=
NULL
;
...
@@ -179,7 +179,7 @@ static int lxc_rexec(const char *memfd_name)
...
@@ -179,7 +179,7 @@ static int lxc_rexec(const char *memfd_name)
*/
*/
__attribute__
((
constructor
))
static
void
liblxc_rexec
(
void
)
__attribute__
((
constructor
))
static
void
liblxc_rexec
(
void
)
{
{
if
(
lxc_rexec
(
"liblxc"
))
{
if
(
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
"liblxc"
))
{
fprintf
(
stderr
,
"Failed to re-execute liblxc via memory file descriptor
\n
"
);
fprintf
(
stderr
,
"Failed to re-execute liblxc via memory file descriptor
\n
"
);
_exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
...
...
src/lxc/rexec.h
0 → 100644
View file @
b091c341
/* liblxcapi
*
* Copyright © 2019 Christian Brauner <christian.brauner@ubuntu.com>.
* Copyright © 2019 Canonical Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __LXC_REXEC_H
#define __LXC_REXEC_H
extern
int
lxc_rexec
(
const
char
*
memfd_name
);
#endif
/* __LXC_REXEC_H */
src/lxc/tools/lxc_attach.c
View file @
b091c341
...
@@ -44,10 +44,28 @@
...
@@ -44,10 +44,28 @@
#include "config.h"
#include "config.h"
#include "confile.h"
#include "confile.h"
#include "log.h"
#include "log.h"
#include "rexec.h"
#include "utils.h"
#include "utils.h"
lxc_log_define
(
lxc_attach
,
lxc
);
lxc_log_define
(
lxc_attach
,
lxc
);
/**
* This function will copy any binary that calls liblxc into a memory file and
* will use the memfd to rexecute the binary. This is done to prevent attacks
* through the /proc/self/exe symlink to corrupt the host binary when host and
* container are in the same user namespace or have set up an identity id
* mapping: CVE-2019-5736.
*/
#ifdef ENFORCE_MEMFD_REXEC
__attribute__
((
constructor
))
static
void
lxc_attach_rexec
(
void
)
{
if
(
!
getenv
(
"LXC_MEMFD_REXEC"
)
&&
lxc_rexec
(
"lxc-attach"
))
{
fprintf
(
stderr
,
"Failed to re-execute lxc-attach via memory file descriptor
\n
"
);
_exit
(
EXIT_FAILURE
);
}
}
#endif
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
);
static
int
add_to_simple_array
(
char
***
array
,
ssize_t
*
capacity
,
char
*
value
);
static
int
add_to_simple_array
(
char
***
array
,
ssize_t
*
capacity
,
char
*
value
);
static
bool
stdfd_is_pty
(
void
);
static
bool
stdfd_is_pty
(
void
);
...
...
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