daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From f50fbeaf7c2ce57027f774d02d9e2b09f810ec2a Mon Sep 17 00:00:00 2001
From: Tom Gundersen <teg@jklm.no>
Date: Thu, 21 May 2015 15:22:07 +0200
Subject: [PATCH] udev: link-config - fix corruption

The parser used for MTU and Speed expects them to be size_t, not unsigned int.

This caused a corruption in the rest of the structure.

Reported by David O Neill <david.m.oneill@intel.com>.

(cherry picked from commit dab495dc23bf9a5ba0487a057bb594355555a0e9)

Cherry-picked from: dab495d
Resolves: #1222517
---
 src/udev/net/link-config.c | 11 ++++++-----
 src/udev/net/link-config.h |  4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index 8b3dc45d4e..489593f4fd 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -177,6 +177,9 @@ static int load_link(link_config_ctx *ctx, const char *filename) {
         else
                 log_debug("Parsed configuration file %s", filename);
 
+        if (link->mtu > UINT_MAX || link->speed > UINT_MAX)
+                return -ERANGE;
+
         link->filename = strdup(filename);
 
         LIST_PREPEND(links, ctx->links, link);
@@ -379,10 +382,9 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
         if (!old_name)
                 return -EINVAL;
 
-        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024,
-                              config->duplex);
+        r = ethtool_set_speed(&ctx->ethtool_fd, old_name, config->speed / 1024, config->duplex);
         if (r < 0)
-                log_warning_errno(r, "Could not set speed or duplex of %s to %u Mbps (%s): %m",
+                log_warning_errno(r, "Could not set speed or duplex of %s to %zu Mbps (%s): %m",
                                   old_name, config->speed / 1024,
                                   duplex_to_string(config->duplex));
 
@@ -461,8 +463,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
                         mac = config->mac;
         }
 
-        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac,
-                                     config->mtu);
+        r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac, config->mtu);
         if (r < 0)
                 return log_warning_errno(r, "Could not set Alias, MACAddress or MTU on %s: %m", old_name);
 
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
index cb434d1aee..f2e9174887 100644
--- a/src/udev/net/link-config.h
+++ b/src/udev/net/link-config.h
@@ -67,8 +67,8 @@ struct link_config {
         NamePolicy *name_policy;
         char *name;
         char *alias;
-        unsigned int mtu;
-        unsigned int speed;
+        size_t mtu;
+        size_t speed;
         Duplex duplex;
         WakeOnLan wol;