Skip to content

Commit bc99979

Browse files
Squashed commit of the following:
commit e44f2c0 Author: Alice Wen <[email protected]> Date: Tue Oct 8 14:58:46 2024 -0400 Update README.md commit e244b91 Author: Chinmay Shringi <[email protected]> Date: Tue Oct 8 14:55:53 2024 -0400 Feat update readme (#49) * feat: update readme * feat: added images commit ebff6b7 Author: Alice Wen <[email protected]> Date: Tue Oct 1 13:21:00 2024 -0400 Porting newest version fdtables and Synchronize the progress of porting test suite (#14) * change to latest fdtables * using newest fdtables * mmap debug * mmap debug * mmap debug * porting test suite * porting test suite * Add more detailed comments * Fix directory cleanup issue in ut_lind_fs_mmap_invalid_flags_both test case (#16) * fix: ut_lind_fs_chdir_removeddir * fix: add syscalls * fix: revert changes * fix: testing subdir1 * fix: testing without i32 * fix: revert to mkdir * fix: test with if * fix: revert * debug: added print * debug: added print * fix: print * fix: revert println * feat: return invalid * fix: revert removed return * feat: update rm subdir1 subdir2 * refactor: update comments * fix: test case ut-lind-fs-fchdir-invalid-args * Fix out-of-range file descriptor error in `getdents` syscall (#17) * Fix: out-of-range file descriptor handling in getdents syscall * fix: update comment * Update src/fdtables/dashmapvecglobal.rs Co-authored-by: Justin Cappos <[email protected]> --------- Co-authored-by: lind <[email protected]> Co-authored-by: Justin Cappos <[email protected]> * Fix `getcwd_syscall` to Handle Invalid Arguments and Correctly Set `errno` (#24) * fix: test case ut_lind_fs_getcwd_invalid_args * fix: PR comments --------- Co-authored-by: lind <[email protected]> * Fix mmap test case to handle invalid flags scenario correctly (#18) * Fix: mmap test to validate EINVAL for invalid flags * fix: PR comments --------- Co-authored-by: lind <[email protected]> * Fix Test `ut_lind_fs_pread_from_directory` from Directory to Return Correct Error (#27) * fix: test case ut_lind_fs_pread_from_directory * fix: add rmdir syscall --------- Co-authored-by: lind <[email protected]> * fix: test case ut-lind-fs-write-to-directory (#19) Co-authored-by: lind <[email protected]> * fix: ut-lind-fs-simple (#21) Co-authored-by: lind <[email protected]> * Fix `ut_lind_fs_rmdir_nowriteperm_parent_dir` rmdir Nowrite Permission Handling and Recursive Directory Cleanup (#28) * fix: test case ut_lind_fs_rmdir_nowriteperm_parent_dir * feat: added cleanup --------- Co-authored-by: lind <[email protected]> * Fix ut lind fs mkdir nonexisting directory (#25) * fix: test case ut_lind_fs_mkdir_nonexisting_directory * feat: added rmdir_recursive_syscall * fix: rm unecessary function * feat: updated comment * feat: updated values --------- Co-authored-by: lind <[email protected]> * Fix EISDIR Error in `ut_lind_fs_getdents_bufsize_too_small` Test by Adjusting Directory Open Flags (#29) * fix: test case ut_lind_fs_getdents_bufsize_too_small * fix: rmdir for clean env --------- Co-authored-by: lind <[email protected]> * Fix EEXIST Error in `ut_lind_fs_close_directory` Test by Removing Existing Directories Before Creation (#31) * fix: test case ut_lind_fs_close_directory * feat: use rmdir --------- Co-authored-by: lind <[email protected]> * Fix EEXIST Error in `ut_lind_fs_dir_multiple` Test by Removing Existing Directories Before Creation (#32) * fix: test case ut_lind_fs_dir_multiple * feat: updated to rmdir --------- Co-authored-by: lind <[email protected]> * Fix EEXIST Error in `ut_lind_fs_dir_mode` Test by Removing Existing Directories Before Creation (#30) * fix: test case ut_lind_fs_dir_mode * fix: cleanup the enviornment --------- Co-authored-by: lind <[email protected]> * Fix EEXIST Error in `ut_lind_fs_unlink_directory` (#34) * fix: test case ut_lind_fs_rmdir_nonexist_dir (#36) * fix: test case ut_lind_fs_rmdir_nonempty_dir (#37) * fix: test case ut_lind_fs_link_directory (#38) * fix: test case ut_lind_fs_read_from_directory (#39) * fix: test case ut_lind_fs_rename (#41) * Fix in `ut_lind_fs_tmp_file_test` ensure /tmp Directory Is Properly Set Up and Cleaned (#35) * fix: test case ut_lind_fs_read_from_chardev_file (#44) Co-authored-by: lind <[email protected]> --------- Co-authored-by: Chinmay Shringi <[email protected]> Co-authored-by: lind <[email protected]> Co-authored-by: Nicholas Renner <[email protected]> Co-authored-by: Justin Cappos <[email protected]>
1 parent c82d690 commit bc99979

File tree

9 files changed

+320
-65
lines changed

9 files changed

+320
-65
lines changed

README.md

Lines changed: 190 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# RustPOSIX [![Build Status](https://github.com/Lind-Project/safeposix-rust/actions/workflows/lind-selfhost.yml/badge.svg?branch=develop)](https://github.com/Lind-Project/safeposix-rust/actions/workflows/lind-selfhost.yml)
2-
3-
More implementation details could be found at [wiki](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Home.md).
1+
# RawPOSIX [![Build Status](https://github.com/Lind-Project/safeposix-rust/actions/workflows/lind-selfhost.yml/badge.svg?branch=develop)](https://github.com/Lind-Project/safeposix-rust/actions/workflows/lind-selfhost.yml)
42

53
## Contents
64

@@ -12,7 +10,195 @@ More implementation details could be found at [wiki](https://github.com/Lind-Pro
1210
* [Style Guide](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Style-Guide.md)
1311
* [Testing and Debugging](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Testing-and-Debugging.md)
1412

15-
## Run RustPOSIX-Rust
13+
## Overview
14+
This document provides a step-by-step guide to access the NYU SSH server and run Docker commands to set up and test the Lind project. If you face issues while accessing the server, troubleshooting steps are included to help you resolve them efficiently.
15+
16+
## Accessing the SSH Server
17+
### SSH Command Format
18+
To gain access, use the following SSH command format:
19+
20+
```bash
21+
[username]@lind-server.engineering.nyu.edu
22+
```
23+
24+
**Description**: Replace `[username]` with your NYU username to connect to the Lind server. This command will initiate a secure shell connection to the server, allowing you to work on the remote system.
25+
26+
### Troubleshooting Access Issues
27+
#### Permission Denied
28+
- **Description**: This usually means that the password is incorrect. Please try to recall the correct password or contact seniors for assistance, or ask for help in the Slack channel.
29+
30+
![Permission Denied](assets/permission-denied.readme.png)
31+
32+
#### Operation Timed Out / Unable to Resolve Host
33+
- **Description**: This error generally means that your network is incorrect or unavailable.
34+
35+
![Operation Timed Out](assets/timed-out.readme.png)
36+
37+
### Network Verification
38+
To verify network connectivity, follow these steps:
39+
40+
1. **Are you on an on-campus network?**
41+
42+
![On-campus Network](assets/network.readme.png)
43+
44+
2. If connected but still unable to access, contact seniors or use the Slack channel for support.
45+
46+
3. If not connected to the on-campus network, connect to VPN via the [NYU VPN Guide](https://www.nyu.edu/life/information-technology/infrastructure/network-services/vpn.html).
47+
48+
## Running Docker
49+
### Running the Docker Container
50+
![Running Docker](assets/docker.readme.png)
51+
52+
Once you have SSH access, run the Docker container with the following command:
53+
54+
```bash
55+
docker run --privileged --ipc=host --cap-add=SYS_PTRACE -it securesystemslab/lind /bin/bash
56+
```
57+
58+
**Description**: This command starts a Docker container using the image `securesystemslab/lind`. The options used are:
59+
60+
- `--privileged`: Grants extended privileges to the container.
61+
- `--ipc=host`: Allows the container to share the host’s IPC namespace, enabling shared memory.
62+
- `--cap-add=SYS_PTRACE`: Adds the capability to use `ptrace`, which is helpful for debugging.
63+
- `-it`: Opens an interactive terminal session.
64+
- `/bin/bash`: Launches a Bash shell inside the container.
65+
66+
**Note**: This command will give you an interactive shell inside the Docker container where you can run other commands.
67+
68+
## Next Steps After Running Docker
69+
### Checking Git Branch and Updating
70+
Once inside the container:
71+
72+
1. **Ensure you are on the `develop` branch**. Run the following commands to check and update:
73+
74+
```bash
75+
git branch
76+
```
77+
78+
**Description**: Displays the current branch. Ensure that you are on the `develop` branch.
79+
80+
```bash
81+
git pull
82+
```
83+
84+
**Description**: Fetches the latest updates from the remote repository and merges them into your current branch.
85+
86+
### Building Lind
87+
1. **Update Contents**:
88+
- Run the following command to update contents to the newest version:
89+
90+
```bash
91+
make -2
92+
```
93+
94+
**Description**: This command will ensure that all the components are updated to the latest version. The `make` command runs the instructions defined in the Makefile, and the `-2` argument here specifies a particular target or set of actions.
95+
96+
2. **Build the Regular Lind Version**:
97+
- Run the following command to build the standard version of Lind:
98+
99+
```bash
100+
make -1
101+
```
102+
103+
**Description**: This command builds the standard version of Lind, preparing it for use.
104+
105+
## Running RawPOSIX
106+
### Environment Setup for RawPOSIX
107+
To run RawPOSIX, follow these steps:
108+
109+
1. **Navigate to the project directory and set up the environment**:
110+
111+
```bash
112+
cd src
113+
sudo rm -rf safeposix-rust
114+
git clone https://github.com/Lind-Project/RawPOSIX.git
115+
mv RawPOSIX/ safeposix-rust
116+
cd /home/lind/lind_project
117+
make -1
118+
```
119+
120+
**Description**:
121+
- `cd src`: Change to the source directory.
122+
- `sudo rm -rf safeposix-rust`: Remove the existing `safeposix-rust` directory (requires admin privileges).
123+
- `git clone ...`: Clone the RawPOSIX repository from GitHub.
124+
- `mv RawPOSIX/ safeposix-rust`: Rename the cloned directory to `safeposix-rust`.
125+
- `cd /home/lind/lind_project`: Change to the Lind project directory.
126+
- `make -1`: Build the project.
127+
128+
### Generating Network Devices for RawPOSIX
129+
2. **Generate network devices** required for RawPOSIX:
130+
131+
```bash
132+
cd src/safeposix-rust
133+
./gen_netdev.sh
134+
```
135+
136+
**Description**:
137+
- `cd src/safeposix-rust`: Change to the `safeposix-rust` directory.
138+
- `./gen_netdev.sh`: Run the script to generate network devices.
139+
140+
## Testing Suites
141+
### Running Lind Test Suites
142+
Navigate to the project root and run the following command:
143+
144+
```bash
145+
cd /home/lind/lind_project
146+
make test
147+
```
148+
149+
**Description**: This command runs the full test suite for Lind, verifying that all components are functioning as expected.
150+
151+
### Running RawPOSIX Test Suites
152+
To build and run the tests for RawPOSIX:
153+
154+
```bash
155+
cd src/safeposix-rust
156+
cargo build
157+
cargo test
158+
```
159+
160+
**Description**:
161+
- `cargo build`: Compiles the Rust code for the RawPOSIX project.
162+
- `cargo test`: Runs the test suite for RawPOSIX to verify functionality.
163+
164+
#### Running Specific Test Cases
165+
To run a specific test case:
166+
167+
```bash
168+
cargo test <TEST_CASE_NAME>
169+
```
170+
171+
**Example**:
172+
173+
```bash
174+
cargo test ut_lind_fs_mkdir_invalid_modebits
175+
```
176+
177+
**Description**: This command runs a specific test case, allowing you to focus on one feature or functionality at a time.
178+
179+
## FAQ
180+
### Handling Errors
181+
1. **New error that requires a big fix**:
182+
- Contact the team and inform the seniors.
183+
- Open a GitHub issue to track the problem.
184+
185+
2. **Encountering a smaller issue**:
186+
- Check if an existing issue is logged. If not, create one at: [https://github.com/Lind-Project/RawPOSIX/issues/15](https://github.com/Lind-Project/RawPOSIX/issues/15).
187+
188+
### Tagging for Review
189+
- Tag two reviewers: either Alice, Nick, or Yuchen Zhang.
190+
191+
### Pull Request (PR) Description
192+
- Write a clear and concise description for each PR.
193+
- Add comments for easier understanding.
194+
195+
### Commenting on Code
196+
- **Requirement**: Comments are required for new code to ensure others can understand it.
197+
- **Future Improvements**: Reference the relevant GitHub issue for any future improvements.
198+
199+
![Comment Example](assets/comments.readme.png)
200+
201+
## Run RawPOSIX-Rust
16202

17203
Quick start
18204
Use Develop branch for the most stable behaviour.
@@ -28,21 +214,10 @@ helpful for exploration and easy testing.
28214

29215
See reference at [Run RustPOSIX Independently](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Run-Independently.md)
30216

31-
## Test RustPOSIX-Rust
32-
33-
Use main branch for the most stable behaviour.
34-
35-
```bash
36-
cargo build
37-
cargo test --lib
38-
```
39-
40217
See reference at [Testing and Debugging](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Testing-and-Debugging.md)
41218

42219
## Development Guideline
43220

44221
* All PRs should be merged to the Develop branch
45222

46223
* Any imports from the standard library or any crates should be done in an interface file
47-
48-
More detailed guideline will be in [RustPOSIX's wiki](https://github.com/Lind-Project/lind-docs/blob/main/docs/RustPOSIX/Style-Guide.md)

assets/comments.readme.png

235 KB
Loading

assets/docker.readme.png

336 KB
Loading

assets/network.readme.png

75.6 KB
Loading
128 KB
Loading

assets/timed-out.readme.png

135 KB
Loading

src/fdtables/dashmapvecglobal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ pub fn translate_virtual_fd(cageid: u64, virtualfd: u64) -> Result<FDTableEntry,
8585
// always have a table for each cage because each new cage is added at fork
8686
// time
8787
assert!(FDTABLE.contains_key(&cageid),"Unknown cageid in fdtable access");
88+
// Below condition checks if the virtualfd is out of bounds and if yes it throws an error
89+
// Note that this assumes that all virtualfd numbers returned < FD_PER_PROCESS_MAX
90+
if virtualfd >= FD_PER_PROCESS_MAX {
91+
return Err(threei::Errno::EBADFD as u64);
92+
}
8893

8994
return match FDTABLE.get(&cageid).unwrap()[virtualfd as usize] {
9095
Some(tableentry) => Ok(tableentry),

src/safeposix/syscalls/fs_calls.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -790,12 +790,16 @@ impl Cage {
790790
return syscall_error(Errno::EBADF, "mmap", "Bad File Descriptor");
791791
}
792792
}
793-
}
794-
795-
// Do type conversion to translate from c_void into i32
796-
unsafe {
797-
((libc::mmap(addr as *mut c_void, len, prot, flags, -1, off) as i64)
798-
& 0xffffffff) as i32
793+
} else {
794+
// Handle mmap with fd = -1 (anonymous memory mapping or special case)
795+
let ret = unsafe {
796+
libc::mmap(addr as *mut c_void, len, prot, flags, -1, off) as i64
797+
};
798+
// Check if mmap failed and return the appropriate error if so
799+
if ret == -1 {
800+
return syscall_error(Errno::EINVAL, "mmap", "mmap failed with invalid flags");
801+
}
802+
return (ret & 0xffffffff) as i32;
799803
}
800804
}
801805

@@ -1060,10 +1064,17 @@ impl Cage {
10601064
* - null, fail
10611065
*/
10621066
pub fn getcwd_syscall(&self, buf: *mut u8, bufsize: u32) -> i32 {
1067+
if (!buf.is_null() && bufsize == 0) || (buf.is_null() && bufsize != 0) {
1068+
return syscall_error(Errno::EINVAL, "getcwd", "Invalid arguments");
1069+
}
1070+
10631071
let cwd_container = self.cwd.read();
10641072
let path = cwd_container.to_str().unwrap();
1065-
if path.len() >= bufsize as usize {
1066-
return -1;
1073+
// The required size includes the null terminator
1074+
let required_size = path.len() + 1;
1075+
if required_size > bufsize as usize {
1076+
unsafe { *libc::__errno_location() = libc::ERANGE };
1077+
return -libc::ERANGE;
10671078
}
10681079
unsafe {
10691080
ptr::copy(path.as_ptr(), buf, path.len());

0 commit comments

Comments
 (0)