77 Commits
Author SHA1 Message Date
Danny Hershko Shemesh c619177102 Refuse a veth peer attribute shorter than its ifinfomsg
The peer payload is sliced at the size of a struct ifinfomsg before anything measures it, so 4 bytes panic the Sentry and take the sandbox with it. Any user reaches it after unshare -Ur -n.

Check the length instead of re-testing a lookup that already succeeded. A short payload now answers EINVAL.

Fixes #14516
2026-08-31 16:08:32 +03:00
Parth SarthiandgVisor bot c2e9a88ab3 NIC: Added support to return kind with info.
PiperOrigin-RevId: 959288350
2026-08-04 16:25:37 -07:00
Nayana BidariandgVisor bot 3846731234 Refactor network configuration during restore and defer link creation in runsc
This change refactors the network configuration flow during sandbox restore
and defers the creation of network links and routes in runsc to run after
seccomp filters are installed.

- Replaced ReplaceConfig with ResetConfig in inet.Stack. Introduced
inet.NetworkArgs to configure the stack during restore, updating k.LoadFrom
to use it.
- Renamed CreateLinksAndRoutes URPC to SetNetworkArgs, which now configures
host sockets before seccomp is installed, deferring link/route creation to run
after seccomp.
- Fixed S/R support by saving and restoring limit/burst state.
- Minor seccomp filter adjustments and test updates.

PiperOrigin-RevId: 945995430
2026-07-10 18:52:31 -07:00
Nayana BidariandgVisor bot 7e09cf7be6 Automated rollback of changelist 941330876
PiperOrigin-RevId: 944161934
2026-07-07 16:47:40 -07:00
Nayana BidariandgVisor bot 997db57cd5 Refactor setting up network during restore.
Previously, during sandbox restore the network configuration was restored by
creating a new network stack (which has all the config scraped from the host)
and the replacing this new config such as NICs, routes and IP addresses from
the new stack to the loaded/restored stack.

This change refactors the process by introducing a new `inet.NetworkArgs`
interface that abstracts how the network stack is configured. The `Loader` now
implements this interface and configures the loaded stack directly using the
configuration scraped from the host during restore. `Kernel.LoadFrom` accepts
this interface (instead of stack), allowing it to configure the restored stack
using either the Loader's configuration.

PiperOrigin-RevId: 941330876
2026-07-01 15:37:56 -07:00
lyphyserandHanzo Dev c161e690a0 netstack: log the correct field in the unsupported ifi_flags warning
The warning for unsupported ifi_flags printed ifinfomsg.Change instead of
ifinfomsg.Flags. Print the field actually being validated.

Co-authored-by: Hanzo Dev <[email protected]>
2026-06-19 08:29:46 +00:00
gVisor bot fda893428f Merge pull request #12949 from tanyifeng:net-interface-order
PiperOrigin-RevId: 904671911
2026-04-23 15:44:00 -07:00
Tan Yifeng e2bd312913 net: Ensure deterministic interface enumeration order
Go map iteration randomness causes network interface enumeration
(getifaddrs, RTM_GETADDR, RTM_GETLINK, /proc/net/*, SIOCGIFCONF)
to return nondeterministic order, breaking applications like
asciidoctor that expect stable ordering across repeated calls.

Since gVisor allocates NIC IDs monotonically (like Linux ifindex),
sorting by NICID is equivalent to registration order. Add
InterfaceIDs() to inet.Stack so all consumer paths iterate in
deterministic ascending-ID order without ad-hoc sorting at each
call site.

Signed-off-by: Tan Yifeng <[email protected]>
2026-04-23 10:16:47 +08:00
Nayana BidariandgVisor bot 1e6759d3d9 Remove usages of save-restore-netstack flag.
This flag has been true by default for a while, remove its usages and
deprecate the flag.

PiperOrigin-RevId: 903909652
2026-04-22 10:15:08 -07:00
Shailend ChandandgVisor bot e37f1fe8d0 netstack: Fix cap check around IFLA_NET_NS_FD
When bridging, or when moving a veth, we must check if we have CAP_NET_ADMIN
in the target netns.

PiperOrigin-RevId: 889518624
2026-03-25 17:36:05 -07:00
Jing ChenandgVisor bot 0b3a2d95e3 Fix nil pointer dereference in netstack.Stack.
The netstack.Stack.Destroy method call s.Stack.Close() without checking
if s.Stack is nil. In some edge cases (e.g., during failed restore),
s.Stack can be nil, leading to a panic.

PiperOrigin-RevId: 882212491
2026-03-11 14:59:32 -07:00
Nayana BidariandgVisor bot a41a6099f9 Terminate connections only for restore (not for resume).
Previously, external connections were terminated during both restore and
resume operations, causing a reconnection after every resume. By limiting
termination to the restore only, connections now remain active during resumes
as intended.

Added tests to verify that resume does not terminate the connection.

PiperOrigin-RevId: 868830577
2026-02-12 14:35:26 -08:00
Shailend ChandandgVisor bot 7920d34651 netlink: Supply IFLA_MASTER in RTM_NEWLINK messages
This allows `ip link show master` to work.

PiperOrigin-RevId: 845470317
2025-12-16 16:07:24 -08:00
Shailend ChandandgVisor bot aa19062305 Fix a bug around IFLA_NET_NS_FD
IFLA_NET_NS_FD is supplied in an RTM_SETLINK message from userland to move a
link to a new netns. The same message might mutate other attributes of the
link. Thus far we were applying those changes to a different link in the source
netns.

PiperOrigin-RevId: 842358153
2025-12-09 12:54:40 -08:00
Shailend ChandandgVisor bot b30c659b42 Add RTNLGRP_LINK netlink multicast support for recv
Only netstack supports sending link events, requests to join multicast
groups for netlink sockets continue to be denied when hostinet is in use.

connect() and sendmsg() to RTMGRP_LINK still fails.

PiperOrigin-RevId: 831688843
2025-11-12 22:04:10 -08:00
Nayana BidariandgVisor bot c52821b3e0 Remove old NICs and routes during save/restore.
During restore there will be new NICs and routes created based on the network
config. Close these old NICs and routes in beforeSave() only for save/restore.
For save/resume, do not close them.

As new link endpoints are created during restore, there is no need to start
the associated old processor goroutines in afterLoad. Start them only for
save/resume.

PiperOrigin-RevId: 804994281
2025-09-09 11:33:49 -07:00
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
Nayana BidariandgVisor bot cbd03df7b0 Changes to support netstack save restore.
- Added a new Stats() method in inet.Stack to get the saved stats
during restore.
- Mark stack.nic, tcpip.Route and stack.addressState structs as "nosave".
These fields should not be saved because the IP addresses and routes can
change during restore and new configuration of routes and IP addresses will be
extracted from the restore spec and initialized in the saved stack.
- Changes in Restore() method in icmp, udp, tcp, packet and raw endpoint files
to support save restore of these endpoints. These changes are flag guarded by
the TESTONLY-save-restore-netstack flag.

PiperOrigin-RevId: 707639274
2024-12-18 12:52:22 -08:00
Jing ChenandgVisor bot a1a4c83448 Returns ENOBUFS when writing to a veth device whose buffer is full.
A task is stuck when it keeps sendMsg w/o any recvMsg  until  the number of
message exceeds the buffer limit. The change also significantly bumps the
limit from 64 to 1000 for a larger buffer.

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 704904404
2024-12-10 17:35:54 -08:00
Nayana BidariandgVisor bot 1bc1bb3b81 Restore listening connections when netstack s/r is enabled.
This CL restores the listening connections when netstack s/r is enabled.
The changes include:
- New method as a workaround to replace the new routes and nics to the loaded
stack after restore.
- New Restore() for transport layer protocols to restore the protocol level
background workers.
- Adds afterLoad() method for fdbased processors.
- Adds a test to verify listening connection is restored after checkpointing
with netstack s/r enabled.
- Few other changes to save restore fields to enable netstack s/r.

PiperOrigin-RevId: 698453124
2024-11-20 11:13:57 -08:00
Jing ChenandgVisor bot 8045b3337a Implement RTM_DELROUTE in netstack.
PiperOrigin-RevId: 675711612
2024-09-17 14:33:41 -07:00
Nayana BidariandgVisor bot 2836a4a651 Mark netstack as save and use it only in tests
- Adds a new flag which will enable netstack s/r. When the flag is not enabled,
there is no change in the existing behavior. The flag will be enabled only in
tests to verify the s/r functionality of netstack.
- Some additional fields in netstack were causing panic when netstack is
save/restored. Such fields are marked as 'save'/'nosave' accordingly to resolve
the panic.

PiperOrigin-RevId: 668566657
2024-08-28 12:49:43 -07:00
Jing ChenandgVisor bot ee22eb3a99 Implement RTM_NEWROUTE in netstack to create/replace a route.
PiperOrigin-RevId: 650814137
2024-07-09 18:04:19 -07:00
Jing ChenandgVisor bot 4189e15f4c Skip IFLA_TXQLEN and IFA_BROADCAST in gVisor.
The attributes are expected by Dockerd to start. In gVisor, skipping
the attributes is good enough to run the Docker workloads.

PiperOrigin-RevId: 650362257
2024-07-08 13:49:26 -07:00
Jing ChenandgVisor bot 0d3d1608d7 Fix the MAC address parse in IFLA_ADDRESS and add the tests.
PiperOrigin-RevId: 650333797
2024-07-08 12:19:08 -07:00
Andrei VaginandgVisor bot 1e132c94ce netstack: implement RTM_SETLINK/IFLA_NET_NS_FD
IFLA_NET_NS_FD specifies a file descriptor that refers to a network namespace.

PiperOrigin-RevId: 648882826
2024-07-02 16:49:27 -07:00
Jing ChenandgVisor bot 144d08a7f7 Implement IFLA_MTU which changes a link's MTU.
PiperOrigin-RevId: 648618069
2024-07-02 00:36:40 -07:00
Jing ChenandgVisor bot 750ff31f5e Implement IFLA_IFNAME which specifies an interface's name.
IFLA_IFNAME is used to set an interface's name when being used
with RTM_NEWLINK and RTM_SETLINK. RTM_NEWLINK is the preferred way, it
is backwards compatible with RTM_SETLINK. For gVisor, when RTM_SETLINK is
introduced, it shall just share the implementation.

PiperOrigin-RevId: 647833657
2024-06-28 17:02:31 -07:00
Andrei VaginandgVisor bot 32a344b96b netstack/veth: use a correct stack to call setLink for a peer device
PiperOrigin-RevId: 647074848
2024-06-26 14:17:49 -07:00
Ayush RanjanandgVisor bot efe2391a05 Delete pkg/tcpip/stack.UniqueID.
There are 2 interfaces in gVisor which are exactly the same:
- pkg/tcpip/stack.UniqueID
- pkg/sentry/uniqueid.Provider

Before this change, both were using the Kernel as the unique number generator.
However, we want to decouple the netstack from the kernel. This coupling is
causing bugs in restore because netstack needs to be created before the Kernel
is restored. So right now, netstack ends up using a "temporary" Kernel which is
later destroyed in the restore sequence, but netstack keeps referencing it.

Before this change, the unique ID generator in pkg/tcpip/stack.Stack was used
for 2 things:
1. Provide NIC IDs which are unique across all network namespaces.
2. Implement stack.TransportEndpoint.UniqueID.

(2) is not used anywhere, so deleted it. (1) is overly unique. NIC IDs do not
need to be unique across network namespace. So instead of holding a pointer to
the kernel, added a NIC ID generator in stack.Stack itself and added
NextNICID() function with proper typing.

PiperOrigin-RevId: 646997006
2024-06-26 10:34:48 -07:00
Jing ChenandgVisor bot 338586fe06 Support IFLA_ADDRESS which changes a device's hardware address.
PiperOrigin-RevId: 645611089
2024-06-21 23:56:13 -07:00
Andrei VaginandgVisor bot d01b0e17d0 tcpip: destroy both ends of one veth pair together
PiperOrigin-RevId: 645562424
2024-06-21 18:50:54 -07:00
Andrei VaginandgVisor bot 064490393c netstack: implement bridge devices
Implement the core part. All packets are broadcast-ed to all ports. The next
step will be to implement forwarding and multicast group databases.

PiperOrigin-RevId: 644471256
2024-06-18 12:15:19 -07:00
Andrei VaginandgVisor bot 17947bd917 Implement veth devices
The veth devices are virtual Ethernet devices. They can act as
tunnels between network namespaces to create a bridge to a
physical network device in another namespace, but can also be
used as standalone network devices.

More information can be found here:
https://man7.org/linux/man-pages/man4/veth.4.html

PiperOrigin-RevId: 638853289
2024-05-30 18:25:30 -07:00
Andrei VaginandgVisor bot 4826035472 Pass NEWLINK netlink commands to network stacks
The NEWLINK commands contains many properties and here is no reason to have
another abstract interface between the Sentry and network stacks.

PiperOrigin-RevId: 627916629
2024-04-24 18:42:44 -07:00
Kevin KrakauerandgVisor bot c4ae01e52e netstack: remove GRO from ingress flow
GRO is getting moved and updated. This removes it in preparation for a
follow-up CL.

PiperOrigin-RevId: 621984030
2024-04-04 15:17:08 -07:00
Nayana BidariandgVisor bot 2b1b92635f Add Resume() method in netstack.
Resume method resumes the endpoints after save which is required for
save/resume. This method resumes the endpoint states which were frozen during
save.

PiperOrigin-RevId: 615467468
2024-03-13 10:36:29 -07:00
Nayana BidariandgVisor bot 54b0ba2706 Rename Resume() to Restore() in netstack.
The existing Resume method in netstack is doing the work of Restore. This
method does not resume endpoints as the resumable endpoints are only stored
during the Restore of the sandbox, rename the method appropriately.

PiperOrigin-RevId: 613320887
2024-03-06 13:25:31 -08:00
Kevin KrakauerandgVisor bot 5cdebeb73d netstack: make tcpip.Address hold a []byte
tcp_benchmark throughput increase 2-3%, but allocations go down (25% in the
download benchmark, only 2% in the upload path).

PiperOrigin-RevId: 532523146
2023-05-16 11:40:49 -07:00
Kevin KrakauerandgVisor bot ef88b30bff netstack: make tcpip.Address an opaque type
The important change here is in tcpip/tcpip.go, where tcpip.Address is defined.
The rest is updating uses of tcpip.Address.

This is preparation for netip.Addr or []byte based addresses, which should save
us a bunch of allocations. Currently, we allocate every time we want to, say,
get a tcpip.Address from a header. This is because the header is a byte slice,
but Address is a string. Strings are immutable, so Go allocates and copies.

PiperOrigin-RevId: 532284732
2023-05-15 18:07:03 -07:00
Ghanan GowripalanandgVisor bot 3173a75072 Use tcpip.NICID when get/set-ing GRO timeout
PiperOrigin-RevId: 529535113
2023-05-04 15:47:28 -07:00
Andrei VaginandgVisor bot 7d66029df0 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Ghanan GowripalanandgVisor bot 3ebe155d12 Don't prevent removing loopback in core netstack
Implement this check in netstack integration (in sentry) so that the
core netstack does not prevent an integrator from removing loopback.

PiperOrigin-RevId: 493992707
2022-12-08 14:23:45 -08:00
Kevin KrakauerandgVisor bot 60b0f76f7f netstack: add gro_flush_timeout
Makes a per-interface file available to configure the GRO timeout, e.g.
/sys/class/net/eth0/gro_flush_timeout

PiperOrigin-RevId: 487082821
2022-11-08 16:34:55 -08:00
Kevin KrakauerandgVisor bot 3a76efe831 convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Andrei VaginandgVisor bot 89c8e320fc Don't leak network namespaces
PiperOrigin-RevId: 454707336
2022-06-13 15:05:21 -07:00
Bhasker HariharanandgVisor bot b3a5701e19 Remove TCP endpoint goroutines.
This change removes all endpoint goroutines and all TCP processing is now done
inline in the TCP processor loop. TCP timers directly invoke handlers as
required rather than assert a waker.

UnlockUser is also simplified to just queue the endpoint to the processor
instead of trying to process segments inline. This allows us to centralize logic
for TCP state handling in the processor. This potentially could involve an extra
wakeup but now that endpoint goroutines do not exist this is not such a big
concern as in case of busy servers the processor goroutines will already be
running anyway.

This change also allows us to clean up S/R as now restoring a TCP endpoint does
not require restarting a goroutine and moving it to the right logical point but
only requires that we restart any timers that may have been running when the
save was done and restore any port bindings as required.

Endpoint.Release is now removed in favor of Endpoint.Abort by using Abort in
places where we use Endpoint.Release.

Updates #231

PiperOrigin-RevId: 442673015
2022-04-18 17:35:36 -07:00
Kevin KrakauerandgVisor bot ab738852bf Automated rollback of changelist 407638912
PiperOrigin-RevId: 410665707
2021-11-17 17:07:05 -08:00
Zach KoopmansandgVisor bot de731b1d1a [syserr] Reverse dependency for tcpip.Error
PiperOrigin-RevId: 407638912
2021-11-04 12:11:41 -07:00
Tony GongandgVisor bot 31f5add4b4 Pass address properties in a single struct
Replaced the current AddAddressWithOptions method with
AddAddressWithProperties which passes all address properties in
a single AddressProperties type. More properties that need to be
configured in the future are expected, so adding a type makes adding
them easier.

PiperOrigin-RevId: 396930729
2021-09-15 15:00:01 -07:00