teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0216-udev-net_id-Only-read-the-first-64-bytes-of-PCI-conf.patch

923a60
From 210ec6353d3cab2029e1eb160671fea918c97814 Mon Sep 17 00:00:00 2001
923a60
From: "Jason S. McMullan" <jason.mcmullan@gmail.com>
923a60
Date: Fri, 22 May 2015 20:30:01 +0200
923a60
Subject: [PATCH] udev/net_id: Only read the first 64 bytes of PCI config space
923a60
923a60
The original code used fread(), which on some libc implementions
923a60
(ie glibc 2.17) would pre-read a full 4K (PAGE_SIZE) of the
923a60
PCI config space, when only 64 bytes were requested.
923a60
923a60
I have recently come across PCIe hardware which responds with
923a60
Completion Timeouts when accesses above 256 bytes are attempted.
923a60
923a60
This can cause server systems with GHES/AEPI support to cause
923a60
and immediate kernel panic due to the failed PCI transaction.
923a60
923a60
This change replaces the buffered fread() with an explict
923a60
unbuffered read() of 64 bytes, which corrects this issue by
923a60
only reading the guaranteed first 64 bytes of PCIe config space.
923a60
923a60
(cherry picked from commit 0454229c100a2113ba82df55703436d6cb2c492b)
923a60
923a60
Cherry-picked from: 0454229
923a60
Resolves: #1222517
923a60
---
923a60
 src/udev/udev-builtin-net_id.c | 9 +++++----
923a60
 1 file changed, 5 insertions(+), 4 deletions(-)
923a60
923a60
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
923a60
index 66474f7728..dd2886caf2 100644
923a60
--- a/src/udev/udev-builtin-net_id.c
923a60
+++ b/src/udev/udev-builtin-net_id.c
923a60
@@ -91,6 +91,7 @@
923a60
 #include <stdlib.h>
923a60
 #include <stdarg.h>
923a60
 #include <unistd.h>
923a60
+#include <fcntl.h>
923a60
 #include <string.h>
923a60
 #include <errno.h>
923a60
 #include <net/if.h>
923a60
@@ -166,15 +167,15 @@ static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
923a60
 
923a60
 /* read the 256 bytes PCI configuration space to check the multi-function bit */
923a60
 static bool is_pci_multifunction(struct udev_device *dev) {
923a60
-        _cleanup_fclose_ FILE *f = NULL;
923a60
+        _cleanup_close_ int fd = -1;
923a60
         const char *filename;
923a60
         uint8_t config[64];
923a60
 
923a60
         filename = strjoina(udev_device_get_syspath(dev), "/config");
923a60
-        f = fopen(filename, "re");
923a60
-        if (!f)
923a60
+        fd = open(filename, O_RDONLY | O_CLOEXEC);
923a60
+        if (fd < 0)
923a60
                 return false;
923a60
-        if (fread(&config, sizeof(config), 1, f) != 1)
923a60
+        if (read(fd, &config, sizeof(config)) != sizeof(config))
923a60
                 return false;
923a60
 
923a60
         /* bit 0-6 header type, bit 7 multi/single function device */