Skip to content

Conversation

@doctaweeks
Copy link

No description provided.

bradbishop pushed a commit that referenced this pull request Nov 6, 2020
The astlpc binding allows negotiation of Tx/Rx region sizes, but the
packet accumulator assumed packet sizes were at most 4096 bytes.  Avoid
buffer overflow by allocating at least the length of the inbound packet
if we have not yet initialised the packet buffer.

Fixes:

=================================================================
==42296==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000002500 at pc 0x7ff8a22235ce bp 0x7ffd47469750 sp 0x7ffd47468ef8
WRITE of size 8192 at 0x621000002500 thread T0
    #0 0x7ff8a22235cd in __interceptor_memcpy (/usr/lib/x86_64-linux-gnu/libasan.so.6+0x3a5cd)
    #1 0x7ff8a21ac78b in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:34
    #2 0x7ff8a21ac78b in mctp_msg_ctx_add_pkt /home/andrew/src/openbmc/libmctp/core.c:237
    #3 0x7ff8a21af245 in mctp_bus_rx /home/andrew/src/openbmc/libmctp/core.c:495
    #4 0x56458d3f9648 in mctp_astlpc_rx_start astlpc.c:813
    #5 0x56458d3f9648 in mctp_astlpc_poll astlpc.c:931
    #6 0x56458d3fc1f4 in astlpc_test_send_large_packet tests/test_astlpc.c:1111
    #7 0x56458d3efc86 in main tests/test_astlpc.c:1185
    #8 0x7ff8a165dcb1 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28cb1)
    #9 0x56458d3efe7d in _start (/home/andrew/src/openbmc/libmctp/tests/.libs/test_astlpc+0x17e7d)

0x621000002500 is located 0 bytes to the right of 4096-byte region [0x621000001500,0x621000002500)
allocated by thread T0 here:
    #0 0x7ff8a22998d0 in __interceptor_realloc (/usr/lib/x86_64-linux-gnu/libasan.so.6+0xb08d0)
    #1 0x7ff8a21b0533 in __mctp_realloc /home/andrew/src/openbmc/libmctp/alloc.c:48

SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.6+0x3a5cd) in __interceptor_memcpy
Shadow bytes around the buggy address:
  0x0c427fff8450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fff8460: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fff8470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fff8480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c427fff8490: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c427fff84a0:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff84b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff84c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff84d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff84e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c427fff84f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==42296==ABORTING

Signed-off-by: Andrew Jeffery <[email protected]>
Change-Id: I9d39090cb9246ec2f6c06942d4f2a91fe0df0202
dkodihal pushed a commit to NVIDIA/libmctp that referenced this pull request May 26, 2025
We support ignoring EIDs returned by the bridge's routing table by
supplying the `-z` parameter. This parameter is typically included in
the systemd environment file.

The above method does not work well for templated control daemon
services (such as USB) if we have the need to ignore different set of
EIDs for a given instance of the service.

Therefore, this commit adds support to supply an array of decimal EIDs
in the USB config JSON, which when supplied, will override any ignore
EIDs in the -z parameter. Since the JSON has separate sections for every
control daemon instance, this method can be used to supply unique ignore
list per instance.

Fixes JIRA https://jirasw.nvidia.com/browse/DGXOPENBMC-17580

Tested:
Tested this on HGXB300 setup by temporarily overriding the USB config
JSON as follows:

```
        "1-1-1-2": {
            "eid_type" : "static",
            "own_eid" : 8,
            "bridge_eid" : 70,
            "bridge_pool_start" : 57,
            "ignore_eids" : [58, 59, 60],
            "vendor_id" : "0x0955",
            "product_id" : "0xCF11",
            "recovery_vendor_id": "0x0955",
            "recovery_product_id": "0xCF1F",
            "reset_gpio_name": "MCU2_RST_N-O",
            "recovery_gpio_name": "MCU2_RECOV_N-O",
            "_comment" : "CX8 MCU openbmc#2: CX8_3/CX8_1"
        }
```

Then, upon restarting the specific control daemon instance:

```
May 08 10:54:20 hgxb300 systemd[1]: Started MCTP USB control daemon.
May 08 10:54:20 hgxb300 mctp-usb-ctrl 1-1-1-2[27536]: parse_command_line: No. of EIDs to ignore: 8
May 08 10:54:20 hgxb300 mctp-usb-ctrl 1-1-1-2[27536]: parse_command_line: Verbose level:1
May 08 10:54:20 hgxb300 mctp-usb-ctrl 1-1-1-2[27536]: parse_command_line: EID to ignore: 58
May 08 10:54:20 hgxb300 mctp-usb-ctrl 1-1-1-2[27536]: parse_command_line: EID to ignore: 59
May 08 10:54:20 hgxb300 mctp-usb-ctrl 1-1-1-2[27536]: parse_command_line: EID to ignore: 60
```
The EIDs to ignore get overridden to 58, 59 and 60.

The discovery output now shows:
```
root@hgxb300:~# busctl tree xyz.openbmc_project.MCTP.Control.USB1_1_1_2
`- /xyz
  `- /xyz/openbmc_project
    `- /xyz/openbmc_project/mctp
      |- /xyz/openbmc_project/mctp/0
      | |- /xyz/openbmc_project/mctp/0/57
      | `- /xyz/openbmc_project/mctp/0/70
      `- /xyz/openbmc_project/mctp/USB1_1_1_2
```

Also verified that other service instance are not impacted as they
continue to use the global ignore list.

Signed-off-by: Santosh Puranik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant