Commit Graph

356 Commits

Author SHA1 Message Date
Alan Somers
6fb3a8fcaa
Merge pull request #2094 from asomers/clippy-aug-11-2023
Clippy cleanup: noop_method_call
2023-08-11 15:43:32 +00:00
Alan Somers
18cbec28a8 Clippy cleanup: noop_method_call 2023-08-11 09:24:01 -06:00
Alan Somers
c1317e477f Add I/O safety to sockopt and some socket functions
* socket
* socketpair
* listen
* setsockopt
* getsockopt
2023-08-06 20:18:09 -06:00
Todd Neal
7a9826273f add vsock support for macOS 2023-07-18 07:31:29 -05:00
Jarred Allen
23125cbb1b Merge branch 'master' into set-sockaddr-length-linux 2023-07-17 11:34:00 -07:00
Ben Kimock
57cdbed0ab Clippy cleanup:
fix the new clippy::non-minimal-cfg lint
2023-06-05 18:11:07 -06:00
Jarred Allen
72a2f567ee PR suggestions: use skip macro 2023-05-22 11:47:24 -07:00
Jarred Allen
96fa5a898c Add test coverage for bug with unset socket address length 2023-05-19 17:00:13 -07:00
Armin Ronacher
960199daf9 Try enabling LocalPeerPid for ios 2023-01-15 22:41:33 +01:00
Armin Ronacher
34788b179b Added changelog entry and test for LocalPeerPid 2023-01-14 19:51:00 +01:00
bors[bot]
99ea907d7d
Merge #1944
1944: Rework vsock test r=asomers a=stefano-garzarella

We mainly provide VsockAddr, so let's try to test well that VsockAddr mapping to libc::sockaddr_vm is correct.

Let's remove all interactions with the socket, since vsock may or may not be available in the environment.
Testing socket(), bind(), listen(), connect(), etc. caused unexpected failures, and it's out of scope of this crate.

So let's simplify the vsock test focussing on VsockAddr. This should work also on graviton, so let's try to re-enable it.

Fixes #1934

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>

Co-authored-by: Stefano Garzarella <sgarzare@redhat.com>
2022-12-14 14:37:34 +00:00
Stefano Garzarella
4d31ecf06b Rework vsock test
We mainly provide VsockAddr, so let's try to test well that VsockAddr
mapping to libc::sockaddr_vm is correct.

Let's remove all interactions with the socket, since vsock may or may
not be available in the environment.
Testing socket(), bind(), listen(), connect(), etc. caused unexpected
failures, and it's out of scope of this crate.

So let's simplify the vsock test focussing on VsockAddr.
This should work also on graviton, so let's try to re-enable it.

Fixes #1934

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2022-12-14 09:54:43 +01:00
Steve Lau
2be852de8e feat: I/O safety for 'sys/select' 2022-12-12 14:18:49 +08:00
bors[bot]
3d3e6b9fa0
Merge #1913 #1926 #1927 #1931 #1933
1913: feat: I/O safety for 'sys/inotify' r=asomers a=SteveLauC

#### What this PR does:

1. Changes the `fd` field of `struct Inotify` from `RawFd` to `OwnedFd`
2. Changes the interfaces of functions in the `impl Inotify {}`
   
    > The type of `self` changes from `Self` to `&mut Self`. 
    
    From:

   ```rust
   pub fn add_watch<P: ?Sized + NixPath>(
         self,
         path: &P,
         mask: AddWatchFlags,
   ) -> Result<WatchDescriptor> 

   pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()>

   pub fn read_events(self) -> Result<Vec<InotifyEvent>>
   ```

   To:

   ```rust
   pub fn add_watch<P: ?Sized + NixPath>(
        &mut self,
        path: &P,
        mask: AddWatchFlags,
    ) -> Result<WatchDescriptor>

   pub fn rm_watch(&mut self, wd: WatchDescriptor) -> Result<()>

   pub fn read_events(&mut self) -> Result<Vec<InotifyEvent>>
   ```
  

   In the previous implementation, these functions can take `self` by value as `struct Inotify` [was `Copy`](https://docs.rs/nix/latest/nix/sys/inotify/struct.Inotify.html#impl-Copy-for-Inotify). With the changes in `1` applied, `struct Inotify` is no longer `Copy`, so we have to take `self` by reference.

-------

Blocks until the merge of #1863 as this PR needs `read(2)` to be I/O-safe.


1926: feat: I/O safety for 'sys/sendfile' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety for module `sys/sendfile`.

1927: feat: I/O safety for 'sys/statvfs' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety for module `sys/statvfs`.

1931: feat: I/O safety for 'sys/uid' & 'sched' r=asomers a=SteveLauC

#### What this PR does:
Adds I/O safety for modules:

1. `sys/uio`
2. `sched`

1933: feat: I/O safety for 'sys/timerfd' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety  for module `sys/timerfd`.

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2022-12-09 16:43:33 +00:00
Steve Lau
8772cde9b8 feat: I/O safety for 'sys/uid' & 'sched' 2022-12-09 11:33:35 +08:00
Steve Lau
f5dffcc7f0 refactor: take AsFd by value 2022-12-09 11:02:30 +08:00
Steve Lau
8f52bc97c9 feat: I/O safety for 'sys/termios' & 'pty' 2022-12-08 14:04:22 +08:00
bors[bot]
67f7d46c6e
Merge #1916
1916: Use I/O safety in sys::mman r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-12-06 22:07:42 +00:00
Alan Somers
16a8c02983 Use I/O safety in sys::mman 2022-12-05 11:43:17 -07:00
Jonathan
4f61d12009 Epoll 2022-12-04 22:50:13 +00:00
Alex Saveau
fb802462a6
Fix clippy lints
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04 13:44:50 -08:00
Alex Saveau
f3aa1affb0
Nuke deprecated net APIs
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-03 11:40:05 -08:00
Alan Somers
8e91b28b64 Fix UB in the SO_TYPE sockopt
When reading a value into an enum from getsockopt, we must validate it.
Failing to do so can lead to UB for example with SOCK_PACKET on Linux.

Perform the validation in GetSockOpt::get.  Currently SockType is the
only type that requires validation.

Fixes #1819
2022-11-28 23:07:54 -07:00
bors[bot]
33a4d495d9
Merge #1865
1865: Add IpMtu sockopt r=asomers a=ShadowJonathan

Resolves https://github.com/nix-rust/nix/issues/1864

Co-authored-by: Jonathan de Jong <jonathandejong02@gmail.com>
2022-11-25 22:35:51 +00:00
Alan Somers
0ae109ddad Clippy cleanup with the latest nightly. 2022-11-25 08:27:55 -07:00
Jonathan de Jong
e9f07eea61 add IpMtu sockopt 2022-11-23 10:48:48 +00:00
bors[bot]
79f04fb3a3
Merge #1857
1857: Add better support for unnamed unix socket addrs r=asomers a=stevenengler

This adds the following 2 functions/methods: `UnixAddr::new_unnamed` and `UnixAddr::is_unnamed`.

Closes #1585

unix(7) on Linux:

> unnamed: A stream socket that has not been bound to a pathname using bind(2) has no name. Likewise, the two sockets created by socketpair(2) are unnamed. When the address of an unnamed socket is returned, its length is `sizeof(sa_family_t)`, and `sun_path` should not be inspected.

**Edit:** This currently isn't working on BSD, but I see why. Will fix it shortly.

Co-authored-by: Steven Engler <opara@cs.georgetown.edu>
2022-11-21 17:45:29 +00:00
Steven Engler
f6a22198a4 fixup! Added better support for unnamed unix socket addrs
Removed test assertion
2022-11-21 12:11:50 -05:00
Steven Engler
49bab984ee fixup! Added better support for unnamed unix socket addrs
Make Linux-only
2022-11-21 12:03:11 -05:00
Steven Engler
8884ea38ec Added better support for unnamed unix socket addrs 2022-11-21 12:03:11 -05:00
Jonathan
63c56263fb mmap non-zero length 2022-11-20 22:53:40 +00:00
bors[bot]
33b5f928ea
Merge #1853
1853: Adds IP_TOS, IPV6_TCLASS and SO_PRIORITY sockopt wrappers for Linux r=asomers a=mzachar

Added socket option wrappers for DiffServ related parameters on Linux

Co-authored-by: mzachar <mzachar@users.noreply.github.com>
2022-11-20 22:03:22 +00:00
Jonathan
d34696c84b mmap addr 2022-11-20 17:16:25 +00:00
mzachar
faac24c779 Adds IP_TOS, IPV6_TCLASS and SO_PRIORITY sockopt wrappers 2022-11-20 13:41:26 +01:00
Michael Baikov
19c83afbbf reimplement recvmsg/sendmmsg
New implementation performs no allocations after all the necessary
structures are created, removes potentially unsound code that
was used by the old version (see below) and adds a bit more
documentation about bugs in how timeout is actually handled

```
    let timeout = if let Some(mut t) = timeout {
        t.as_mut() as *mut libc::timespec
    } else {
        ptr::null_mut()
    };
```
2022-10-14 08:57:41 -04:00
Ryan Zoeller
6e7bddd154 Fix clippy warnings on nightly
Clippy is now smarter about detecting unnecessary casts and
useless conversions, which means we need to be more explicit
about when the conversions are needed for a subset of platforms.

Required changes found by repeatedly running the following command
against a list of the supported platforms.

`xargs -t -I {} sh -c "cargo clippy -Zbuild-std --target {} --all-targets -- -D warnings || exit 255"`

I removed the casts it complained about, and then restored them
with an `#[allow]` if a later target needed the cast.
2022-10-08 14:08:54 -05:00
Alan Somers
c6371db662 Fix a new clippy lint 2022-08-14 10:12:57 -06:00
bors[bot]
ffc793ed4d
Merge #1776
1776: Add support for the IP_SENDSRCADDR control message r=rtzoeller a=matttpt

This control message is available on FreeBSD, NetBSD, and OpenBSD. When used with `sendmsg`, it sets the IPv4 source address. This adds support through a new `ControlMessage::Ipv4SendSrcAddr` variant that complements `ControlMessageOwned::Ipv4RecvDstAddr`.

A few notes:
* `IP_SENDSRCADDR` is actually just an alias for `IP_RECVDSTADDR` (though the code doesn't depend on this).
* On NetBSD, `IP_PKTINFO` can be used to accomplish the same thing and is already supported by nix. On FreeBSD and OpenBSD, though, `IP_SENDSRCADDR` is the only method I'm aware of.
* The accompanying test binds a UDP socket to all local interfaces (0.0.0.0). If this is not acceptable, please let me know; however, FreeBSD requires this to use `IP_SENDSRCADDR`.

I'll add a change-log entry once I see the PR number.

Thanks!

Co-authored-by: Matthew Ingwersen <matttpt@gmail.com>
2022-08-12 04:38:44 +00:00
SteveLau
9161a294d7
Merge branch 'nix-rust:master' into remove-deprecated-items 2022-08-12 08:57:10 +08:00
Michael Baikov
384d47d25e Folloup for !1778, remove some of the less helpful error msgs 2022-08-12 08:29:29 +08:00
SteveLauC
347915bdb5 format code 2022-08-09 12:17:27 +08:00
SteveLauC
d458ecd4e1 remove deprecated items 2022-08-09 12:15:52 +08:00
Matthew Ingwersen
6bf07fdbb9 Add support for the IP_SENDSRCADDR control message
This control message (actually just an alias for IP_RECVDSTADDR) sets
the IPv4 source address when used with sendmsg. It is available on
FreeBSD, NetBSD, OpenBSD, and DragonFlyBSD.
2022-08-05 12:35:57 -04:00
Michael Baikov
a6ee63ac32 fix clippy assertions_on_result_states
https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
2022-08-04 09:44:40 +08:00
Brian May
c45cd74f42 Add support for RecvOrigDstAddr on Linux
Fixes #1767
2022-07-26 07:39:00 +10:00
Alan Somers
e0e768e7b9 Fix a buffer overflow in sys::socket::recvfrom
IPv4 and stream sockets are unaffected, but for datagram sockets of
other address types libc::recvfrom might overwrite part of the stack.

Fixes #1762
2022-07-14 11:37:56 -06:00
musikid
137a9abb66 Add chflags 2022-07-13 21:27:36 -06:00
Alan Somers
dc1a34b864 Clippy cleanup in the tests.
* Remove a redundant closure.
* Comparison with null
* Manual implementation of find
* Suppress a false positive
2022-07-10 08:43:04 -06:00
Costin-Robert Sin
3e6cb639f0 Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:52 +03:00
Ryan Zoeller
80f8320ffd Cleanup cfg blocks
Remove obsolete references to target_env = wasi, target_os = nacl,
target_os = osx, and a typo'd target_os = fushsia that didn't compile
when fixed.

 - target_env = wasi is dead: https://github.com/rust-lang/rust/pull/60117
 - target_os = nacl is dead: https://github.com/rust-lang/rust/pull/45041
 - target_os = osx is dead, but I can't find a link.
2022-06-06 18:50:19 -05:00