OvmfPkg/VirtioFsDxe: add helper for appending and sanitizing paths
EFI_FILE_PROTOCOL.Open() -- for opening files -- and EFI_FILE_PROTOCOL.SetInfo() -- for renaming files -- will require us to append a relative UEFI pathname to an absolute base pathname. In turn, components of the resultant pathnames will have to be sent to virtiofsd, which does not consume UEFI-style pathnames. We're going to maintain the base pathnames in canonical POSIX format: - absolute (starts with "/"), - dot (.) and dot-dot (..) components resolved/removed, - uses forward slashes, - sequences of slashes collapsed, - printable ASCII character set, - CHAR8 encoding, - no trailing slash except for the root directory itself, - length at most VIRTIO_FS_MAX_PATHNAME_LENGTH. Add a helper function that can append a UEFI pathname to such a base pathname, and produce the result in conformance with the same invariants. Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20201216211125.19496-17-lersek@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
This commit is contained in:
committed by
mergify[bot]
parent
28092a3938
commit
9307d7c7a4
@@ -22,6 +22,30 @@
|
||||
#define VIRTIO_FS_FILE_SIG \
|
||||
SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L')
|
||||
|
||||
//
|
||||
// The following limit applies to two kinds of pathnames.
|
||||
//
|
||||
// - The length of a POSIX-style, canonical pathname *at rest* never exceeds
|
||||
// VIRTIO_FS_MAX_PATHNAME_LENGTH. (Length is defined as the number of CHAR8
|
||||
// elements in the canonical pathname, excluding the terminating '\0'.) This
|
||||
// is an invariant that is ensured for canonical pathnames created, and that
|
||||
// is assumed about canonical pathname inputs (which all originate
|
||||
// internally).
|
||||
//
|
||||
// - If the length of a UEFI-style pathname *argument*, originating directly or
|
||||
// indirectly from the EFI_FILE_PROTOCOL caller, exceeds
|
||||
// VIRTIO_FS_MAX_PATHNAME_LENGTH, then the argument is rejected. (Length is
|
||||
// defined as the number of CHAR16 elements in the UEFI-style pathname,
|
||||
// excluding the terminating L'\0'.) This is a restriction that's checked on
|
||||
// external UEFI-style pathname inputs.
|
||||
//
|
||||
// The limit is not expected to be a practical limitation; it's only supposed
|
||||
// to prevent attempts at overflowing size calculations. For both kinds of
|
||||
// pathnames, separate limits could be used; a common limit is used purely for
|
||||
// simplicity.
|
||||
//
|
||||
#define VIRTIO_FS_MAX_PATHNAME_LENGTH ((UINTN)65535)
|
||||
|
||||
//
|
||||
// Filesystem label encoded in UCS-2, transformed from the UTF-8 representation
|
||||
// in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII code
|
||||
@@ -192,6 +216,14 @@ VirtioFsErrnoToEfiStatus (
|
||||
IN INT32 Errno
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
VirtioFsAppendPath (
|
||||
IN CHAR8 *LhsPath8,
|
||||
IN CHAR16 *RhsPath16,
|
||||
OUT CHAR8 **ResultPath8,
|
||||
OUT BOOLEAN *RootEscape
|
||||
);
|
||||
|
||||
//
|
||||
// Wrapper functions for FUSE commands (primitives).
|
||||
//
|
||||
|
Reference in New Issue
Block a user