Skip to content

Commit

Permalink
WIP: rollback status introspection
Browse files Browse the repository at this point in the history
Signed-off-by: g2flyer <michael.steiner@intel.com>
  • Loading branch information
g2flyer committed Jul 9, 2024
1 parent 1e77fa2 commit 7ec30e1
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions libos/include/libos_fs_pseudo.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ int proc_ipc_thread_follow_link(struct libos_dentry* dent, char** out_target);

int init_devfs(void);
int init_attestation(struct pseudo_node* dev);
int init_rollback(struct pseudo_node* dev);

/* sysfs */

Expand Down
4 changes: 4 additions & 0 deletions libos/src/fs/dev/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,9 @@ int init_devfs(void) {
if (ret < 0)
return ret;

ret = init_rollback(root);
if (ret < 0)
return ret;

return 0;
}
64 changes: 64 additions & 0 deletions libos/src/fs/dev/rollback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2024 Intel Labs
* Michael Steiner <michael.steiner@intel.com>
*/

/*!
* \file
*
* This file contains a pseudo-device for an application to inspect the rollback protection state.
* `/dev/rollback/<path> pseudo-file.
*
*/

// TODO (MST): also add pseudo file to get hash of the last seen root hash (or, better for
// atomicity, status ahd hash)

#include "api.h"
#include "libos_fs_encrypted.h"
#include "libos_fs_pseudo.h"
#include "pal.h"
#include "toml_utils.h"

static int path_load(struct libos_dentry* dent, char** out_data, size_t* out_size) {
// TODO (MST): implement me
// - find volume matching path
// - libos/include/libos_fs.h:int walk_mounts(int (*walk)(struct libos_mount* mount, void*
// arg), void* arg);
// - libos_mount* find_mount_from_uri(const char* uri) path_lookupat(start, path,
// - lookup_flags, &dent);
//
// - find (relative) path in map
/*
struct libos_encrypted_volume_state_map* file_state = NULL;
lock(&(enc->volume->files_state_map_lock));
HASH_FIND_STR(enc->volume->files_state_map, norm_path, file_state);
unlock(&(enc->volume->files_state_map_lock));
*/
// - prepare outpub buffer with map entry
/*
if (is_set) {
char* buf = malloc(sizeof(pf_key));
if (!buf)
return -ENOMEM;
memcpy(buf, &pf_key, sizeof(pf_key));
*out_data = buf;
*out_size = sizeof(pf_key);
} else {
*out_data = NULL;
*out_size = 0;
}
*/
__UNUSED(dent);
__UNUSED(out_data);
__UNUSED(out_size);
return 0;
}

int init_rollback(struct pseudo_node* dev) {
struct pseudo_node* rollback_dir = pseudo_add_dir(dev, "rollback");
pseudo_add_str(rollback_dir, "file_status", &path_load);

return 0;
}
1 change: 1 addition & 0 deletions libos/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ libos_sources = files(
'fs/chroot/fs.c',
'fs/dev/attestation.c',
'fs/dev/fs.c',
'fs/dev/rollback.c',
'fs/etc/fs.c',
'fs/eventfd/fs.c',
'fs/libos_dcache.c',
Expand Down
1 change: 1 addition & 0 deletions libos/test/regression/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ tests = {
'readdir': {},
'rename_unlink': {},
'rename_unlink_fchown': {},
'rollback': {},
'run_test': {
'include_directories': include_directories(
# for `gramine_entry_api.h`
Expand Down
28 changes: 28 additions & 0 deletions libos/test/regression/rollback.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2024 Intel Corporation
* Michael Steiner <michael.steiner@intel.com>
*/

/* Test for setting and reading encrypted files keys (/dev/attestation/keys). */

#include <assert.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "rw_file.h"

// TODO (MST): implement me
// - tests
// - handles correctly paths which are not encryped files
// - reports correctly presence/absence of files
// - for existing files, reports correct state (one for each state)

int main(int argc, char** argv) {
return 0;
}
1 change: 1 addition & 0 deletions libos/test/regression/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ manifests = [
"readdir",
"rename_unlink",
"rename_unlink_fchown",
"rollback",
"run_test",
"rwlock",
"sched",
Expand Down
1 change: 1 addition & 0 deletions libos/test/regression/tests_musl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ manifests = [
"readdir",
"rename_unlink",
"rename_unlink_fchown",
"rollback",
"run_test",
"rwlock",
"sched",
Expand Down

0 comments on commit 7ec30e1

Please sign in to comment.