803fb7
From 0fa424a08a31af512a698b60b497cfc0cf0554e0 Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Mon, 25 Jan 2016 17:16:27 +0100
803fb7
Subject: [PATCH] udev: filter out non-sensically high onboard indexes reported
803fb7
 by the kernel
803fb7
803fb7
Let's not accept onboard interface indexes, that are so high that they are obviously non-sensical.
803fb7
803fb7
Fixes: #2407
803fb7
803fb7
Cherry-picked from: 6c1e69f9456d022f14dd00737126cfa4d9cca10
803fb7
Resolves: #1230210
803fb7
---
803fb7
 src/udev/udev-builtin-net_id.c | 9 +++++++++
803fb7
 1 file changed, 9 insertions(+)
803fb7
803fb7
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
803fb7
index ffd6ea416..19e1f2631 100644
803fb7
--- a/src/udev/udev-builtin-net_id.c
803fb7
+++ b/src/udev/udev-builtin-net_id.c
803fb7
@@ -101,6 +101,8 @@
803fb7
 #include "udev.h"
803fb7
 #include "fileio.h"
803fb7
 
803fb7
+#define ONBOARD_INDEX_MAX (16*1024-1)
803fb7
+
803fb7
 enum netname_type{
803fb7
         NET_UNDEF,
803fb7
         NET_PCI,
803fb7
@@ -147,6 +149,13 @@ static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
803fb7
         if (idx <= 0)
803fb7
                 return -EINVAL;
803fb7
 
803fb7
+        /* Some BIOSes report rubbish indexes that are excessively high (2^24-1 is an index VMware likes to report for
803fb7
+         * example). Let's define a cut-off where we don't consider the index reliable anymore. We pick some arbitrary
803fb7
+         * cut-off, which is somewhere beyond the realistic number of physical network interface a system might
803fb7
+         * have. Ideally the kernel would already filter his crap for us, but it doesn't currently. */
803fb7
+        if (idx > ONBOARD_INDEX_MAX)
803fb7
+                return -ENOENT;
803fb7
+
803fb7
         /* kernel provided port index for multiple ports on a single PCI function */
803fb7
         attr = udev_device_get_sysattr_value(dev, "dev_port");
803fb7
         if (attr)