Re: [PATCH] ACPICA: fix UBSAN warning using __builtin_offsetof
From: Nick Desaulniers
Date: Tue Jun 02 2020 - 14:46:47 EST
On Mon, Jun 1, 2020 at 5:03 PM Kaneda, Erik <erik.kaneda@xxxxxxxxx> wrote:
> > Will reported UBSAN warnings:
> > UBSAN: null-ptr-deref in drivers/acpi/acpica/tbfadt.c:459:37
> > UBSAN: null-ptr-deref in arch/arm64/kernel/smp.c:596:6
> > Looks like the emulated offsetof macro ACPI_OFFSET is causing these. We
> > can avoid this by using the compiler builtin, __builtin_offsetof.
> I'll take a look at this tomorrow
> > The non-kernel runtime of UBSAN would print:
> > runtime error: member access within null pointer of type for this macro.
> actypes.h is owned by ACPICA so we typically do not allow compiler-specific
> extensions because the code is intended to be compiled using the C99 standard
> without compiler extensions. We could allow this sort of thing in a Linux-specific
> header file like include/acpi/platform/aclinux.h but I'll take a look at the error as well..
If I'm not allowed to touch that header, it looks like I can include
<linux/stddef.h> (rather than my host's <stddef.h>) to get a
definition of `offsetof` thats implemented in terms of
`__builtin_offsetof`. I should be able to use that to replace uses of
ACPI_OFFSET. Are any of these off limits?
$ grep -rn ACPI_OFFSET
(ACPI_OFFSET(struct acpi_madt_generic_interrupt, \
include/acpi/actbl.h:376:#define ACPI_FADT_OFFSET(f) (u16)
ACPI_OFFSET (struct acpi_table_fadt, f)
(u8) ACPI_OFFSET (struct acpi_resource,f)
(u8) ACPI_OFFSET (union aml_resource,f)
(u8) ACPI_OFFSET (union acpi_operand_object,f)
(u8) ACPI_OFFSET (struct acpi_namespace_node,f)
(u8) ACPI_OFFSET (union acpi_resource_data,f)
(u8) ACPI_OFFSET (struct acpi_pci_routing_table,f)