-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LibOS] Introduce
sys.fds.limit
manifest option
This manifest option allows to modify the original `RLIMIT_NOFILE` resource limit. There is *no* way to propagate this limit from the host; this is a deliberate design choice. Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
- Loading branch information
Showing
11 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* SPDX-License-Identifier: LGPL-3.0-or-later */ | ||
/* Copyright (C) 2024 Intel Corporation */ | ||
|
||
#include <err.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/resource.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
|
||
#include "common.h" | ||
|
||
int main(void) { | ||
struct rlimit rlim; | ||
|
||
int dev_null_fd = CHECK(open("/dev/null", O_WRONLY, 0666)); | ||
|
||
CHECK(getrlimit(RLIMIT_NOFILE, &rlim)); | ||
printf("old RLIMIT_NOFILE soft limit: %d\n", (int)rlim.rlim_cur); | ||
int old_lim = (int)rlim.rlim_cur; | ||
|
||
/* make sure we can increase the current soft limit */ | ||
if (old_lim <= 0 || old_lim >= (int)rlim.rlim_max) | ||
CHECK(-1); | ||
|
||
int good_dup_fd = dup2(dev_null_fd, old_lim - 1); | ||
CHECK(good_dup_fd); | ||
printf("(before setrlimit) opened fd: %d\n", good_dup_fd); | ||
CHECK(close(good_dup_fd)); | ||
|
||
int fail_dup_fd = dup2(dev_null_fd, old_lim); | ||
if (fail_dup_fd != -1 || errno != EBADF) | ||
CHECK(-1); | ||
|
||
rlim.rlim_cur++; | ||
CHECK(setrlimit(RLIMIT_NOFILE, &rlim)); | ||
printf("new RLIMIT_NOFILE soft limit: %d\n", (int)rlim.rlim_cur); | ||
|
||
fflush(stdout); | ||
|
||
int pid = CHECK(fork()); | ||
if (pid == 0) { | ||
/* verify that NOFILE limit is correctly migrated to the child process */ | ||
good_dup_fd = dup2(dev_null_fd, old_lim); | ||
CHECK(good_dup_fd); | ||
printf("(in child, after setrlimit) opened fd: %d\n", good_dup_fd); | ||
exit(0); | ||
} else { | ||
int status = 0; | ||
CHECK(wait(&status)); | ||
if (!WIFEXITED(status) || WEXITSTATUS(status)) | ||
errx(1, "child wait status: %#x", status); | ||
} | ||
|
||
good_dup_fd = dup2(dev_null_fd, old_lim); | ||
CHECK(good_dup_fd); | ||
printf("(after setrlimit) opened fd: %d\n", good_dup_fd); | ||
CHECK(close(good_dup_fd)); | ||
|
||
CHECK(close(dev_null_fd)); | ||
puts("TEST OK"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% set entrypoint = "rlimit_nofile" -%} | ||
|
||
libos.entrypoint = "{{ entrypoint }}" | ||
|
||
loader.env.LD_LIBRARY_PATH = "/lib" | ||
|
||
fs.mounts = [ | ||
{ path = "/lib", uri = "file:{{ gramine.runtimedir(libc) }}" }, | ||
{ path = "/{{ entrypoint }}", uri = "file:{{ binary_dir }}/{{ entrypoint }}" }, | ||
] | ||
|
||
sys.fds.limit = 4096 | ||
|
||
sgx.max_threads = {{ '1' if env.get('EDMM', '0') == '1' else '4' }} | ||
sgx.debug = true | ||
sgx.edmm_enable = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }} | ||
sgx.use_exinfo = {{ 'true' if env.get('EDMM', '0') == '1' else 'false' }} | ||
|
||
sgx.trusted_files = [ | ||
"file:{{ gramine.runtimedir(libc) }}/", | ||
"file:{{ binary_dir }}/{{ entrypoint }}", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters