daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From f50fbeaf7c2ce57027f774d02d9e2b09f810ec2a Mon Sep 17 00:00:00 2001
923a60
From: Tom Gundersen <teg@jklm.no>
923a60
Date: Thu, 21 May 2015 15:22:07 +0200
923a60
Subject: [PATCH] udev: link-config - fix corruption
923a60
923a60
The parser used for MTU and Speed expects them to be size_t, not unsigned int.
923a60
923a60
This caused a corruption in the rest of the structure.
923a60
923a60
Reported by David O Neill <david.m.oneill@intel.com>.
923a60
923a60
(cherry picked from commit dab495dc23bf9a5ba0487a057bb594355555a0e9)
923a60
923a60
Cherry-picked from: dab495d
923a60
Resolves: #1222517
923a60
---
923a60
 src/udev/net/link-config.c | 11 ++++++-----
923a60
 src/udev/net/link-config.h |  4 ++--
923a60
 2 files changed, 8 insertions(+), 7 deletions(-)
923a60
923a60
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
923a60
index 8b3dc45d4e..489593f4fd 100644
923a60
--- a/src/udev/net/link-config.c
923a60
+++ b/src/udev/net/link-config.c
923a60
@@ -177,6 +177,9 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
923a60
         else
923a60
                 log_debug("Parsed configuration file %s", filename);
923a60
 
923a60
+        if (link->mtu > UINT_MAX || link->speed > UINT_MAX)
923a60
+                return -ERANGE;
923a60
+
923a60
         link->filename = strdup(filename);
923a60
 
923a60
         LIST_PREPEND(links, ctx->links, link);
923a60
@@ -379,10 +382,9 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
923a60
         if (!old_name)
923a60
                 return -EINVAL;
923a60
 
923a60
-        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024,
923a60
-                              config->duplex);
923a60
+        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024, config->duplex);
923a60
         if (r < 0)
923a60
-                log_warning_errno(r, "Could not set speed or duplex of %s to %u Mbps (%s): %m",
923a60
+                log_warning_errno(r, "Could not set speed or duplex of %s to %zu Mbps (%s): %m",
923a60
                                   old_name, config->speed / 1024,
923a60
                                   duplex_to_string(config->duplex));
923a60
 
923a60
@@ -461,8 +463,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
923a60
                         mac = config->mac;
923a60
         }
923a60
 
923a60
-        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac,
923a60
-                                     config->mtu);
923a60
+        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac, config->mtu);
923a60
         if (r < 0)
923a60
                 return log_warning_errno(r, "Could not set Alias, MACAddress or MTU on %s: %m", old_name);
923a60
 
923a60
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
923a60
index cb434d1aee..f2e9174887 100644
923a60
--- a/src/udev/net/link-config.h
923a60
+++ b/src/udev/net/link-config.h
923a60
@@ -67,8 +67,8 @@ struct link_config {
923a60
         NamePolicy *name_policy;
923a60
         char *name;
923a60
         char *alias;
923a60
-        unsigned int mtu;
923a60
-        unsigned int speed;
923a60
+        size_t mtu;
923a60
+        size_t speed;
923a60
         Duplex duplex;
923a60
         WakeOnLan wol;
923a60