u-boot/drivers
Eugeniu Rosca 9bfacf249b core: ofnode: Fix ASAN-reported stack-buffer-overflow in of_get_address
v2019.04-rc3 sandbox U-Boot fails to boot when compiled with
 -fsanitize=address and linked against -lasan, reporting [1].

Git bisecting shows that the issue is contributed by v2019.01 commit
1678754f5e ("core: ofnode: Fix ofnode_get_addr_index function").

The root cause seems to be the mismatch between sizeof(u64) and
sizeof(fdt_size_t) on sandbox. Luckily, thanks to the fact that the
size argument of both of_get_address() and fdtdec_get_addr_size_fixed()
is optional, we can pass NULL in its place, avoiding the problem.

[1] Backtrace reported by ASAN (gcc 8.1.0):

$> ./u-boot -d arch/sandbox/dts/sandbox.dtb
[..]
Reviewed-by: Simon Glass <sjg@chromium.org>

=================================================================
==10998==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcc2331140 at pc 0x0000004eeeb0 bp 0x7ffcc2330f80 sp 0x7ffcc2330f70
WRITE of size 8 at 0x7ffcc2331140 thread T0
    #0 0x4eeeaf in of_get_address drivers/core/of_addr.c:154
    #1 0x4f7441 in ofnode_get_addr_index drivers/core/ofnode.c:263
    #2 0x5b2a78 in sb_eth_ofdata_to_platdata drivers/net/sandbox.c:422
    #3 0x4dccd8 in device_probe drivers/core/device.c:407
    #4 0x753170 in eth_initialize net/eth-uclass.c:428
    #5 0x47d9bf in initr_net common/board_r.c:557
    #6 0x6bcfa7 in initcall_run_list lib/initcall.c:30
    #7 0x47e1fe in board_init_r common/board_r.c:859
    #8 0x4060e5 in main arch/sandbox/cpu/start.c:356
    #9 0x7fb8d135482f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #10 0x40a3a8 in _start (/path/to/u-boot/u-boot+0x40a3a8)

Address 0x7ffcc2331140 is located in stack of thread T0 at offset 32 in frame
    #0 0x4f72b8 in ofnode_get_addr_index drivers/core/ofnode.c:255

  This frame has 3 object(s):
    [32, 36) 'size' <== Memory access at offset 32 partially overflows this variable
    [96, 100) 'flags'
    [160, 168) 'node'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow drivers/core/of_addr.c:154 in of_get_address
Shadow bytes around the buggy address:
  0x10001845e1d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10001845e1e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10001845e1f0: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
  0x10001845e200: 04 f2 f2 f2 f2 f2 f2 f2 04 f2 f2 f2 f2 f2 f2 f2
  0x10001845e210: 04 f2 f2 f2 f3 f3 f3 f3 00 00 00 00 00 00 00 00
=>0x10001845e220: 00 00 00 00 f1 f1 f1 f1[04]f2 f2 f2 f2 f2 f2 f2
  0x10001845e230: 04 f2 f2 f2 f2 f2 f2 f2 00 f2 f2 f2 f3 f3 f3 f3
  0x10001845e240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x10001845e250: 00 00 00 00 f1 f1 f1 f1 00 00 f2 f2 f3 f3 f3 f3
  0x10001845e260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1
  0x10001845e270: f1 f1 00 f2 f2 f2 f3 f3 f3 f3 00 00 00 00 00 00
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
==10998==ABORTING

'To' list:
 git log --since=1year drivers/core/ofnode.c | grep "\-by: .*@" | \
     sed 's/.*-by: //' | sort | uniq -c | sort -rn
     10 Simon Glass <sjg@chromium.org>
      3 Mario Six <mario.six@gdsys.cc>
      2 Martin Fuzzey <mfuzzey@parkeon.com>
      2 Marek Vasut <marek.vasut+renesas@gmail.com>
      1 Tom Rini <trini@konsulko.com>
      1 Masahiro Yamada <yamada.masahiro@socionext.com>
      1 Keerthy <j-keerthy@ti.com>
      1 Jens Wiklander <jens.wiklander@linaro.org>
      1 Bin Meng <bmeng.cn@gmail.com>

Fixes: 1678754f5e ("core: ofnode: Fix ofnode_get_addr_index function")
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
2019-04-11 20:10:05 -06:00
..
adc adc: exynos-adc: Fix wrong bit operation used to stop the ADC 2019-03-11 15:53:19 +09:00
ata scsi: ceva: add ls2080a soc support 2018-12-06 14:38:03 -08:00
axi drivers: cosmetic: Convert SPDX license tags to Linux Kernel style 2018-10-28 09:26:39 -04:00
bios_emulator bios_emulator: remove assignment without effect 2018-07-23 14:33:21 -04:00
block blk: Increase cache element size 2019-01-15 15:28:53 -05:00
board drivers: cosmetic: Convert SPDX license tags to Linux Kernel style 2018-10-28 09:26:39 -04:00
bootcount bootcount: add a DM RTC backing store for bootcount 2018-12-10 10:04:45 +01:00
clk clk: renesas: Synchronize Gen3 tables with Linux 5.0 2019-04-09 18:19:10 +02:00
core core: ofnode: Fix ASAN-reported stack-buffer-overflow in of_get_address 2019-04-11 20:10:05 -06:00
cpu cpu: Bind timer driver for boot hart 2019-02-27 09:12:33 +08:00
crypto SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
ddr mv_ddr: ddr3: only use active chip-selects when tuning ODT 2019-03-19 09:22:05 +01:00
demo SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
dfu dfu: mmc: call fs functions instead of run_command 2019-01-30 21:22:53 -05:00
dma dma: add bcm6348-iudma support 2018-12-19 15:23:00 +01:00
fastboot fastboot: common: fix default fastboot_boot on 64-bit 2019-03-16 13:29:43 +01:00
firmware firmware: psci: introduce SPL_ARM_PSCI_FW 2018-12-12 12:14:25 -05:00
fpga ARM: socfpga: stratix10: Return valid error code from FPGA driver 2019-02-18 13:00:54 +01:00
gpio gpio: altera_pio: fix get_value 2019-02-25 16:07:36 +01:00
hwspinlock hwspinlock: add stm32 hardware spinlock support 2018-12-06 23:26:33 -05:00
i2c i2c: i2c_cdns: Fix below warnings with checker tool 2019-03-21 08:21:43 +01:00
input Kconfig: tegra: Migrate TEGRA_KEYBOARD 2019-02-20 09:01:45 -07:00
led dm: led: move default state support in led uclass 2018-08-10 10:27:32 -04:00
mailbox drivers: cosmetic: Convert SPDX license tags to Linux Kernel style 2018-10-28 09:26:39 -04:00
memory SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
misc xilinx: common: Remove !DM_i2C code for reading mac from eeprom 2019-02-14 14:31:10 +01:00
mmc mmc: correct the HS400 initialization process 2019-03-29 10:53:18 -04:00
mtd mtd: ubi, ubifs debug: Use pr_debug instead of pr_crit 2019-04-09 07:46:42 +02:00
net Merge branch 'master' of git://git.denx.de/u-boot-sh 2019-04-11 14:29:22 -04:00
nvme blk: Call part_init() in the post_probe() method 2018-11-14 09:16:27 -08:00
pch pch: Add ioctl support 2019-02-20 15:27:08 +08:00
pci pci: pci_mvebu: Add comment about missing of_n_addr_cells() call 2019-03-19 09:22:05 +01:00
pcmcia SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
phy phy: Also allow MESON_GXM for MESON_GXL_USB_PHY 2019-04-03 10:23:38 -04:00
pinctrl dm: pinctrl: Skip gpio-controller node in pinconfig_post_bind() 2019-04-11 20:10:05 -06:00
power Merge branch 'master' of git://git.denx.de/u-boot-samsung 2019-03-14 11:37:11 -04:00
pwm pwm: sunxi: choose best prescaler to improve PWM resolution 2018-10-24 21:57:16 +05:30
qe drivers: qe: add TFABOOT support 2018-12-06 14:37:51 -08:00
ram rockchip: ram: update license for sdram driver 2019-01-02 22:37:10 +01:00
remoteproc spl: Allow remoteproc drivers to be used within SPL 2018-09-11 08:32:55 -04:00
reset reset: Add Allwinner RESET driver 2019-01-18 22:19:08 +05:30
rtc rtc: m41t62: Convert the RTC driver to support the driver model (DM) 2018-12-03 10:44:10 -05:00
scsi dm: scsi: report correct device number 2019-02-19 08:55:43 -05:00
serial serial: atmel_usart: Use fixed clock value in SPL version with DM_SERIAL 2019-04-09 09:28:50 +03:00
smem drivers: smem: sandbox 2018-07-19 16:31:38 -04:00
soc SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
sound x86: Add sound support for samus 2019-02-20 15:27:11 +08:00
spi spi: Rename sun4i_spi.c into spi-sunxi.c 2019-03-04 18:08:56 +05:30
spmi SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
sysreset sysreset: use syscon_regmap_lookup_by_phandle 2019-04-11 20:10:05 -06:00
tee tee: change return code for REE FS supplicant cmd 2018-12-15 11:49:19 -05:00
thermal SPDX: Convert all of our single license tags to Linux Kernel style 2018-05-07 09:34:12 -04:00
timer x86: tsc: Add support for native calibration of TSC freq 2019-02-12 14:37:16 +08:00
tpm tpm: Export the open/close functions 2018-11-29 09:30:06 -07:00
usb usb: ehci-mx6: Use common code to extract dr_mode 2019-04-09 13:11:45 +02:00
video sunxi: video: HDMI: Fix clock setup 2019-03-28 23:45:41 +01:00
virtio virtio: Add a Sandbox transport driver 2018-11-14 09:16:28 -08:00
w1 w1: Add driver for i.MX bus master controller 2019-01-01 14:12:18 +01:00
w1-eeprom w1-eeprom: Add support for Maxim DS2502 add only memory 2018-11-16 16:51:55 -05:00
watchdog arm: at91: Enable watchdog support 2019-04-09 09:28:50 +03:00
Kconfig x86: sandbox: pch: Add a CONFIG option for PCH 2019-02-20 15:25:30 +08:00
Makefile x86: sandbox: pch: Add a CONFIG option for PCH 2019-02-20 15:25:30 +08:00