Skip to content

Commit d8a8f35

Browse files
apconoleddiproietto
authored andcommitted
netdev-dpdk: Restrict vhost_sock_dir
Since the vhost-user sockets directory now comes from the database, it is possible for any user with database access to program an arbitrary filesystem location for the sockets directory. This could result in unprivileged users creating or deleting arbitrary filesystem files by using specially crafted names. To prevent this, 'vhost-sock-dir' is now relative to ovs_rundir() and must not contain "..". Signed-off-by: Aaron Conole <aconole@redhat.com> Acked-by: Daniele Di Proietto <diproiettod@vmware.com>
1 parent bab6940 commit d8a8f35

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

lib/netdev-dpdk.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,6 +2895,9 @@ dpdk_init__(const struct smap *ovs_other_config)
28952895
int argc;
28962896
int err;
28972897
cpu_set_t cpuset;
2898+
#ifndef VHOST_CUSE
2899+
char *sock_dir_subcomponent;
2900+
#endif
28982901

28992902
if (!smap_get_bool(ovs_other_config, "dpdk-init", false)) {
29002903
VLOG_INFO("DPDK Disabled - to change this requires a restart.\n");
@@ -2907,15 +2910,29 @@ dpdk_init__(const struct smap *ovs_other_config)
29072910
if (process_vhost_flags("cuse-dev-name", xstrdup("vhost-net"),
29082911
PATH_MAX, ovs_other_config, &cuse_dev_name)) {
29092912
#else
2910-
if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()),
2911-
NAME_MAX, ovs_other_config, &vhost_sock_dir)) {
2913+
if (process_vhost_flags("vhost-sock-dir", xstrdup(""),
2914+
NAME_MAX, ovs_other_config,
2915+
&sock_dir_subcomponent)) {
29122916
struct stat s;
2913-
2914-
err = stat(vhost_sock_dir, &s);
2915-
if (err) {
2916-
VLOG_ERR("vhost-user sock directory '%s' does not exist.",
2917-
vhost_sock_dir);
2917+
if (!strstr(sock_dir_subcomponent, "..")) {
2918+
vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(),
2919+
sock_dir_subcomponent);
2920+
2921+
err = stat(vhost_sock_dir, &s);
2922+
if (err) {
2923+
VLOG_ERR("vhost-user sock directory '%s' does not exist.",
2924+
vhost_sock_dir);
2925+
}
2926+
} else {
2927+
vhost_sock_dir = xstrdup(ovs_rundir());
2928+
VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid"
2929+
"characters '..' - using %s instead.",
2930+
ovs_rundir(), sock_dir_subcomponent, ovs_rundir());
29182931
}
2932+
free(sock_dir_subcomponent);
2933+
} else {
2934+
vhost_sock_dir = xstrdup(ovs_rundir());
2935+
free(sock_dir_subcomponent);
29192936
#endif
29202937
}
29212938

vswitchd/vswitch.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@
290290
<column name="other_config" key="vhost-sock-dir"
291291
type='{"type": "string"}'>
292292
<p>
293-
Specifies the path to the vhost-user unix domain socket files.
293+
Specifies the path to the vhost-user unix domain socket files. This
294+
path must exist and be a subdirectory tree of the Open vSwitch
295+
run directory.
294296
</p>
295297
<p>
296298
Defaults to the working directory of the application. Changing this

0 commit comments

Comments
 (0)