24 Commits

Author SHA1 Message Date
mlsad3 fd820380a6 Fix head-of-line blocking and resource leak in BidirectionalRelay (#713)
- Closes #712.
- Replace synchronous `write()` calls in
  `BidirectionalRelay` with non-blocking I/O
  and `DispatchSourceWrite` backpressure
  handling. Under concurrent vsock proxy load,
  a single blocked write on the shared serial
  dispatch queue would freeze all relay
  connections permanently, including unrelated
  new connections.
- Set relay file descriptors to `O_NONBLOCK`
  and handle `EAGAIN` by suspending reads and
  installing a write source to drain pending data.
- Give each `BidirectionalRelay` its own serial queue
  instead of sharing one from `UnixSocketRelayManager`,
  eliminating cross-connection blocking.
- Resume suspended read sources before cancelling
  in `stop()` — GCD does not deliver cancel handlers
  on suspended dispatch sources, which caused file
  descriptor and memory leaks on teardown under
  backpressure.
- Guard-unwrap `buf.baseAddress` in
  `drainPendingWrite`.
2026-06-01 10:33:36 -07:00
Sidhartha Mani df125a2300 Prevent recursion attacks in EXT4Formatter.unlink (#415)
This issue doesn't affect any of our existing products. This is a
preemptive fix for downstream consumers of EXT4.format where, in some
platforms, leading `//` in the path could get resolved into a FileTree
that looks like this

```sh
/ 
 └──  / 
 └── usr
```
2026-04-30 12:01:32 -07:00
Danny Canter 57f623d7f7 Start converting libraries to use FoundationEssentials (#676)
This helps on binary size if we can successfully get all Foundation
imports out of our dep chain. It seems Foundation brings in a 30MiB ICU
blob, which bloats vmexec and vminitd.
2026-04-10 19:58:41 -07:00
Dmitry Kovba 7dea6dfa66 Downgrade a relay error to a warning (#545)
- This PR downgrades a relay error that might be
  logged when a connection is closed to a warning.
- Related PR in apple/container#1238.
2026-02-19 19:43:37 -08:00
Yibo Zhuang 185b04af74 fix: explicit cast SHUT_WR and SHUT_RDWR to Int32 (#544)
Release containerization / deployDocs (push) Has been cancelled
Release containerization / Publish release (push) Has been cancelled
Release containerization / containerization (push) Successful in 1s
This is needed in order to make sure containerization compiles
successfully in linux
2026-02-19 15:31:54 -08:00
Dmitry Kovba 36002eed5e Fix the socket relay error handling and log level (#535)
- Downgrades a warning to the debug level in `BidirectionalRelay`
because the shutdown syscall isn't supported for certain socket types
- Rethrows an error if we can't start a socket relay
2026-02-18 15:55:50 -08:00
Dmitry Kovba 7c7ed05e10 Add a public method to wait for the relay to complete (#529)
- Adds a public method to wait for the relay to complete when both
directions close
- Improves error handling
- Moves `UnixSocketRelayManager` into a separate file
- Renames `SocketRelay` to `UnixSocketRelay`
- Adds logs at the info level after converting other logs to the debug
level previously
2026-02-11 23:44:22 -08:00
Dmitry Kovba 69bc038b30 Refactor a bidirectional relay and fix bugs (#516)
Changes:
- Refactors a bidirectional relay into a new class
- Makes the unique identifier for a socket configuration public

Bug fixes:
- Fixes a bug where partial writes didn't advance the pointer
- Fixes a buffer memory leak
- Fixes error messages
- Fixes log messages
- Fixes log levels
2026-02-05 16:50:45 -08:00
Kathryn Baldauf ec2ee3e94d Update license header on all files to include the current year (#470)
Related to https://github.com/apple/container/pull/1024

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2026-01-05 13:08:48 -08:00
Dmitry Kovba bb0cd39177 Lowercase error messages (#440)
For consistency, all error messages are lowercased.
2025-12-09 05:38:48 -08:00
Danny Canter 836b699a91 Wire up experimental OCI runtime support (#416) 2025-11-21 12:16:58 -08:00
Kathryn Baldauf 86f5051fe6 Fix compiler errors in socket types when building with glibc (#421)
* on glibc, swift expects that the msg_controllen is type Int
* on glibc, socket shutdown options should be an Int32

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
2025-11-19 17:36:38 -08:00
Danny Canter cfe4fd77cb Socket: Return Int32 and not FileHandle for uds receives (#398)
Gives more flexibility. The caller doesn't need to carry around this
FileHandle object if they don't really need it.
2025-11-10 15:48:06 -08:00
Danny Canter 8a34763e40 Socket: Add fd receiving (#330)
Via scm_rights. Useful for supporting spawning runc as an OCI runtime as
that's how the pty is passed to the client.
2025-10-14 15:59:56 -07:00
J Logan 995a231348 Removes "all rights reserved" from license header. (#309) 2025-10-03 13:27:59 -07:00
Dmitry Kovba 7b00f39140 Close a handle inside a lock (#257)
Improves https://github.com/apple/containerization/pull/245. A potential
deadlock risk was not proven. This PR moves the closing operation inside
the lock to prevent leaking an unclosed handle in case of an error.
2025-08-11 12:26:31 -04:00
Dmitry Kovba bfc34e0da4 Eliminate race windows in the Socket class (#245)
While individual accesses were properly mutex-protected, the logical
operations were not atomic, leading to a potential inconsistency in a
multi-threaded environment. Multiple separate `state.withLock` calls
created race windows. With the proposed changes, single atomic
operations check and update the state together.
2025-08-06 18:22:54 -07:00
Dmitry Kovba 197e9b63a9 Use Mutex for thread-safe access to structs (#208)
Changes in this PR prevent a race caused by an implicit call to a
computed property getter when updating the property value.
2025-07-11 15:45:27 -07:00
Josh Soref c00ede68c1 fix comment misspellings (#131)
This PR corrects misspellings identified by the [check-spelling
action](https://github.com/marketplace/actions/check-spelling)

The misspellings have been reported at
https://github.com/jsoref/containerization/actions/runs/15662940240/attempts/1#summary-44123291170
The action reports that the changes in this PR would make it happy:
https://github.com/jsoref/containerization/actions/runs/15662940315/attempts/1#summary-44123291367

---------

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2025-06-16 16:06:37 -04:00
Michael Crosby 5d2d7a1bc3 update license header removing new line (#99)
Fixes #63

Signed-off-by: crosbymichael <michael_crosby@apple.com>
2025-06-12 09:57:35 -04:00
Danny Canter fc4a124173 Continue documenting public surface (#25)
Signed-off-by: Danny Canter <danny_canter@apple.com>
2025-06-06 10:34:19 -04:00
Danny Canter f49f668936 Updates to license headers (#17)
- Capitalize containerization.
- Wrap "All rights reserved" to a new line.

Signed-off-by: Danny Canter <danny_canter@apple.com>
2025-06-05 16:16:22 -07:00
Danny Canter 6bc4bf5124 Source code documentation updates (#9)
This change adds documentation to quite a few existing public types that
didn't have a blurb before.

Additionally, this fixes a couple things that I think either didn't make
sense when going to document them:
- Rename ConnectionStream to VsockConnectionStream. This type only
functions for vsock connections.
- Deletes NsLock+Closure. This was not used anywhere.
- Rename ContainerizationOCI/Config.swift to ImageConfig.swift.

Signed-off-by: Danny Canter <danny_canter@apple.com>
2025-06-05 16:16:18 -07:00
Kathryn Baldauf 3407cc3f16 initial commit
Co-authored-by: Aditya Ramani <a_ramani@apple.com>
Co-authored-by: Agam Dua <agam_dua@apple.com>
Co-authored-by: Danny Canter <danny_canter@apple.com>
Co-authored-by: Dmitry Kovba <dkovba@apple.com>
Co-authored-by: Eric Ernst <eric_ernst@apple.com>
Co-authored-by: Evan Hazlett <ehazlett@apple.com>
Co-authored-by: Gilbert Song <gilbertsong@apple.com>
Co-authored-by: Hugh Bussell <hbussell@apple.com>
Co-authored-by: John Logan <john_logan@apple.com>
Co-authored-by: Kathryn Baldauf <k_baldauf@apple.com>
Co-authored-by: Madhu Venugopal <mvenugopal@apple.com>
Co-authored-by: Michael Crosby <michael_crosby@apple.com>
Co-authored-by: Sidhartha Mani <sidhartha_mani@apple.com>
Co-authored-by: Tanweer Noor <tnoor@apple.com>
Co-authored-by: Ximena Perez Diaz <xperez528@gmail.com>
Co-authored-by: Yibo Zhuang <yzhuang@apple.com>
2025-06-05 16:15:21 -07:00