Skip to content

lib/ubsan: integer-divide-by-zero sanitizer is never enabled in custom mode #1946

Open

Description

@Anand-240

Describe the bug

In custom mode (CONFIG_LIBUBSAN_GLOBAL_CUSTOM=y), turning on "Integer division by zero" does nothing.

lib/ubsan/Makefile.uk has a typo in the config name:

SANITIZE_LIST-$(CONFIG_LIBUBSAN_SAN_DIV_BY_ZEOR)	+= integer-divide-by-zero

Config.uk defines LIBUBSAN_SAN_DIV_BY_ZERO, so the ZEOR one is never set and -fsanitize=integer-divide-by-zero never gets added. The default mode uses -fsanitize=undefined, so it's fine there.

Steps to reproduce

On staging (359307a), with:

  • CONFIG_LIBUBSAN=y
  • CONFIG_LIBUBSAN_GLOBAL_CUSTOM=y
  • CONFIG_LIBUBSAN_SAN_DIV_BY_ZERO=y

I built a small app that divides by a volatile zero and ran it on QEMU (kvm, x86_64 and arm64).

integer-divide-by-zero is missing from the -fsanitize flags in compile_commands.json, and there is no UBSan report at runtime. On arm64 it just prints 0, on x86_64 it hits the divide error trap.

Expected behavior

UBSan should report the division by zero. Changing ZEOR to ZERO in the Makefile fixes it, I tested this on both x86_64 and arm64. I'll send a PR.

Which architectures were you using or does this bug affect?

No response

Which platforms were you using or does this bug affect?

No response

Relevant log output

arm64, before:
[libubsan] Undefined behavior at main.c:7:33: shift of 42 by 40 out of bounds for type 'int'
[test] div:   0

arm64, after fix:
[libubsan] Undefined behavior at main.c:7:33: shift of 42 by 40 out of bounds for type 'int'
[libubsan] Undefined behavior at main.c:8:33: division by zero
[test] div:   0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions