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
7cf89ee8
Unverified
Commit
7cf89ee8
authored
Feb 18, 2019
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "rexec: handle legacy kernels"
Broke Android This reverts commit
8f350e63
. Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
parent
4d8a34c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
109 deletions
+17
-109
file_utils.c
src/lxc/file_utils.c
+1
-31
file_utils.h
src/lxc/file_utils.h
+0
-1
memory_utils.h
src/lxc/memory_utils.h
+5
-11
rexec.c
src/lxc/rexec.c
+11
-66
No files found.
src/lxc/file_utils.c
View file @
7cf89ee8
...
@@ -222,7 +222,7 @@ int lxc_make_tmpfile(char *template, bool rm)
...
@@ -222,7 +222,7 @@ int lxc_make_tmpfile(char *template, bool rm)
mode_t
msk
;
mode_t
msk
;
msk
=
umask
(
0022
);
msk
=
umask
(
0022
);
fd
=
mk
ostemp
(
template
,
O_CLOEXEC
);
fd
=
mk
stemp
(
template
);
umask
(
msk
);
umask
(
msk
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
-
1
;
return
-
1
;
...
@@ -366,33 +366,3 @@ on_error:
...
@@ -366,33 +366,3 @@ on_error:
return
NULL
;
return
NULL
;
}
}
int
fd_to_fd
(
int
from
,
int
to
)
{
for
(;;)
{
uint8_t
buf
[
PATH_MAX
];
uint8_t
*
p
=
buf
;
ssize_t
bytes_to_write
;
ssize_t
bytes_read
;
bytes_read
=
lxc_read_nointr
(
from
,
buf
,
sizeof
buf
);
if
(
bytes_read
<
0
)
return
-
1
;
if
(
bytes_read
==
0
)
break
;
bytes_to_write
=
(
size_t
)
bytes_read
;
do
{
ssize_t
bytes_written
;
bytes_written
=
lxc_write_nointr
(
to
,
p
,
bytes_to_write
);
if
(
bytes_written
<
0
)
return
-
1
;
bytes_to_write
-=
bytes_written
;
p
+=
bytes_written
;
}
while
(
bytes_to_write
>
0
);
}
return
0
;
}
src/lxc/file_utils.h
View file @
7cf89ee8
...
@@ -57,6 +57,5 @@ extern FILE *fopen_cloexec(const char *path, const char *mode);
...
@@ -57,6 +57,5 @@ extern FILE *fopen_cloexec(const char *path, const char *mode);
extern
ssize_t
lxc_sendfile_nointr
(
int
out_fd
,
int
in_fd
,
off_t
*
offset
,
extern
ssize_t
lxc_sendfile_nointr
(
int
out_fd
,
int
in_fd
,
off_t
*
offset
,
size_t
count
);
size_t
count
);
extern
char
*
file_to_buf
(
char
*
path
,
size_t
*
length
);
extern
char
*
file_to_buf
(
char
*
path
,
size_t
*
length
);
extern
int
fd_to_fd
(
int
from
,
int
to
);
#endif
/* __LXC_FILE_UTILS_H */
#endif
/* __LXC_FILE_UTILS_H */
src/lxc/memory_utils.h
View file @
7cf89ee8
...
@@ -28,8 +28,6 @@
...
@@ -28,8 +28,6 @@
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
#include "macro.h"
static
inline
void
__auto_free__
(
void
*
p
)
static
inline
void
__auto_free__
(
void
*
p
)
{
{
free
(
*
(
void
**
)
p
);
free
(
*
(
void
**
)
p
);
...
@@ -47,17 +45,13 @@ static inline void __auto_closedir__(DIR **d)
...
@@ -47,17 +45,13 @@ static inline void __auto_closedir__(DIR **d)
closedir
(
*
d
);
closedir
(
*
d
);
}
}
#define close_prot_errno_disarm(fd) \
if (fd >= 0) { \
int _e_ = errno; \
close(fd); \
errno = _e_; \
fd = -EBADF; \
}
static
inline
void
__auto_close__
(
int
*
fd
)
static
inline
void
__auto_close__
(
int
*
fd
)
{
{
close_prot_errno_disarm
(
*
fd
);
if
(
*
fd
>=
0
)
{
int
e
=
errno
;
close
(
*
fd
);
errno
=
e
;
}
}
}
#define __do_close_prot_errno __attribute__((__cleanup__(__auto_close__)))
#define __do_close_prot_errno __attribute__((__cleanup__(__auto_close__)))
...
...
src/lxc/rexec.c
View file @
7cf89ee8
...
@@ -84,97 +84,42 @@ static int parse_argv(char ***argv)
...
@@ -84,97 +84,42 @@ static int parse_argv(char ***argv)
static
int
is_memfd
(
void
)
static
int
is_memfd
(
void
)
{
{
__do_close_prot_errno
int
fd
=
-
EBADF
;
__do_close_prot_errno
int
fd
=
-
EBADF
;
int
seals
;
int
s
aved_errno
,
s
eals
;
fd
=
open
(
"/proc/self/exe"
,
O_RDONLY
|
O_CLOEXEC
);
fd
=
open
(
"/proc/self/exe"
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
-
ENOTRECOVERABLE
;
return
-
ENOTRECOVERABLE
;
seals
=
fcntl
(
fd
,
F_GET_SEALS
);
seals
=
fcntl
(
fd
,
F_GET_SEALS
);
if
(
seals
<
0
)
{
if
(
seals
<
0
)
struct
stat
s
=
{
0
};
if
(
fstat
(
fd
,
&
s
)
==
0
)
{
fprintf
(
stderr
,
"AAAAA: %ld
\n
"
,
(
long
)
s
.
st_nlink
);
return
(
s
.
st_nlink
==
0
);
}
return
-
EINVAL
;
return
-
EINVAL
;
}
return
seals
==
LXC_MEMFD_REXEC_SEALS
;
return
seals
==
LXC_MEMFD_REXEC_SEALS
;
}
}
static
void
lxc_rexec_as_memfd
(
char
**
argv
,
char
**
envp
,
const
char
*
memfd_name
)
static
void
lxc_rexec_as_memfd
(
char
**
argv
,
char
**
envp
,
const
char
*
memfd_name
)
{
{
__do_close_prot_errno
int
fd
=
-
EBADF
,
memfd
=
-
EBADF
,
tmpfd
=
-
EBADF
;
__do_close_prot_errno
int
fd
=
-
EBADF
,
memfd
=
-
EBADF
;
int
ret
;
int
saved_errno
;
ssize_t
bytes_sent
;
memfd
=
memfd_create
(
memfd_name
,
MFD_ALLOW_SEALING
|
MFD_CLOEXEC
);
memfd
=
memfd_create
(
memfd_name
,
MFD_ALLOW_SEALING
|
MFD_CLOEXEC
);
if
(
memfd
<
0
)
{
if
(
memfd
<
0
)
char
template
[
PATH_MAX
];
return
;
ret
=
snprintf
(
template
,
sizeof
(
template
),
P_tmpdir
"/.%s_XXXXXX"
,
memfd_name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
template
))
return
;
tmpfd
=
lxc_make_tmpfile
(
template
,
true
);
if
(
tmpfd
<
0
)
return
;
ret
=
fchmod
(
tmpfd
,
0700
);
if
(
ret
)
return
;
}
fd
=
open
(
"/proc/self/exe"
,
O_RDONLY
|
O_CLOEXEC
);
fd
=
open
(
"/proc/self/exe"
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
;
return
;
/* sendfile() handles up to 2GB. */
/* sendfile() handles up to 2GB. */
if
(
memfd
>=
0
)
{
bytes_sent
=
lxc_sendfile_nointr
(
memfd
,
fd
,
NULL
,
LXC_SENDFILE_MAX
);
ssize_t
bytes_sent
=
0
;
if
(
bytes_sent
<
0
)
struct
stat
st
=
{
0
};
ret
=
fstat
(
fd
,
&
st
);
if
(
ret
)
return
;
while
(
bytes_sent
<
st
.
st_size
)
{
ssize_t
sent
;
sent
=
lxc_sendfile_nointr
(
memfd
,
fd
,
NULL
,
st
.
st_size
-
bytes_sent
);
if
(
sent
<
0
)
return
;
bytes_sent
+=
sent
;
}
}
else
if
(
fd_to_fd
(
fd
,
tmpfd
))
{
return
;
return
;
}
close_prot_errno_disarm
(
fd
);
if
(
fcntl
(
memfd
,
F_ADD_SEALS
,
LXC_MEMFD_REXEC_SEALS
))
if
(
memfd
>=
0
&&
fcntl
(
memfd
,
F_ADD_SEALS
,
LXC_MEMFD_REXEC_SEALS
))
return
;
return
;
if
(
memfd
>=
0
)
{
fexecve
(
memfd
,
argv
,
envp
);
fexecve
(
memfd
,
argv
,
envp
);
}
else
{
__do_close_prot_errno
int
execfd
=
-
EBADF
;
char
procfd
[
LXC_PROC_PID_FD_LEN
];
ret
=
snprintf
(
procfd
,
sizeof
(
procfd
),
"/proc/self/fd/%d"
,
tmpfd
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
procfd
))
return
;
execfd
=
open
(
procfd
,
O_PATH
|
O_CLOEXEC
);
close_prot_errno_disarm
(
tmpfd
);
if
(
execfd
<
0
)
return
;
fexecve
(
execfd
,
argv
,
envp
);
}
}
}
/*
/*
...
...
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