Skip to content

Commit

Permalink
[PAL/Linux-SGX] Log invalid search domains/hostname in post_callback()
Browse files Browse the repository at this point in the history
Gramine's logging configuration is done in the PAL-common logic (to
avoid duplication), which is executed after the PAL-specific logic. So
previously, the warnings about invalid search domain names and/or
hostname (which are checked and produced during the PAL-specific logic)
didn't show up in Gramine logs.

This commit saves the invalid DNS information, and prints the warnings
in `post_callback()`, which is after logging is configured.

Signed-off-by: Kailun Qin <[email protected]>
  • Loading branch information
kailun-qin committed Jan 12, 2024
1 parent 2f88dae commit e282ee5
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions pal/src/host/linux-sgx/pal_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ PAL_SESSION_KEY g_master_key = {0};

const size_t g_page_size = PRESET_PAGESIZE;

static struct invalid_dns_host_conf {
char* dn_search[PAL_MAX_DN_SEARCH];
size_t dn_search_count;
char* hostname;
} g_invalid_dns_host_conf = { 0 };

static bool verify_and_init_rpc_queue(void* untrusted_rpc_queue) {
if (!untrusted_rpc_queue) {
/* user app didn't request RPC queue (i.e., the app didn't request exitless syscalls) */
Expand Down Expand Up @@ -367,7 +373,9 @@ static int import_and_init_extra_runtime_domain_names(struct pal_dns_host_conf*
for (size_t i = 0; i < untrusted_dns.dn_search_count; i++) {
untrusted_dns.dn_search[i][PAL_HOSTNAME_MAX - 1] = 0x00;
if (!is_hostname_valid(untrusted_dns.dn_search[i])) {
log_warning("The search domain name %s is invalid, skipping it", untrusted_dns.dn_search[i]);
g_invalid_dns_host_conf.dn_search[g_invalid_dns_host_conf.dn_search_count] =
strdup(untrusted_dns.dn_search[i]);
g_invalid_dns_host_conf.dn_search_count++;
continue;
}

Expand All @@ -388,8 +396,7 @@ static int import_and_init_extra_runtime_domain_names(struct pal_dns_host_conf*

untrusted_dns.hostname[sizeof(untrusted_dns.hostname) - 1] = 0x00;
if (!is_hostname_valid(untrusted_dns.hostname)) {
log_warning("The hostname on the host seems to be invalid. "
"The Gramine hostname will be set to \"localhost\".");
g_invalid_dns_host_conf.hostname = strdup(untrusted_dns.hostname);
} else {
memcpy(pub_dns->hostname, untrusted_dns.hostname, sizeof(pub_dns->hostname));
}
Expand Down Expand Up @@ -547,13 +554,30 @@ static void print_warning_on_invariant_tsc(PAL_HANDLE parent_process) {
}
}

static void print_warnings_on_invalid_dns_host_conf(PAL_HANDLE parent_process) {
if (!parent_process) {
/* Warn only in the first process. */
for (size_t i = 0; i < g_invalid_dns_host_conf.dn_search_count; i++) {
log_warning("The search domain name %s is invalid, skipping it.",
g_invalid_dns_host_conf.dn_search[i]);
}
if (g_invalid_dns_host_conf.hostname != NULL) {
log_warning("The hostname on the host \"%s\" seems to be invalid. "
"The Gramine hostname will be set to \"localhost\".",
g_invalid_dns_host_conf.hostname);
}
}
}

static void post_callback(void) {
if (print_warnings_on_insecure_configs(g_pal_common_state.parent_process) < 0) {
log_error("Cannot parse the manifest (while checking for insecure configurations)");
ocall_exit(1, /*is_exitgroup=*/true);
}

print_warning_on_invariant_tsc(g_pal_common_state.parent_process);

print_warnings_on_invalid_dns_host_conf(g_pal_common_state.parent_process);
}

__attribute_no_sanitize_address
Expand Down

0 comments on commit e282ee5

Please sign in to comment.