Commit graph

12494 commits

Author SHA1 Message Date
Alexey Kodanev
70ebdc7730 nm-manager: restore passing correct size to sendfile in copy_lease()
Otherwise sendfile() fails with EINVAL when the file offset
is greater than zero (pos + size > max), always on the second
iteration.

Fixes: 0c6cd07ec8 ('nm-manager: remove lease file if copying dhclient lease fails')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/359
2019-12-12 08:07:20 +01:00
Beniamino Galvani
f2dbf8fbc0 manager: forbid autoactivation of parent when it is blocked by user request
If a device is being autoactivated and requires a parent that is
blocked due to user request, the autoactivation attempt should fail
because NM shouldn't overrule the user decision.

https://bugzilla.redhat.com/show_bug.cgi?id=1765566
2019-12-11 13:46:57 +01:00
Beniamino Galvani
9339d3310e device: always allow reapply of MTU from wired setting
Many device types take the MTU value from the wired setting; usually
they don't implement the can_reapply_change() method and so the MTU
can't be changed with the Reapply() API.

Instead of implementing the method for all such devices to support the
same property (adding a lot of duplicated code), add a check in
NMDevice to allow the reapply of MTU when we recognize that the device
uses the MTU from the wired setting.

Device types can still decide to implement can_reapply_change() and
support whatever properties they want, even from the wired setting.
2019-12-11 13:35:35 +01:00
Beniamino Galvani
ceeefa82c5 infiniband: allow reapply of MTU 2019-12-11 13:35:35 +01:00
Thomas Haller
fd8c8ffe0d config: print config warnings during NetworkManager --print-config 2019-12-11 11:52:05 +01:00
Thomas Haller
8f96d3cb0c config: emit warning about invalid main.auth-polkit setting 2019-12-11 11:52:05 +01:00
Thomas Haller
8d20b9363b config: add nm_config_data_get_warnings() to get additional warnings about wrong configuration
No additional warnings are implemented yet.
2019-12-11 11:52:05 +01:00
Thomas Haller
6998c5f129 config: return GPtrArray with warnings from internal read_entire_config() function
The underlying GPtrArray that we use to construct the list of warnings
is more useful than the strv array. For the internal function, don't
let it return the strv array but instead take (and fill) the warnings
as GPtrArray. There is no difference in practice, because also
previously we would always create an empty GPtrArray.
2019-12-11 11:52:05 +01:00
Thomas Haller
6d7446e52f core: add main.auth-polkit option "root-only"
We always build with PolicyKit support enabled, because it has no
additional dependencies, beside some D-Bus calls.

However, in NetworkManager.conf the user could configure
"main.auth-polkit" to disable PolicyKit. However, previously it would
only allow to disable PolicyKit while granting access to all users.

I think it's useful to have an option that disables PolicyKit and grants
access only to root. I think we should not go too far in implementing
our own authorization mechanisms beside PolicyKit (e.g. you cannot
disable PolicyKit and grant access based on group membership of the
user). However, disabling PolicyKit can be useful sometimes, and it's
simple to implement a "root-only" setup.

Note one change is that when NetworkManager now runs without a D-Bus
connection (in initrd), it would deny all non-root requests. Previously
it would grant access. I think there should be little difference in
practice, because if we have no D-Bus we also don't have any requests to
authenticate.
2019-12-11 11:52:05 +01:00
Thomas Haller
0c6cd07ec8 nm-manager: remove lease file if copying dhclient lease fails
- also use nm_auto_close and nm_close().
2019-12-11 10:05:00 +01:00
Alexey Kodanev
ce1f9e6eb9 nm-manager: fix selinux label for dhclient lease file from initramfs
When moving a lease file from initramfs directory to NetworkManager
run directory, SELinux label for that file retains tmpfs_t type.

Fix it by using sendfile() instead of rename(). That way, the
lease file will have the default type: NetworkManager_var_run_t.
Since we take ownership of the lease file, also drop it from the
old location.

* Before the patch:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:tmpfs_t:s0 dhclient-13162c00-abfb-4e28-bbfb-170187ddd044-ens3.lease

* After:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:NetworkManager_var_run_t:s0 dhclient-f47d1908-67ae-49c6-bd5e-19a690d85526-ens3.lease

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/353
2019-12-11 09:58:45 +01:00
Thomas Haller
33754752ea core: use nm_client_permission_result_to_string() to map permission result
In NetworkManager we have NMAuthCallResult, which is really a duplicate
of NMClientPermissionResult.

Maybe NMAuthCallResult should be entirely replaced by NMClientPermissionResult.
But the name NMClientPermissionResult is a bit awkward. But then the
duplication is even more awkward... fixing this is left for another day.
2019-12-10 07:53:25 +01:00
Thomas Haller
466a4c4562 core: don't duplicate list of known permissions in impl_manager_get_permissions()
Reuse the list of all permissions and don't duplicate it.

Also, now the result of GetPermissions() on D-Bus contains the
permissions sorted by name. We get it almost for free, and it's
a nice property.
2019-12-10 07:53:25 +01:00
Thomas Haller
50a12ce2d5 core: also return unknown permission check result
For example with

  mount -o remount,rw,hidepid=1 /proc/

all permission checks will fail with an error. Internally, we map the
failure to NM_AUTH_CALL_RESULT_UNKNOWN.

    <trace> [1575645672.5958] auth: call[1069]: CheckAuthorization(org.freedesktop.NetworkManager.enable-disable-connectivity-check), subject=unix-process[pid=468316, uid=1000, start=1912881]
    <trace> [1575645672.6295] auth: call[1069]: completed: failed: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dfile_2derror_2dquark.Code4: Failed to open file “/proc/468316/status”: No such file or directory
    <debug> [1575645672.6296] manager: unknown auth chain result 0

First of all, we should not log a debug message about that (we already log the
result of permission checks separately).

Also, we should include the unknown result in the response. The permission was
checked, and omitting it from GetPermissions() result seems wrong (even if we
failed to get the result).

Note that "unknown" is now a new possible return value on D-Bus. But
see how nm_permission_result_to_client() would map such a value to
"unknown" as well. So, it's probably a fine extension of the D-Bus API.

Note that NMClient API is currently quite limited. The user won't know
whether permissions were received (and if they were received, they
could not distinguish between UNKNOWN and absent). Hence, returning
all permissions as unknown (or not at all) causes `nmcli general permissions`
to hang. The solution here is to improve NMClient API to allow the user
to know when the permissions are received. But this patch doesn't
fix the hanging of nmcli nor the limitation of NMClient's API.
2019-12-10 07:53:25 +01:00
Thomas Haller
b650d1d181 core: also check "org.freedesktop.NetworkManager.wifi.scan" permissions 2019-12-10 07:53:25 +01:00
Thomas Haller
e0569ee575 settings: assert that we don't leak error variable in impl_settings_load_connections() 2019-12-09 09:54:17 +01:00
Thomas Haller
eb642fecdf settings: fix use after free in keyfile's load_connections()
Fixes: d35d3c468a ('settings: rework tracking settings connections and settings plugins')
2019-12-09 09:54:11 +01:00
Thomas Haller
1e742e0fb4 ifcfg: don't use D-Bus connection if NMDBusManager is without main connection
In configure-and-quit mode, NMDBusManager does not have a D-Bus connection.
Likewise, ifcfg-rh plugin should not use one either.
2019-12-09 09:02:24 +01:00
Thomas Haller
9d602529cc settings/trivial: comment why we create GDBusConnection for ifcfg D-Bus interface
There is nothing to fix. Replace the FIXME comment.
2019-12-09 08:59:29 +01:00
Beniamino Galvani
93e9010b75 device: don't transition assumed devices to FAILED before ACTIVATED
If the activation of an assumed device fails, we first set the device
state to FAILED and then to ACTIVATED. In the FAILED state, the active
connection transitions to DEACTIVATED and clears its device pointer;
hence we end up with an inconsistent state which causes assertion
failures in other parts of the code (for example, get_best_ip_config()
assumes that the device of the best active connection is not NULL).

Don't first transition to FAILED and then to ACTIVATED, just set the
latter.

https://bugzilla.redhat.com/show_bug.cgi?id=1737774
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/351
2019-12-05 17:09:53 +01:00
David Bauer
9a2bbbbc7a wifi/utils: complete key-mgmt=owe for OWE capable APs 2019-12-05 14:00:10 +01:00
David Bauer
235cb4a5d3 settings/ifcfg: add support for KEY_MGMT=OWE 2019-12-05 14:00:10 +01:00
David Bauer
1e55eff498 supplicant: add support for OWE key management 2019-12-05 14:00:10 +01:00
David Bauer
1bae844fac wifi/ap: expose OWE capability 2019-12-05 14:00:10 +01:00
Thomas Haller
d68373c305 initrd: don't use inet_aton() to parse IPv4 address
inet_aton() is very accepting when parsing the address. For example,
it accepts addresses with fewer octets (interpreting the last octet
as a number in network byte order for multiple bytes). It also ignores
any trailing garbage after the first delimiting whitespace (at least,
the glibc implementation). It also accepts octets in hex and octal
notation.

For the initrd reader we want to be more forgiving than inet_pton()
and also accept addresses like 255.000.000.000 (octal notation). For
that we would want to use inet_aton(). But we should not accept all the
craziness that inet_aton() otherwise accepts.

Use nm_utils_parse_inaddr_bin_full() instead. This function implements
our way how we want to interpret IP addresses in string representation.
Under the hood, of course it also uses inet_pton() and even inet_aton(),
but it is stricter than inet_aton() and only accepts certain formats.
2019-12-05 12:36:13 +01:00
Thomas Haller
9618f1bb4b initrd: fix out-of-bounds read when detecting address family in dt_get_ipaddr_property()
The @family argument is an input and output argument.

Initially, the family is set to AF_UNSPEC, in which case the family
gets detected based on the IP address. However, we call
dt_get_ipaddr_property() multiple times to parse the netmask, the
gateway and the IP address.

That means, after the first successfull call, the @family is set to
AF_INET or AF_INET6.

Note that the previous code (in the switch block) would only check that
the family is set to AF_UNSPEC, but it would not check that the @family
matches the expected binary address length @len. Later, we then might call
nm_ip_address_new_binary() with a family and a binary address of
unexpected length.

Also drop the error checking for nm_ip_address_new_binary().
nm_ip_address_new_binary() can only fail if the prefix length is larger
than 32/128. The function has no way to validate the input arguments
beyond that and can thus not fail (short of undefined behavior).
2019-12-05 12:36:13 +01:00
Thomas Haller
e7cf22be3e initrd: use cleanup attribute in nmi_dt_reader_parse() 2019-12-05 12:36:13 +01:00
Thomas Haller
321a323df4 initrd: fix use-after-free for variable "s_gateway" in nmi_dt_reader_parse() 2019-12-05 12:36:13 +01:00
Thomas Haller
15fb8fe26d settings/trivial: add fixme comment for creating GDBusConnection for ifcfg D-Bus interface
We really should just use the one and only main connection.
2019-12-05 12:27:13 +01:00
Thomas Haller
ea4e95ec33 initrd: generate IPv6 profiles with ipv6.addr-gen-mode=eui64
https://bugzilla.redhat.com/show_bug.cgi?id=1779389
2019-12-04 18:25:39 +01:00
Beniamino Galvani
b90f8e785e core: fix IAID endianness in client-id generation test
Fixes: 6f16e524be ('core: support ipvX.dhcp-iaid properties')

https://bugzilla.redhat.com/show_bug.cgi?id=1778640
2019-12-02 17:50:41 +01:00
Beniamino Galvani
4fcff3f34c core: remove 'legacy_unstable_byteorder' argument from client-id helpers
The argument has no effect because the order only influences IAID
generation.
2019-12-02 17:50:40 +01:00
Thomas Haller
f7e3cc0b71 platform/tests: skip team test when we fail to create team link
This is necessary on Travis/Ubuntu 16.04, otherwise the test
fails with

  # NetworkManager-MESSAGE: <warn>  [1575301791.7600] platform-linux: do-add-link[nm-test-device/team]: failure 95 (Operation not supported)
  Aborted (core dumped)
  # test:ERROR:../src/platform/tests/test-link.c:353:test_software: assertion failed: (software_add (link_type, DEVICE_NAME))
  ERROR: src/platform/tests/test-link-linux - too few tests run (expected 76, got 6)
2019-12-02 17:25:03 +01:00
Thomas Haller
390086a3cc build/meson: fix link failure of bluetooth's nm-bt-test
$ meson . build -D bluez5_dun=true -D selinux=false -D qt=false
2019-12-02 13:47:48 +01:00
Lubomir Rintel
9ba55ea6a6 modem-broadband: avoid a crash if we fail to guess an APN
Don't proceed if the context was torn down on an error in
try_create_connect_properties().

  <info>  [1574092292.0225] manager: NetworkManager state is now CONNECTING
  <warn>  [1574092292.0228] modem-broadband[ttyV0]: failed to connect 'ttyV0': unable to determine the network id
  <info>  [1574092292.0230] device (ttyV0): state change: prepare -> failed (reason 'modem-init-failed', sys-iface-state: 'managed')
  <info>  [1574092292.0236] manager: NetworkManager state is now DISCONNECTED
  <warn>  [1574092292.0250] device (ttyV0): Activation: failed for connection 'ttyV0'

  (NetworkManager:69212): libnm-CRITICAL **: 16:51:32.025: ((libnm-core/nm-connection.c:193)): assertion '<dropped>' failed

  Thread 1 "NetworkManager" received signal SIGTRAP, Trace/breakpoint trap.
  0x00007ffff78da6e5 in _g_log_abort () from /lib64/libglib-2.0.so.0
  (gdb) bt
  #0  0x00007ffff78da6e5 in _g_log_abort () at /lib64/libglib-2.0.so.0
  #1  0x00007ffff78db9b6 in g_logv () at /lib64/libglib-2.0.so.0
  #2  0x00007ffff78dbb83 in g_log () at /lib64/libglib-2.0.so.0
  #3  0x000055555563fcd2 in _nm_g_return_if_fail_warning (line=line@entry=193, file=0x5555557ae221 "libnm-core/nm-connection.c", log_domain=0x5555557ae23c "libnm") at ./shared/nm-default.h:219
  #4  0x000055555563feba in _connection_get_setting_checkPython Exception <class 'gdb.error'> No type named TypeNode.:
   (connection=0x0, setting_type=) at libnm-core/nm-connection.c:193
  #5  _connection_get_setting_checkPython Exception <class 'gdb.error'> No type named TypeNode.:
   (connection=0x0, setting_type=) at libnm-core/nm-connection.c:191
  #6  0x00007fffe871f8b4 in nm_modem_get_connection_ip_type (self=self@entry=0x7fffd801c730, connection=0x0, error=error@entry=0x7fffffffc8e8) at src/devices/wwan/nm-modem.c:374
  #7  0x00007fffe871bfed in connect_context_step (self=0x7fffd801c730) at src/devices/wwan/nm-modem-broadband.c:591
  #8  0x00007fffe871c74b in modem_act_stage1_prepare (_self=0x7fffd801c730, connection=0x555555af5520, out_failure_reason=<optimized out>) at src/devices/wwan/nm-modem-broadband.c:687
  #9  0x00007fffe8720203 in nm_modem_act_stage1_prepare (self=0x7fffd801c730, req=0x555555b08a30, out_failure_reason=0x7fffffffcbe0) at src/devices/wwan/nm-modem.c:1045
  #10 0x0000555555705f1b in activate_stage1_device_prepare (self=0x555555a956a0) at src/devices/nm-device.c:6562
  #11 0x00005555556dcbca in activation_source_handle_cb (self=0x555555a956a0, addr_family=2) at src/devices/nm-device.c:6177
  #12 0x00007ffff78d0dcb in g_idle_dispatch () at /lib64/libglib-2.0.so.0
  #13 0x00007ffff78d44a0 in g_main_context_dispatch () at /lib64/libglib-2.0.so.0
  #14 0x00007ffff78d4830 in g_main_context_iterate.isra () at /lib64/libglib-2.0.so.0
  #15 0x00007ffff78d4b23 in g_main_loop_run () at /lib64/libglib-2.0.so.0
  #16 0x0000555555599ff4 in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:451

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/338/
2019-12-02 02:32:18 +01:00
Thomas Haller
40012e2aa8 shared: move log level info from core to "nm-logging-base.h"
We have our NM specific logging and log levels. Maybe we should
not have that, and instead only rely on syslog (like systemd)
or glog(). Anyway, currently we have one way and it makes sense
that this is also used outside from "src".

Move the helper function to parse log levels from string to
"nm-logging-base.h" so that we can use the same logging levels
outside of core.

This moves code that is currently GPL2+ licensed to
LGPL2.1+. However as far as I see, this code was entirely written
by Red Hat employees who would not object with this change. Also,
it's as obvious and trivial as it gets.
2019-11-28 19:20:33 +01:00
Beniamino Galvani
aa8d5a3e9e dhcp: support FQDN flags in the nettools backend
Make the nettools backed honor the ipv4.dhcp-hostname-flags property.
2019-11-28 17:56:35 +01:00
Beniamino Galvani
316ff68bfa dhcp: support FQDN flags in the dhclient backend
Make the dhclient backend honor the ipv4.dhcp-fqdn-flags setting.
2019-11-28 17:56:35 +01:00
Beniamino Galvani
292d3f2b57 ifcfg-rh: add support for DHCP hostname flags 2019-11-28 17:56:35 +01:00
Thomas Haller
b9f1beb06e all: add support for "scope" attribute for IPv4 routes
- systemd-networkd and initscripts both support it.

- it seems suggested to configure routes with scope "link" on AWS.

- the scope is only supported for IPv4 routes. Kernel ignores the
  attribute for IPv6 routes.

- we don't support the aliases like "link" or "global". Instead
  only the numeric value is supported. This is different from
  systemd-networkd, which accepts names like "global" and "link",
  but no numerical values. I think restricting ourself only to
  the aliases unnecessarily limits what is possible on netlink.
  The alternative would be to allow aliases and numbers both,
  but that causes multiple ways to define something and has
  thus downsides. So, only numeric values.

- when setting rtm_scope to RT_SCOPE_NOWHERE (0, the default), kernel
  will coerce that to RT_SCOPE_LINK. This ambiguity of nowhere vs. link
  is a problem, but we don't do anything about it.

- The other problem is, that when deleting a route with scope RT_SCOPE_NOWHERE,
  this acts as a wild care and removes the first route that matches (given the
  other route attributes). That means, NetworkManager has no meaningful
  way to delete a route with scope zero, there is always the danger that
  we might delete the wrong route. But this is nothing new to this
  patch. The problem existed already previously, except that
  NetworkManager could only add routes with scope nowhere (i.e. link).
2019-11-28 00:11:15 +01:00
Thomas Haller
b8c0078008 ifcfg-rh: separately handle static information during parsing ip-route commandline
There is an "info" part and a part with the data that we parsed.
Don't track the static and mutable data in the same variable.

Also, this allows to mark the static part as "const static".
2019-11-27 16:06:00 +01:00
Thomas Haller
e7816a2508 ifcfg-rh: fix accepting onlink flag also for IPv6 routes
In the past, kernel (and NetworkManager) did not support the onlink
flags for IPv6 routes. That is no longer the case.

Fixes: f5e8bbc8e0 ('libnm,core: enable "onlink" flags also for IPv6 routes')
2019-11-27 16:06:00 +01:00
Thomas Haller
d0f385ce34 sd: cleanup integrating systemd's event loop with GMainContext
Get rid of the default_source_id global for tracking the default
event. It's not useful to track this.
2019-11-25 12:58:33 +01:00
Beniamino Galvani
a73efb059f manager: don't activate device if the parent is missing
In multiple places we currently proceed to creating a virtual device
even if the connection specifies a parent device which is
missing. This can be easily reproduced with:

  nmcli con add type vxlan ifname vxlan1 \
                vxlan.parent not-exists \
                id 43 remote 172.25.1.1

which creates a vxlan1 interface without activating any
connection. Add a check to prevent this.

https://bugzilla.redhat.com/show_bug.cgi?id=1774074
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/344
2019-11-25 08:58:27 +01:00
Thomas Haller
d3c7083f97 dhcp: switch IPv4 "internal" DHCP client to use "nettools" backend instead of "systemd"
Previously, our "internal" DHCPv4 client is based on a fork of
systemd code. This manner of maintaining the fork is problematic.
The solution is to use a proper library: n-dhcp4 from the nettools
project.

We already have these two as undocumented plugins available, by
setting either "dhcp=systemd" or "dhcp=nettools". This is only for
testing. Users are only supposed to use the "internal" plugin.

Up until now, the "internal" DHCPv4 plugin was based on "systemd" code.
Change that to use "nettools" instead.

Possibly this breaks something, and we need to fix it. But do this
early so we have time to test the nettools plugin and identify issues.

For the user, this change should be entirely transparant.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/302
2019-11-23 09:21:55 +01:00
Beniamino Galvani
ccfc3370af iface-helper: accept new DHCP4 leases
The new lease must be accepted or the nettools client will not renew
it.
2019-11-23 09:14:14 +01:00
Thomas Haller
033c2b82c2 core: move _LOG*() macros to "shared/nm-glib-aux/nm-logging-fwd.h"
We preferably should use our convenience macros like _LOGD().
Since those macros expand to _NMLOG() (which needs to be defined
separately), we can move it to "nm-logging-fwd.h" and reuse.
2019-11-22 15:32:52 +01:00
Thomas Haller
c24f122e22 connectivity: fix using curl_multi_strerror() for CURLMcode error code 2019-11-22 15:32:52 +01:00
Thomas Haller
0871c9533f connectivity: don't use the GIOChannel but poll the file descriptor directly
I guess, if you write portable applications, then GIOChannel makes a lot of sense.
But we know that this is on Linux. We don't need to pretend that we
cannot poll on the file descriptor directly.
2019-11-22 15:32:52 +01:00
Thomas Haller
05c31da4d9 connectivity: don't cancel curl timerfunction from timeout
Curl documents about CURLMOPT_TIMERFUNCTION:

  The timer_callback will only be called when the timeout expire time is
  changed.

That means, we should not cancel the timeout when it happend, but
only when the callback is called again (or during cleanup).

See-also: https://curl.haxx.se/libcurl/c/CURLMOPT_TIMERFUNCTION.html
2019-11-22 15:32:52 +01:00