Skip to content

Commit

Permalink
[LibOS] Allow stat() and chmod() on encrypted-files dirs
Browse files Browse the repository at this point in the history
Commit "[LibOS] Allow `unlink()` on corrupted encrypted files"
introduced checks `if (!dent->inode->data) return -EACCES` for all
encrypted-files callbacks. However, these callbacks are also used for
directories of encrypted files (FS mounts in manifest file and their
sub-dirs), and directories never have `inode->data` anyway. Therefore,
that commit introduced a bug that encrypted-files dirs returned EACCES
error on `stat()` and `chmod()`.

This commit fixes this bug by additionally checking that the inode is of
"regular file" type. A sub-test is added in `sealed_file` LibOS test.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
  • Loading branch information
Dmitrii Kuvaiskii committed Apr 10, 2024
1 parent a9f7d1c commit fa241d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libos/src/fs/chroot/encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static int chroot_encrypted_chmod(struct libos_dentry* dent, mode_t perm) {
assert(locked(&g_dcache_lock));
assert(dent->inode);

if (!dent->inode->data)
if (dent->inode->type == S_IFREG && !dent->inode->data)
return -EACCES;

char* uri = NULL;
Expand Down Expand Up @@ -528,7 +528,7 @@ static int chroot_encrypted_stat(struct libos_dentry* dent, struct stat* buf) {
assert(locked(&g_dcache_lock));
assert(dent->inode);

if (!dent->inode->data)
if (dent->inode->type == S_IFREG && !dent->inode->data)
return -EACCES;

return generic_inode_stat(dent, buf);
Expand Down
12 changes: 12 additions & 0 deletions libos/test/regression/sealed_file.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2021 Intel Corporation */

#define _GNU_SOURCE
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "rw_file.h"

#define ENC_FILES_MOUNT "tmp_enc/mrenclaves/"

#define SECRETSTRING "Secret string\n"
#define SECRETSTRING_LEN (sizeof(SECRETSTRING) - 1)

Expand All @@ -24,6 +29,13 @@ int main(int argc, char** argv) {
argv[0]);
}

/* test that the encrypted-files mount is stat-able (there was a bug in Gramine) */
struct stat st;
if (stat(ENC_FILES_MOUNT, &st) < 0)
err(EXIT_FAILURE, "stat on encrypted-files mount");
if ((st.st_mode & S_IFMT) != S_IFDIR)
errx(EXIT_FAILURE, "stat on encrypted-files mount didn't return S_IFDIR");

ret = access(argv[1], F_OK);
if (ret < 0) {
if (errno == ENOENT) {
Expand Down

0 comments on commit fa241d4

Please sign in to comment.