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
927ea337
Unverified
Commit
927ea337
authored
Feb 04, 2021
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: restricted fd-only lxc_fill_autodev()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a370f16b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
14 deletions
+37
-14
conf.c
src/lxc/conf.c
+37
-14
No files found.
src/lxc/conf.c
View file @
927ea337
...
@@ -1156,7 +1156,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1156,7 +1156,7 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
cmask
=
umask
(
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
cmask
=
umask
(
S_IXUSR
|
S_IXGRP
|
S_IXOTH
);
for
(
i
=
0
;
i
<
sizeof
(
lxc_devices
)
/
sizeof
(
lxc_devices
[
0
]);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
lxc_devices
)
/
sizeof
(
lxc_devices
[
0
]);
i
++
)
{
char
hostpath
[
PATH_MAX
],
path
[
PATH_MAX
];
char
device_
path
[
PATH_MAX
];
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
)
{
...
@@ -1204,23 +1204,46 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
...
@@ -1204,23 +1204,46 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
}
}
/* Fallback to bind-mounting the device from the host. */
/* Fallback to bind-mounting the device from the host. */
ret
=
snprintf
(
hostpath
,
sizeof
(
hostpath
),
"/
dev/%s"
,
device
->
name
);
ret
=
snprintf
(
device_path
,
sizeof
(
device_path
),
"
dev/%s"
,
device
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
host
path
))
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
device_
path
))
return
ret_errno
(
EIO
);
return
ret_errno
(
EIO
);
ret
=
safe_mount_beneath_at
(
rootfs
->
dev_mntpt_fd
,
hostpath
,
device
->
name
,
NULL
,
MS_BIND
,
NULL
);
ret
=
mount_from_at
(
rootfs
->
dfd_root_host
,
device_path
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH_XDEV
,
rootfs
->
dev_mntpt_fd
,
device
->
name
,
PROTECT_OPATH_FILE
,
PROTECT_LOOKUP_BENEATH
,
NULL
/* fstype */
,
MS_BIND
/* mount flags */
,
NULL
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
const
char
*
mntpt
=
rootfs
->
path
?
rootfs
->
mount
:
NULL
;
char
path
[
PATH_MAX
];
if
(
errno
==
ENOSYS
)
{
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/%s"
,
mntpt
,
device
->
name
);
if
(
errno
!=
ENOSYS
)
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
return
log_error_errno
(
-
errno
,
errno
,
return
log_error
(
-
1
,
"Failed to create device path for %s"
,
device
->
name
);
"Failed to mount %d(%s) to %d(%s)"
,
ret
=
safe_mount
(
hostpath
,
path
,
0
,
MS_BIND
,
NULL
,
rootfs
->
path
?
rootfs
->
mount
:
NULL
);
rootfs
->
dfd_root_host
,
}
device_path
,
rootfs
->
dev_mntpt_fd
,
device
->
name
);
ret
=
snprintf
(
device_path
,
sizeof
(
device_path
),
"/dev/%s"
,
device
->
name
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
device_path
))
return
ret_errno
(
EIO
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"%s/dev/%s"
,
get_rootfs_mnt
(
rootfs
),
device
->
name
);
if
(
ret
<
0
||
ret
>=
sizeof
(
path
))
return
log_error
(
-
1
,
"Failed to create device path for %s"
,
device
->
name
);
ret
=
safe_mount
(
device_path
,
path
,
0
,
MS_BIND
,
NULL
,
get_rootfs_mnt
(
rootfs
));
if
(
ret
<
0
)
return
log_error_errno
(
-
1
,
errno
,
"Failed to bind mount host device node
\"
%s
\"
to
\"
%s
\"
"
,
device_path
,
path
);
DEBUG
(
"Bind mounted host device node
\"
%s
\"
to
\"
%s
\"
"
,
device_path
,
path
);
continue
;
}
}
if
(
ret
<
0
)
DEBUG
(
"Bind mounted host device %d(%s) to %d(%s)"
,
rootfs
->
dfd_root_host
,
device_path
,
rootfs
->
dev_mntpt_fd
,
device
->
name
);
return
log_error_errno
(
-
1
,
errno
,
"Failed to bind mount host device node
\"
%s
\"
onto
\"
%s
\"
"
,
hostpath
,
device
->
name
);
DEBUG
(
"Bind mounted host device node
\"
%s
\"
onto
\"
%s
\"
"
,
hostpath
,
device
->
name
);
}
}
(
void
)
umask
(
cmask
);
(
void
)
umask
(
cmask
);
...
...
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