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
c18a6ad1
Unverified
Commit
c18a6ad1
authored
Feb 03, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: harden open in lxc_fill_autodev()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
ebb4d1a2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
12 deletions
+6
-12
conf.c
src/lxc/conf.c
+6
-12
No files found.
src/lxc/conf.c
View file @
c18a6ad1
...
@@ -1146,18 +1146,12 @@ enum {
...
@@ -1146,18 +1146,12 @@ enum {
static
int
lxc_fill_autodev
(
const
struct
lxc_rootfs
*
rootfs
)
static
int
lxc_fill_autodev
(
const
struct
lxc_rootfs
*
rootfs
)
{
{
__do_close
int
dev_dir_fd
=
-
EBADF
;
int
i
,
ret
;
int
i
,
ret
;
mode_t
cmask
;
mode_t
cmask
;
int
use_mknod
=
LXC_DEVNODE_MKNOD
;
int
use_mknod
=
LXC_DEVNODE_MKNOD
;
dev_dir_fd
=
openat
(
rootfs
->
mntpt_fd
,
"dev/"
,
O_RDONLY
|
O_CLOEXEC
|
O_DIRECTORY
|
O_PATH
|
O_NOFOLLOW
);
if
(
rootfs
->
dev_mntpt_fd
<
0
)
if
(
dev_dir_fd
<
0
)
{
return
log_info
(
0
,
"No /dev directory found, skipping setup"
);
if
(
errno
==
ENOENT
)
return
log_info
(
0
,
"No /dev directory found, skipping setup"
);
return
-
errno
;
}
INFO
(
"Populating
\"
/dev
\"
"
);
INFO
(
"Populating
\"
/dev
\"
"
);
...
@@ -1167,7 +1161,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1167,7 +1161,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
const
struct
lxc_device_node
*
device
=
&
lxc_devices
[
i
];
const
struct
lxc_device_node
*
device
=
&
lxc_devices
[
i
];
if
(
use_mknod
>=
LXC_DEVNODE_MKNOD
)
{
if
(
use_mknod
>=
LXC_DEVNODE_MKNOD
)
{
ret
=
mknodat
(
dev_dir
_fd
,
device
->
name
,
device
->
mode
,
makedev
(
device
->
maj
,
device
->
min
));
ret
=
mknodat
(
rootfs
->
dev_mntpt
_fd
,
device
->
name
,
device
->
mode
,
makedev
(
device
->
maj
,
device
->
min
));
if
(
ret
==
0
||
(
ret
<
0
&&
errno
==
EEXIST
))
{
if
(
ret
==
0
||
(
ret
<
0
&&
errno
==
EEXIST
))
{
DEBUG
(
"Created device node
\"
%s
\"
"
,
device
->
name
);
DEBUG
(
"Created device node
\"
%s
\"
"
,
device
->
name
);
}
else
if
(
ret
<
0
)
{
}
else
if
(
ret
<
0
)
{
...
@@ -1187,7 +1181,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1187,7 +1181,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
* - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=55956b59df336f6738da916dbb520b6e37df9fbd
* - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=55956b59df336f6738da916dbb520b6e37df9fbd
* - https://lists.linuxfoundation.org/pipermail/containers/2018-June/039176.html
* - https://lists.linuxfoundation.org/pipermail/containers/2018-June/039176.html
*/
*/
fd
=
open
at
(
dev_dir_fd
,
device
->
name
,
O_RDONLY
|
O_CLOEXEC
);
fd
=
open
_at
(
rootfs
->
dev_mntpt_fd
,
device
->
name
,
PROTECT_OPEN
,
PROTECT_LOOKUP_BENEATH
,
0
);
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
/* Device nodes are fully useable. */
/* Device nodes are fully useable. */
use_mknod
=
LXC_DEVNODE_OPEN
;
use_mknod
=
LXC_DEVNODE_OPEN
;
...
@@ -1205,7 +1199,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1205,7 +1199,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
* nodes the prio mknod() call will have created the
* nodes the prio mknod() call will have created the
* device node so we can use it as a bind-mount target.
* device node so we can use it as a bind-mount target.
*/
*/
ret
=
mknodat
(
dev_dir
_fd
,
device
->
name
,
S_IFREG
|
0000
,
0
);
ret
=
mknodat
(
rootfs
->
dev_mntpt
_fd
,
device
->
name
,
S_IFREG
|
0000
,
0
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
if
(
ret
<
0
&&
errno
!=
EEXIST
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to create file
\"
%s
\"
"
,
device
->
name
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to create file
\"
%s
\"
"
,
device
->
name
);
}
}
...
@@ -1215,7 +1209,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1215,7 +1209,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
hostpath
))
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
hostpath
))
return
ret_errno
(
EIO
);
return
ret_errno
(
EIO
);
ret
=
safe_mount_beneath_at
(
dev_dir
_fd
,
hostpath
,
device
->
name
,
NULL
,
MS_BIND
,
NULL
);
ret
=
safe_mount_beneath_at
(
rootfs
->
dev_mntpt
_fd
,
hostpath
,
device
->
name
,
NULL
,
MS_BIND
,
NULL
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
const
char
*
mntpt
=
rootfs
->
path
?
rootfs
->
mount
:
NULL
;
const
char
*
mntpt
=
rootfs
->
path
?
rootfs
->
mount
:
NULL
;
if
(
errno
==
ENOSYS
)
{
if
(
errno
==
ENOSYS
)
{
...
...
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