]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsfd: avoid undefined behavior
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 19 Nov 2023 16:21:25 +0000 (17:21 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 30 Nov 2023 09:35:00 +0000 (10:35 +0100)
commit192d8aaa07e088e44fcb78736a53baae1ead7ccd
treeba6b20b1892ed81a38e42f788bd26275566bd73a
parent756588f8c8b2ed93c124ca15cfb3f0efc4a0f9f6
lsfd: avoid undefined behavior

Passing a pointer to a different datatype to tfind() then were inserted
evokes undefines behavior.
This triggers UBSAN as shown below.

Instead pass the proper structs.

```
../misc-utils/lsfd.c:513:27: runtime error: member access within misaligned address 0x7ffe9ee6495c for type 'struct proc', which requires 8 byte alignment
0x7ffe9ee6495c: note: pointer points here
  1a 1a 1a 1a 01 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  d0 49 e6 9e fe 7f 00 00
              ^
    #0 0x56159cfa4a3b in proc_tree_compare ../misc-utils/lsfd.c:513
    #1 0x7f9dd4d2d743 in __tfind (/usr/lib/libc.so.6+0x10f743) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658)
    #2 0x56159cfa4ac3 in get_proc ../misc-utils/lsfd.c:518
    #3 0x56159cfe217b in anon_pidfd_get_name ../misc-utils/lsfd-unkn.c:203
    #4 0x56159cfe1040 in unkn_fill_column ../misc-utils/lsfd-unkn.c:93
    #5 0x56159cfaaa37 in fill_column ../misc-utils/lsfd.c:1178
    #6 0x56159cfaaac5 in convert_file ../misc-utils/lsfd.c:1193
    #7 0x56159cfaac4f in convert ../misc-utils/lsfd.c:1212
    #8 0x56159cfb2b54 in main ../misc-utils/lsfd.c:2317
    #9 0x7f9dd4c45ccf  (/usr/lib/libc.so.6+0x27ccf) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658)
    #10 0x7f9dd4c45d89 in __libc_start_main (/usr/lib/libc.so.6+0x27d89) (BuildId: 8bfe03f6bf9b6a6e2591babd0bbc266837d8f658)
    #11 0x56159cfa3c34 in _start (util-linux/build-meson/lsfd+0x41c34) (BuildId: 35fece1a205f96a2dbfe7a0e93b658530de675c4)
```

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
(cherry picked from commit 816109f6ffb99d3a7aee1ff6c3467803dcd7939c)
misc-utils/lsfd-sock-xinfo.c
misc-utils/lsfd.c