virtiofsd: Don't allow empty filenames
commit28d1ad0ea41342472afda15b515d95671eac4030
authorGreg Kurz <groug@kaod.org>
Fri, 12 Mar 2021 14:10:03 +0000 (12 15:10 +0100)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Mon, 15 Mar 2021 20:01:55 +0000 (15 20:01 +0000)
treef4fd54263e44b1645da54323acc1ef7ceeca4a24
parent6d118c4349966a1890d00bbbdc42001f173c6e4d
virtiofsd: Don't allow empty filenames

POSIX.1-2017 clearly stipulates that empty filenames aren't
allowed ([1] and [2]). Since virtiofsd is supposed to mirror
the host file system hierarchy and the host can be assumed to
be linux, we don't really expect clients to pass requests with
an empty path in it. If they do so anyway, this would eventually
cause an error when trying to create/lookup the actual inode
on the underlying POSIX filesystem. But this could still confuse
some code that wouldn't be ready to cope with this.

Filter out empty names coming from the client at the top level,
so that the rest doesn't have to care about it. This is done
everywhere we already call is_safe_path_component(), but
in a separate helper since the usual error for empty path
names is ENOENT instead of EINVAL.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_170
[2] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13

Signed-off-by: Greg Kurz <groug@kaod.org>
Message-Id: <20210312141003.819108-4-groug@kaod.org>
Reviewed-by: Connor Kuehl <ckuehl@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
tools/virtiofsd/passthrough_ll.c