device: avoid touching sysctls for devices without platform link

Since 32b3eb1181 [core: merge IPv4 and IPv6 implementation of
nm_utils_ip4_property_path()], nm_utils_sysctl_ip_conf_path() introduced
in cd271d5cb1 [core: add nm_utils_sysctl_ip_conf_is_path() util] is used to
cunstruct sysctl paths and it is way less tolerant towards using something
that is not an interface name in the path.

It's always been incorrect to assume the ifname is a linux link name and
it resulted it ugly, if benign, sysctl access attempts such as
"/sys/class/net/28:B2:BD:5D:23:AB/phys_port_id" etc.

Now it triggers an assertion failure. Let's guard all such accesses.

Fixes: 32b3eb1181
Fixes: cd271d5cb1
This commit is contained in:
Lubomir Rintel 2017-10-31 18:22:37 +01:00
parent 5f97430e21
commit bc83bec253

View file

@ -856,6 +856,9 @@ nm_device_ipv4_sysctl_set (NMDevice *self, const char *property, const char *val
const char *value_to_set;
char buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
if (!nm_device_get_ip_ifindex (self))
return FALSE;
if (value) {
value_to_set = value;
} else {
@ -875,6 +878,9 @@ nm_device_ipv4_sysctl_get_uint32 (NMDevice *self, const char *property, guint32
{
char buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
if (!nm_device_get_ip_ifindex (self))
return fallback;
return nm_platform_sysctl_get_int_checked (nm_device_get_platform (self),
NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_sysctl_ip_conf_path (AF_INET, buf, nm_device_get_ip_iface (self), property)),
10,
@ -888,6 +894,9 @@ nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *val
{
char buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
if (!nm_device_get_ip_ifindex (self))
return FALSE;
return nm_platform_sysctl_set (nm_device_get_platform (self), NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_sysctl_ip_conf_path (AF_INET6, buf, nm_device_get_ip_iface (self), property)), value);
}
@ -896,6 +905,9 @@ nm_device_ipv6_sysctl_get_uint32 (NMDevice *self, const char *property, guint32
{
char buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
if (!nm_device_get_ip_ifindex (self))
return fallback;
return nm_platform_sysctl_get_int_checked (nm_device_get_platform (self),
NMP_SYSCTL_PATHID_ABSOLUTE (nm_utils_sysctl_ip_conf_path (AF_INET6, buf, nm_device_get_ip_iface (self), property)),
10,
@ -7735,6 +7747,9 @@ save_ip6_properties (NMDevice *self)
g_hash_table_remove_all (priv->ip6_saved_properties);
if (!nm_device_get_ip_ifindex (self))
return;
for (i = 0; i < G_N_ELEMENTS (ip6_properties_to_save); i++) {
char buf[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
@ -7863,6 +7878,9 @@ _ip6_privacy_get (NMDevice *self)
if (ip6_privacy != NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN)
return ip6_privacy;
if (!nm_device_get_ip_ifindex (self))
return NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;;
/* 3.) No valid default-value configured. Fallback to reading sysctl.
*
* Instead of reading static config files in /etc, just read the current sysctl value.
@ -8402,6 +8420,8 @@ start_sharing (NMDevice *self, NMIP4Config *config)
g_return_val_if_fail (config != NULL, FALSE);
ip_iface = nm_device_get_ip_iface (self);
if (!ip_iface)
return FALSE;
ip4_addr = nm_ip4_config_get_first_address (config);
if (!ip4_addr || !ip4_addr->address)
@ -8670,6 +8690,8 @@ activate_stage5_ip6_config_commit (NMDevice *self)
/* Interface must be IFF_UP before IP config can be applied */
ip_ifindex = nm_device_get_ip_ifindex (self);
g_return_if_fail (ip_ifindex);
if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex) && !nm_device_sys_iface_state_is_external_or_assume (self)) {
nm_platform_link_set_up (nm_device_get_platform (self), ip_ifindex, NULL);
if (!nm_platform_link_is_up (nm_device_get_platform (self), ip_ifindex))