vlib: allow unpriviledged vlib_pci_get_device_info() 70/39670/2
authorDamjan Marion <damarion@cisco.com>
Thu, 12 Oct 2023 17:41:14 +0000 (17:41 +0000)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Fri, 13 Oct 2023 10:39:10 +0000 (10:39 +0000)
When running unpriviledged sysfs allows reading only first
64 bytes of PCI config space.

Change-Id: I62d18328925a2e4936406c2842154b20182cacb9
Type: improvement
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vlib/linux/pci.c
src/vlib/pci/pci_config.h

index 9661827..1a70c56 100644 (file)
@@ -238,7 +238,8 @@ vlib_pci_get_device_info (vlib_main_t * vm, vlib_pci_addr_t * addr,
 
   /* You can only read more that 64 bytes of config space as root; so we try to
      read the full space but fall back to just the first 64 bytes. */
-  if (read (fd, &di->config, sizeof (di->config)) < sizeof (di->config))
+  if (read (fd, &di->config, sizeof (di->config)) <
+      sizeof (vlib_pci_config_hdr_t))
     {
       err = clib_error_return_unix (0, "read `%s'", f);
       close (fd);
index 3501bde..21b40c0 100644 (file)
@@ -247,9 +247,9 @@ typedef struct
 #define _(a, b, ...) a b __VA_ARGS__;
   foreach_pci_config_reg
 #undef _
-} vlib_pci_config_mandatory_t;
+} vlib_pci_config_hdr_t;
 
-STATIC_ASSERT_SIZEOF (vlib_pci_config_mandatory_t, 64);
+STATIC_ASSERT_SIZEOF (vlib_pci_config_hdr_t, 64);
 
 typedef union
 {