Commit graph

34345 commits

Author SHA1 Message Date
Beniamino Galvani
12754c55d7 bpf: clat: support rewriting the headers inside a ICMPv6 packet 2025-12-31 14:36:24 +01:00
Beniamino Galvani
12517a2ef6 bpf: clat: use the right endian-conversion function
bpf_ntohl() is more correct. But there is no actual change in
behavior.
2025-12-23 22:13:26 +01:00
Beniamino Galvani
1d4e06380f bpf: clat: add missing break statements
To detect problems like this in the future, compile with
-Wimplicit-fallthrough.
2025-12-23 22:13:25 +01:00
Beniamino Galvani
20ffe2be9d bpf: clat: fix translation of ICMPv6 Parameter Problem message 2025-12-23 22:13:23 +01:00
Beniamino Galvani
481b7f2f59 bpf: clat: add comment about debugging 2025-12-23 22:13:22 +01:00
Beniamino Galvani
0bcf646994 clat: support all pref64 lengths
Support all the prefix lengths defined in RFC 6052.
2025-12-23 22:13:21 +01:00
Beniamino Galvani
ec05b73c47 core: export IPv6 next-hop for IPv4 routes 2025-12-23 22:13:20 +01:00
Beniamino Galvani
e4118bddc3 bpf: clat: remove unused includes 2025-12-23 22:13:19 +01:00
Beniamino Galvani
a27af9a91b bpf: clat: rework rewrite_icmpv6() 2025-12-23 22:13:18 +01:00
Beniamino Galvani
02caa635c3 bpf: clat: rework rewrite_icmp() 2025-12-23 22:13:17 +01:00
Beniamino Galvani
e1924352f6 bpf: clat: change the signature of update_icmp_checksum()
- rename argument 'add' to 'v4to6'
- make argument 'ip6h' const since it's not modified by the function
2025-12-23 22:13:16 +01:00
Beniamino Galvani
6df2fdedb2 bpf: clat: remove unused variables 2025-12-23 22:13:15 +01:00
Beniamino Galvani
cca9e1afce clat: pass the configuration as struct
The program only needs to know the local IPv4 address, the local IPv6
address and the PREF64. There is no need to create multiple maps for
that, just pass a configuration struct containing those 3 fields.
2025-12-23 22:13:13 +01:00
Beniamino Galvani
195d6e5561 clat: remove the libxdp dependency
It's no longer required
2025-12-17 18:52:04 +01:00
Beniamino Galvani
6085095101 bpf: clat: rework to avoid pointer arithmetic
Avoid using pointer arithmetic in the BPF program, so that it requires
only CAP_BPF and not CAP_PERFMON. In this context "pointer arithmetic"
means adding a variable value to a packet pointer. This means that the
program no longer tries to parse variable-size headers (IPv4 options,
IPv6 extension headers). Those were already not supported before. It
also doesn't parse VLAN tags, but there should be no need for that. If
we use fixed offset, we can avoid using the parsing helpers from
libxdp.
2025-12-17 18:52:03 +01:00
Beniamino Galvani
48be1b549e ipv4: improve logging for ipv4.dhcp-ipv6-only-preferred 2025-12-17 18:52:02 +01:00
Beniamino Galvani
bf8c9551b8 ipv4: enable by default ipv4.dhcp-ipv6-only-preferred when CLAT is on 2025-12-17 18:52:01 +01:00
Mary Strodl
3d400e3592 NEWS: Note CLAT support 2025-12-17 18:51:59 +01:00
Beniamino Galvani
930b035118 bpf: clat: remove commented code
The rewrite of IPv6 header inside a ICMP error needs to be
implemented. Remove the unused comments for now.
2025-12-17 18:51:59 +01:00
Beniamino Galvani
1aa9bc1f5e bpf: clat: fix error handling for IPv6 packets
There are 3 possible results from clat_translate_v6():

 1. the packet didn't match the CLAT IPv6 address and must be
   accepted;

 2. the packet matches but it is invalid and so it must be dropped;

 3. the packet matches and it is valid; clat_handle_v6() should
    translate the packet to IPv4;

Before, the function returned TC_ACT_SHOT for both 2 and 3. Therefore,
clat_handle_v6() tried to rewrite also invalid packets.

Fix that by returning TC_ACT_UNSPEC for valid packets, meaning that
there isn't a final verdict yet.
2025-12-17 18:51:58 +01:00
Beniamino Galvani
25158ac7e6 bpf: clat: don't explicitly inline functions
BPF handles function calls fine these days.
2025-12-17 18:51:57 +01:00
Beniamino Galvani
acfa0ab3a3 bpf: clat: fix other verifier errors 2025-12-17 18:51:56 +01:00
Beniamino Galvani
d44e21c62c bpf: clat: avoid 32-bit register spills when access skb->data
The verifier reports this error when accessing skb->data:

  ; void *data     = (void *)(unsigned long long)skb->data; @ clat.bpf.c:625
  (61) r2 = *(u32 *)(r1 +76)       ; frame1: R1=ctx() R2_w=pkt(r=0)
  (63) *(u32 *)(r10 -120) = r2
  invalid size of register spill

Apparently it's trying to spill only 32 bits from the register to the
stack, which is invalid. A similar problem was reported here:
https://github.com/cilium/cilium/pull/25336

Add some macros using inline asm to fix the problem. With this change
now the compiler properly generates 64-bit spills.

 ; src/core/bpf/clat.bpf.c:625
-;     void *data     = (void *)(unsigned long long)skb->data;
+;     void *data     = SKB_DATA(skb);
      137:      61 12 4c 00 00 00 00 00 w2 = *(u32 *)(r1 + 0x4c)
-     138:      63 2a 88 ff 00 00 00 00 *(u32 *)(r10 - 0x78) = w2
+     138:      7b 2a 88 ff 00 00 00 00 *(u64 *)(r10 - 0x78) = r2
2025-12-17 18:51:56 +01:00
Beniamino Galvani
32d17d4ce6 core: honor the ipv6.clat property 2025-12-17 18:51:55 +01:00
Beniamino Galvani
e097b33e22 libnm,nmcli: add a ipv6.clat property 2025-12-17 18:37:14 +01:00
Beniamino Galvani
0551f38b83 ndisc: add support for PREF64 option (fixes) 2025-12-17 18:31:17 +01:00
Mary Strodl
1c72b3f252 ndisc: add support for PREF64 option 2025-12-17 18:31:16 +01:00
Beniamino Galvani
6395de653c Add support for CLAT to l3cfg (fixes) 2025-12-17 18:31:15 +01:00
Mary Strodl
e262c84032 Add support for CLAT to l3cfg 2025-12-17 18:31:14 +01:00
Beniamino Galvani
3919f06e98 Add CLAT BPF program and build machinery (fixes) 2025-12-17 18:31:13 +01:00
Mary Strodl
b75c247b6d Add CLAT BPF program and build machinery 2025-12-17 18:31:12 +01:00
Mary Strodl
503673cab3 contrib: Add libbpf and libxdp to dependencies
Required for CLAT support
2025-12-17 18:31:12 +01:00
Mary Strodl
a6be193490 l3-config-data: make get_direct_route_for_host public 2025-12-17 18:31:11 +01:00
Mary Strodl
fd4cd2a7ed clat: propagate network_id down to l3cfg 2025-12-17 18:31:10 +01:00
Beniamino Galvani
a5cc5a7539 netns: add a CLAT IP reservation type
This will be used to obtain an IPv4 address to be used for the CLAT
(464XLAT).

Based on a patch by Mary Strodl <ipadlover8322@gmail.com>.
2025-12-17 18:31:10 +01:00
Beniamino Galvani
a2d147366c Merge branch 'bg/issue1688'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2323
2025-12-17 11:59:20 +01:00
Beniamino Galvani
427a7cf257 nmcli: start the agent only after updating the connection
When connecting to a wifi network and providing the password on the
command line, nmcli first looks if there is a compatible connection to
reuse. If there is not, it creates and activates a new one via a
single call to AddAndActivate().

If there is a compatible connection, nmcli first calls Update() on it
to set the new password and then Activate() to bring it up. Before
that, it registers a secret agent that can prompt for a new password
in case of authentication failure.

However, as soon as nmcli registers a secret agent, NM tries to
activate again the connection if it was blocked due to a previous
authentication failure. This connection attempt is going to fail
because it still uses the old password, as new one hasn't been set via
Update().

Change the order of operations to register the agent after Update()
and before Activate().

Reproducer:

 nmcli device wifi connect SSID password BAD_PASSWORD
 nmcli device wifi connect SSID password GOOD_PASSWORD

Fixes: c8ff1b30fb ('nmcli/dev: use secret agent for nmcli d [wifi] connect')
2025-12-17 10:55:51 +01:00
Beniamino Galvani
3a4e18e302 nmcli: fix "device wifi connect" command with existing connection
Executing this command twice, or when a connection profile already
exists for the SSID:

  nmcli device wifi connect $SSID password $PASSWORD

returns error:

  Error: 802-11-wireless-security.key-mgmt: property is missing.

When setting the password nmcli was wiping the existing wireless
security setting.

Fixes: c8ff1b30fb ('nmcli/dev: use secret agent for nmcli d [wifi] connect')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1688
2025-12-17 10:55:50 +01:00
Íñigo Huguet
8e0825f9cd release: bump version to 1.57.1 (development) 2025-12-12 16:01:44 +01:00
Íñigo Huguet
df8288de7f merge: branch 'ih/strerror_r'
Fix two compilation issues

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2330
2025-12-12 14:36:58 +00:00
Íñigo Huguet
118475d571 ci: build with -D systemdsystemgeneratordir=no
Avoid build failures in some distros.
  ERROR: Assert failed: systemd required but not found, please provide a valid systemd user generator dir or disable it

Fixes: 636fb5ef24 ('systemd: install initrd services using a generator')
2025-12-12 15:24:09 +01:00
Íñigo Huguet
599cc1ed1d std-aux: use _nm_strerror_r
The function strerror_r returns an int per POSIX spec, but GNU version
returns char *. Using it fails the compilation in Alpine, so use
_nm_strerror_r instead that handles both cases.

Fixes: 41e28b900f ('daemon-helper: add read-file-as-user')
2025-12-12 15:07:53 +01:00
Íñigo Huguet
1756ec54e3 merge: branch 'issue1809'
CVE-2025-9615: avoid that non-admin user using other users' certificates.

Closes #1809

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2324
2025-12-12 12:29:41 +00:00
Beniamino Galvani
1a52bbe7c9 libnm: add function to copy a certificate or key as user
Add a new public function nm_utils_copy_cert_as_user() to libnm. It
reads a certificate or key file on behalf of the given user and writes
it to a directory in /run/NetworkManager. It is useful for VPN plugins
that run as root and need to verify that the user owning the
connection (the one listed in the connection.permissions property) can
access the file.
2025-12-12 12:43:15 +01:00
Beniamino Galvani
57eb4a5bc6 vpn: check that plugin supports private connections
Only allow private VPN connections if the VPN plugin declares the
supports-safe-private-file-access capability. Also check that the
private connection doesn't have more than one owner.
2025-12-12 12:42:01 +01:00
Beniamino Galvani
10db4baeb6 vpn: add nm_vpn_plugin_info_supports_safe_private_file_access()
The new API indicates that the VPN plugin supports reading files
(certificates, keys) of private connections in a safe way
(i.e. checking user permissions), or that it doesn't need to read any
file from disk.
2025-12-12 12:41:28 +01:00
Beniamino Galvani
8d8edda3f4 core,libnm-core: introduce property flag for certificate and keys
If we add a new property in the future and it references a certificate
or key stored on disk, we need to also implement the logic to verify
the access to the file for private connections.

Add a new property flag NM_SETTING_PARAM_CERT_KEY_FILE to existing
certificate and key properties, so that it's easier to see that they
need special treatment. Also add some assertions to verify that the
properties with the flag are handled properly.

While at it, move the enumeration of private-files to the settings.
2025-12-12 12:38:50 +01:00
Beniamino Galvani
e85cc46d0b core: pass certificates as blobs to supplicant for private connections
In case of private connections, the device has already read the
certificates and keys content from disk, validating that the owner of
the connection has access to them. Pass those files as blobs to the
supplicant so that it doesn't have to read them again from the
filesystem, creating the opportunity for TOCTOU bugs.
2025-12-12 12:38:50 +01:00
Beniamino Galvani
a1928b4459 device: read private files in stage2
During stage2 (prepare) of an activation, check if the connection is
private and if it contains any certificate/key path. If so, start
reading the files and delay stage2. Once done, store the files'
content into priv->private_files.table and continue the activation.
2025-12-12 12:38:49 +01:00
Beniamino Galvani
9703305122 core: add functions to read private files of connections
Add function nm_utils_read_private_files(). It can be used to read a
list of paths as the given user. It spawns the daemon-helper to read
each path and returns asynchronously a hash table containing the files
content.

Also add nm_utils_get_connection_private_files_paths() to return a
list of file paths referenced in a connection. The function currently
returns only 802.1x file paths for certificates and keys.
2025-12-12 12:38:49 +01:00