14 Commits
Author SHA1 Message Date
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
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
Jing ChenandgVisor bot 60423ba2bc Consider ethernet header size when returning MTU.
PiperOrigin-RevId: 834925762
2025-11-20 15:04:21 -08:00
Shailend ChandandgVisor bot 2c6185b9d1 Support privileged executables inside the sandbox
There is already some support for privileged executables before this change:
file capabilities were taken into account when creating new processes inside
the sandbox from external instigation (but not during execve(2)). set-user-id
and set-group-id bits were never taken into account, and the Sentry behaved
as if NO_NEW_PRIVS is always true. After this change, execve(2) and the
external Exec entry point both take the set-user(group)-id bits and file
capabilities into account.

Because NO_NEW_PRIVS can no longer be assumed to be always set, a couple of
extra checks to prevent privilege elevation during execve(2) are needed:
the presence of a ptracer and the use of a shared fsContext. Moreover,
execve had to be serialized with seccomp(2) when it is syncing filters to
all threads in a group. Serializing execve with PTRACE_ATTACH and seccomp
required some Task runState gymnastics.

Task dumpability is reset when privilege elevation takes place and privilege
elevation is denied for binaries living on nosuid mounts. To fix an old bug
where some aux vectors were populated using data from the old pre-execve
creds, the computation of the (file-privilege-augmented) creds during execve
now takes place before the stack for the new program is set up.

gvisor users who thus far have exec'd into the sandbox with UID as (sandbox)
root will lose the caps an all-powerful namespace root'd have if: 1) the binary
is a suid/guid binary 2) the owner of the binary is host root and there is
no mapping for host root in the host user namespace of the sandbox. To avoid
this surprise, the suid/sgid bits are ignored by default. Users can opt-in
via the --allow-suid flag.

One result of this change is that sudo now works inside the sandbox.

PiperOrigin-RevId: 794414101
2025-08-12 23:07:38 -07:00
Jing ChenandgVisor bot 6fe72c26d6 Update MTU value for ethernet devices.
L2 MTU includes both payload and ethernet header. gVisor has supported setting
data link layer MTU, it will be  up to users to set up proper value for a
device's MTU if a larger value is expected.

By doing the change, gVisor will be consistent with runc:

```shell
# runc
root@cec4d7238802:/# ip link set dev lo mtu 1234
root@cec4d7238802:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

# runsc before the change.
root@7cd89278d414:/# ip link set dev lo mtu 1234
root@7cd89278d414:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1220
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff

# runsc after the change.
root@e811c5851226:/# ip link set dev lo mtu 1234
root@e811c5851226:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
```
PiperOrigin-RevId: 684746090
2024-10-11 01:36:07 -07:00
Jing ChenandgVisor bot 3f71f6d73a Disallow setting a coordinator for a coordinator device.
The error code is based on the runc's behavior:

```shell
# ip link set dev br0 master br0
Error: Can not enslave a bridge to a bridge.
# echo $?
2
```

Reported-by: [email protected]
PiperOrigin-RevId: 679761515
2024-09-27 16:13:45 -07:00
Jing ChenandgVisor bot 8045b3337a Implement RTM_DELROUTE in netstack.
PiperOrigin-RevId: 675711612
2024-09-17 14:33:41 -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 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 b28c2a849c Test renaming a link name in setlink_test.sh
PiperOrigin-RevId: 648834200
2024-07-02 14:01:51 -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 3cae0d54ac test: add the rtnetlink test suit
It is much easier to create complex configurations from bash scripts with help
of the iproute2 tools.

PiperOrigin-RevId: 646286415
2024-06-24 18:25:26 -07:00