After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760907 - fix handling of invalid connections in libnm/libnm-glib
fix handling of invalid connections in libnm/libnm-glib
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: Thomas Haller
NetworkManager maintainer(s)
Depends on:
Blocks: nm-1-2 763528
 
 
Reported: 2016-01-20 22:04 UTC by Thomas Haller
Modified: 2016-03-29 10:00 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Thomas Haller 2016-01-20 22:04:08 UTC
NetworkManager will never send a connection to the client that doesn't verify (according to the libnm-core version of NM).

However, if the client uses a different version of libnm or libnm-glib, the connection can easily become invalid at the client side.

e.g. master's libnm added support to NMSettingTun, but this new connection type was not backported to libnm-util. Thus, every tun connection will be invalid (even in an up-to-date libnm-glib client).



Connections that don't validate in the client is something that is unavoidable. The question is how the library should handle them.



One problem is, that all kind of connection related functions in libnm assert/assume valid connections. E.g. they expect at least a NMSettingConnection member. So, exposing invalid connections to the client might be problematic.



I added unit-test to investigate how libnm/libn-glib behaves: http://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=92f122525dab49fece51b6b6bda99c762507f7c9

See the commit message. This needs fixing.
Comment 1 Thomas Haller 2016-03-15 17:24:48 UTC
One problem is that older libnm-glib will assert against invalid connections: https://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=8c27a370ff70430225bd6a2408e32e332f872f2e

So, when upgrading NetworkManager, you can easily hit an assertion.
But that was really a bug in libnm-glib and not much we can do about it.

Note, that usually you'd also upgrade libnm-glib and don't hit any problem. But it's still ugly that older libnm-glib version will not work with newer NM.
Comment 2 Thomas Haller 2016-03-18 19:00:16 UTC
this rabbit hole turns out to run deep.

First patches at th/invalid-connections-bgo760907
Comment 3 Thomas Haller 2016-03-23 15:34:27 UTC
(In reply to Thomas Haller from comment #2)
> this rabbit hole turns out to run deep.
> 
> First patches at th/invalid-connections-bgo760907

ok, th/invalid-connections-bgo760907 gets it now right for libnm and NetworkManager core. 

Some of the later patches are potentially change in behavior that breaks existing applications. Please review.

libnm-util/libnm-glib is still todo...
Comment 4 Dan Williams 2016-03-23 16:17:49 UTC
> libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()

I would say by default parsing is strict, and the flags relax the behavior, rather than have two flags.  I don't think we need an explicit STRICT flag.

> libnm-core: add _nm_simple_connection_new_from_dbus() function

It doesn't seem like anything uses PARSE_FLAGS_VERIFY, so let's drop it until something needs it?

> libnm: don't normalize connection for nm_device_get_applied_connection()

The API docs should be updated to indicate that the returned connection may not actually validate if libnm is older than the NM version.

> libnm: be more accepting for invalid connections from NetworkManager

Same here; relevant API docs (for nm_client_get_connections() and the NMRemoteConnection docs) should be updated to indicate that the connection may not verify if the libnm version is older than the NM version, and what a user might need to do about that.

> core: be more relaxed parsing connection in AddAndActivateConnection

Here I think we are OK with incomplete connections (since they will be filled in by NM) but we *do* want to reject badly formatted ones with stuff like:

1) invalid/unknown permissions types (eg we want to call validate_permissions_type())
2) we want to reject unknown setting types
3) we want to reject duplicate settings

and ideally reject these things earlier rather than later.  But none of those happen with BEST_EFFORT; there are some classes of errors that aren't acceptable here.
Comment 5 Thomas Haller 2016-03-23 16:47:08 UTC
(In reply to Dan Williams from comment #4)
> > libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()
> 
> I would say by default parsing is strict, and the flags relax the behavior,
> rather than have two flags.  I don't think we need an explicit STRICT flag.

The old behavior was a mixture of strict and best-behavior. To preserve the old behavior, a third way is needed.

Note that for example nm_simple_connection_new_from_dbus() and nm_connection_replace_settings() which are public API do not change behavior in this branch (apart from no longer printing a g_warning()).

The intent at this point is not to improve the public API (which would be a follow-up task).


Once all callers strictly use STRICT or BEST_EFFORT, those two flags can be merged.


> > libnm-core: add _nm_simple_connection_new_from_dbus() function
> 
> It doesn't seem like anything uses PARSE_FLAGS_VERIFY, so let's drop it
> until something needs it?

Ok.



> > libnm: don't normalize connection for nm_device_get_applied_connection()
> 
> The API docs should be updated to indicate that the returned connection may
> not actually validate if libnm is older than the NM version.
>
> > libnm: be more accepting for invalid connections from NetworkManager
> 
> Same here; relevant API docs (for nm_client_get_connections() and the
> NMRemoteConnection docs) should be updated to indicate that the connection
> may not verify if the libnm version is older than the NM version, and what a
> user might need to do about that.

Note that already before this branch, nm_client_get_connections() will happily return invalid connections. That doesn't change.

(ok, it changed for nm_device_get_applied_connection(), which would try to normalize the connection. But that is new API and now only behaves like the others). 


Anyway, new commit:
  "libnm: add code comments to hint that NMConnection might not validate"



> > core: be more relaxed parsing connection in AddAndActivateConnection
> 
> Here I think we are OK with incomplete connections (since they will be
> filled in by NM) but we *do* want to reject badly formatted ones with stuff
> like:
> 
> 1) invalid/unknown permissions types (eg we want to call
> validate_permissions_type())
> 2) we want to reject unknown setting types
> 3) we want to reject duplicate settings
> 
> and ideally reject these things earlier rather than later.  But none of
> those happen with BEST_EFFORT; there are some classes of errors that aren't
> acceptable here.

Which is exactly what STRICT does. Changed, and updated code comment.



Repushed.
Comment 6 Beniamino Galvani 2016-03-24 15:32:06 UTC
> libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()

+               setting = _nm_setting_new_from_dbus (type, setting_dict, new_settings, NM_SETTING_PARSE_FLAGS_NONE, &local);

		if (!setting) {
+                       if (NM_FLAGS_HAS (parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT))
+                               continue;
+                       g_propagate_error (error, local);
			g_slist_free_full (settings, g_object_unref);
			return FALSE;
		}

Since all paths returning NULL in _nm_setting_new_from_dbus() check
now for flags, maybe we can pass @parse_flags instead of FLAGS_NONE
and remove the 'if (NM_FLAGS_HAS (parse_flags, BEST_EFFORT)' below?

> core: be more strict when parsing connection in AddAndActivateConnection
> core: be strict about connection argument in D-Bus methods

As the commit messages say these potentially break applications, in my
opinion we should not do it.
Comment 7 Thomas Haller 2016-03-24 16:59:44 UTC
(In reply to Beniamino Galvani from comment #6)
> > libnm-core: allow strict and relaxed error behavior for _nm_setting_new_from_dbus()
> 
> +               setting = _nm_setting_new_from_dbus (type, setting_dict,
> new_settings, NM_SETTING_PARSE_FLAGS_NONE, &local);
> 
> 		if (!setting) {
> +                       if (NM_FLAGS_HAS (parse_flags,
> NM_SETTING_PARSE_FLAGS_BEST_EFFORT))
> +                               continue;
> +                       g_propagate_error (error, local);
> 			g_slist_free_full (settings, g_object_unref);
> 			return FALSE;
> 		}
> 
> Since all paths returning NULL in _nm_setting_new_from_dbus() check
> now for flags, maybe we can pass @parse_flags instead of FLAGS_NONE
> and remove the 'if (NM_FLAGS_HAS (parse_flags, BEST_EFFORT)' below?

Good catch. Of course, we must pass @parse_flags and not NONE.

And you are right, that indeed settings will not be NULL when parse_flags are BEST_EFFORT. But I'd prefer to keep this extra "if" because otherwise we make assumptions on _nm_setting_new_from_dbus that are not obviously true.

How about the fixup?


> > core: be more strict when parsing connection in AddAndActivateConnection
> > core: be strict about connection argument in D-Bus methods
> 
> As the commit messages say these potentially break applications, in my
> opinion we should not do it.

Maybe, we might now reject messages that were accepted previously. But note, that these messages were always invalid, so... maybe we can change behavior in this regard?
@dcbw, what do you think?


Repushed.
Comment 8 Beniamino Galvani 2016-03-24 20:40:57 UTC
(In reply to Thomas Haller from comment #7)

> How about the fixup?

Looks right.
Comment 9 Thomas Haller 2016-03-26 13:05:26 UTC
Pushed more patches, now also adding relaxed behavior to libnm-glib.

This would be it...
Comment 10 Beniamino Galvani 2016-03-29 09:41:11 UTC
New patches look good to me.

Regarding the strict validation of connections, I think this is
something that should eventually be done, because ignoring unknown
properties can be dangerous. For example, we recently introduced the
8021x.domain-suffix-match property, NM versions that don't understand
it should not accept connections with that property, otherwise they
will allow connection to insecure authenticators.
Comment 11 Thomas Haller 2016-03-29 09:54:53 UTC
(In reply to Beniamino Galvani from comment #10)
> New patches look good to me.
> 
> Regarding the strict validation of connections, I think this is
> something that should eventually be done, because ignoring unknown
> properties can be dangerous. For example, we recently introduced the
> 8021x.domain-suffix-match property, NM versions that don't understand
> it should not accept connections with that property, otherwise they
> will allow connection to insecure authenticators.

I agree. 

Note that we want to support older clients against newer server version -- not the other way around.
So using a newer library version that supports 8021x.domain-suffix-match is strictly speaking not supported anyway -- of course, we should try to make do as much as possible, and being strict about unknown properties is also right in this case.