Skip to contentSkip to conversation

xf86drm: ensure proper alignment of pointers in drmProcessPciDevice

PATCH In review Nicolai Hähnle 2 participants 6 messages May 13, 2016 – Jun 10, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xf86drm: ensure proper alignment of pointers in drmProcessPciDevice

From: Nicolai Hähnle <[email protected]>

Previously, (*device)->businfo.pci would end up misaligned, which results in undefined behavior.

---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +1 -1
index 5f587d9..94efc08 100644
@@ -3000,7 +3000,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
                                const char *node, int node_type,
                                int maj, int min, bool fetch_deviceinfo)
 {
-    const int max_node_str = drmGetMaxNodeName();
+    const int max_node_str = ALIGN(drmGetMaxNodeName(), sizeof(void *));
     int ret, i;
     char *addr;
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi Nicolai,

Quoted 5 lines · Nicolai Hähnle

From: Nicolai Hähnle <[email protected]>

Previously, (*device)->businfo.pci would end up misaligned, which results in undefined behavior.

Can you point me to a source where I can read more on the topic ? I'm pretty sure I ran this through valgrind and it gave a clear bill of health.

Thanks
Emil
P.S. Please run the following in your repo $git config --local format.subjectPrefix "PATCH libdrm"
_______________________________________________
dri-devel mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Hi Emil,

Quoted 10 lines · Emil Velikov

Hi Nicolai,

Quoted 5 lines · Nicolai Hähnle

From: Nicolai Hähnle <[email protected]>

Previously, (*device)->businfo.pci would end up misaligned, which results in undefined behavior.

Can you point me to a source where I can read more on the topic ? I'm pretty sure I ran this through valgrind and it gave a clear bill of health.

Valgrind doesn't complain here either, I noticed it with -fsanitize=undefined (ubsan) applied to Mesa.

That makes sense, since unaligned loads/stores aren't really a bug as far as the x86 ISA is concerned, which is the level at which valgrind looks at the code. On the other hand, apparently already an unaligned cast (not just the dereference!) is undefined behavior as far as C is concerned. I'm not a C language lawyer, but that's what people are saying on the interwebs, so it must be true :)

Quoted 2 lines

P.S. Please run the following in your repo $git config --local format.subjectPrefix "PATCH libdrm"

Done.

Cheers,
Nicolai
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to Nicolai Hähnle

Ping.

Quoted 16 lines · Nicolai Hähnle

From: Nicolai Hähnle <[email protected]>

Previously, (*device)->businfo.pci would end up misaligned, which results in undefined behavior.

---
  xf86drm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
xf86drm.c +0 -0
index 5f587d9..94efc08 100644

xf86drm.c static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name, · line 3006

Quoted 8 lines
xf86drm.c +1 -1
@@ -3000,7 +3000,7 @@ static int drmProcessPciDevice(drmDevicePtr *device, const char *d_name,
                                 const char *node, int node_type,
                                 int maj, int min, bool fetch_deviceinfo)
  {
-    const int max_node_str = drmGetMaxNodeName();
+    const int max_node_str = ALIGN(drmGetMaxNodeName(), sizeof(void *));
      int ret, i;
      char *addr;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 7 lines · Emil Velikov
Quoted 2 lines · Nicolai Hähnle

Ping.

Sorry about that, I thought I've already mentioned it:

I take it you have commit access ? If not, let me know and I'll push if for you.

Thanks, I just pushed it.

Cheers,
Nicolai

Quoted 2 lines

Emil

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel