Re: KUBSan & alignment
On 19.05.2019 17:33, Christos Zoulas wrote: > In article <76d02b7c-6408-1836-b247-0b5951c8a...@gmx.com>, > Kamil Rytarowski wrote: >> -=-=-=-=-=- >> -=-=-=-=-=- >> >> On 18.05.2019 17:21, Martin Husemann wrote: >>> On Fri, May 17, 2019 at 12:15:16PM -0500, David Young wrote: On Fri, May 17, 2019 at 05:19:40PM +0100, Patrick Welche wrote: > What should one do about > > UBSan: Undefined Behavior in >> ../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of >> misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which >> requires 4 byte alignment > UBSan: Undefined Behavior in >> ../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member >> access within misaligned address 0xe967d71420e2 for type 'union >> AML_RESOURCE' which requires 4 byte alignment >>> >>> Have not looked at those... >>> > UBSan: Undefined Behavior in >> ../../../../arch/x86/pci/pci_machdep.c:1134:15, member access within >> misaligned address 0x85a87c7c for type 'struct >> btinfo_framebuffer' which requires 8 byte alignment Supposing the authors really intended for the objects to be accessed in this way, label each declaration with __aligned(n) for some n? >>> >>> Since this code is in pci *machdep* and the behaviour is well defined for >>> those CPUs, just ignore it (or fix UBSan). >> >> Strictly speaking it's still UB and a compiler is allowed to miscompile >> it. x86 is also sensitive to alignment in certain operations (movaps vs >> movups; stack alignment, ...). >> >> My 80386 manual says that misalignment operations are slower than >> alignment ones on x86. > > I have already fixed it. And although misaligned access are slower than > aligned ones, the act of aligning them is even slower :-) > > christos > Thank you for the patch! We are working on pre-GSoC tasks now on cleaning the remaining UB warnings in the kernel. Our goal is to use kUBSan for kernel fuzzing (syzkaller and ideally TriforceAFL). signature.asc Description: OpenPGP digital signature
Re: KUBSan & alignment
On Sun, May 19, 2019 at 03:33:00PM -, Christos Zoulas wrote: > I have already fixed it. And although misaligned access are slower than > aligned ones, the act of aligning them is even slower :-) Thanks! I think I understand the answer to be "add a memcpy" which will align whateveritis. Cheers, Patrick
Re: KUBSan & alignment
In article <76d02b7c-6408-1836-b247-0b5951c8a...@gmx.com>, Kamil Rytarowski wrote: >-=-=-=-=-=- >-=-=-=-=-=- > >On 18.05.2019 17:21, Martin Husemann wrote: >> On Fri, May 17, 2019 at 12:15:16PM -0500, David Young wrote: >>> On Fri, May 17, 2019 at 05:19:40PM +0100, Patrick Welche wrote: What should one do about UBSan: Undefined Behavior in >../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of >misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which >requires 4 byte alignment UBSan: Undefined Behavior in >../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member >access within misaligned address 0xe967d71420e2 for type 'union >AML_RESOURCE' which requires 4 byte alignment >> >> Have not looked at those... >> UBSan: Undefined Behavior in >../../../../arch/x86/pci/pci_machdep.c:1134:15, member access within >misaligned address 0x85a87c7c for type 'struct >btinfo_framebuffer' which requires 8 byte alignment >>> >>> Supposing the authors really intended for the objects to be accessed in >>> this way, label each declaration with __aligned(n) for some n? >> >> Since this code is in pci *machdep* and the behaviour is well defined for >> those CPUs, just ignore it (or fix UBSan). > >Strictly speaking it's still UB and a compiler is allowed to miscompile >it. x86 is also sensitive to alignment in certain operations (movaps vs >movups; stack alignment, ...). > >My 80386 manual says that misalignment operations are slower than >alignment ones on x86. I have already fixed it. And although misaligned access are slower than aligned ones, the act of aligning them is even slower :-) christos
Re: KUBSan & alignment
On 18.05.2019 17:21, Martin Husemann wrote: > On Fri, May 17, 2019 at 12:15:16PM -0500, David Young wrote: >> On Fri, May 17, 2019 at 05:19:40PM +0100, Patrick Welche wrote: >>> What should one do about >>> >>> UBSan: Undefined Behavior in >>> ../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of >>> misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which >>> requires 4 byte alignment >>> UBSan: Undefined Behavior in >>> ../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member >>> access within misaligned address 0xe967d71420e2 for type 'union >>> AML_RESOURCE' which requires 4 byte alignment > > Have not looked at those... > >>> UBSan: Undefined Behavior in >>> ../../../../arch/x86/pci/pci_machdep.c:1134:15, member access within >>> misaligned address 0x85a87c7c for type 'struct btinfo_framebuffer' >>> which requires 8 byte alignment >> >> Supposing the authors really intended for the objects to be accessed in >> this way, label each declaration with __aligned(n) for some n? > > Since this code is in pci *machdep* and the behaviour is well defined for > those CPUs, just ignore it (or fix UBSan). Strictly speaking it's still UB and a compiler is allowed to miscompile it. x86 is also sensitive to alignment in certain operations (movaps vs movups; stack alignment, ...). My 80386 manual says that misalignment operations are slower than alignment ones on x86. > > Martin > signature.asc Description: OpenPGP digital signature
Re: KUBSan & alignment
On Fri, May 17, 2019 at 12:15:16PM -0500, David Young wrote: > On Fri, May 17, 2019 at 05:19:40PM +0100, Patrick Welche wrote: > > What should one do about > > > > UBSan: Undefined Behavior in > > ../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of > > misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which > > requires 4 byte alignment > > UBSan: Undefined Behavior in > > ../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member > > access within misaligned address 0xe967d71420e2 for type 'union > > AML_RESOURCE' which requires 4 byte alignment Have not looked at those... > > UBSan: Undefined Behavior in > > ../../../../arch/x86/pci/pci_machdep.c:1134:15, member access within > > misaligned address 0x85a87c7c for type 'struct btinfo_framebuffer' > > which requires 8 byte alignment > > Supposing the authors really intended for the objects to be accessed in > this way, label each declaration with __aligned(n) for some n? Since this code is in pci *machdep* and the behaviour is well defined for those CPUs, just ignore it (or fix UBSan). Martin
Re: KUBSan & alignment
On Fri, May 17, 2019 at 05:19:40PM +0100, Patrick Welche wrote: > What should one do about > > UBSan: Undefined Behavior in > ../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of > misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which > requires 4 byte alignment > UBSan: Undefined Behavior in > ../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member access > within misaligned address 0xe967d71420e2 for type 'union AML_RESOURCE' > which requires 4 byte alignment > UBSan: Undefined Behavior in ../../../../arch/x86/pci/pci_machdep.c:1134:15, > member access within misaligned address 0x85a87c7c for type 'struct > btinfo_framebuffer' which requires 8 byte alignment Supposing the authors really intended for the objects to be accessed in this way, label each declaration with __aligned(n) for some n? Dave -- David Young dyo...@pobox.comUrbana, IL(217) 721-9981
KUBSan & alignment
What should one do about UBSan: Undefined Behavior in ../../../../external/bsd/acpica/dist/events/evregion.c:611:14, load of misaligned address 0x8302d4f3 for type 'const ACPI_NAME' which requires 4 byte alignment UBSan: Undefined Behavior in ../../../../external/bsd/acpica/dist/resources/rsaddr.c:331:22, member access within misaligned address 0xe967d71420e2 for type 'union AML_RESOURCE' which requires 4 byte alignment UBSan: Undefined Behavior in ../../../../arch/x86/pci/pci_machdep.c:1134:15, member access within misaligned address 0x85a87c7c for type 'struct btinfo_framebuffer' which requires 8 byte alignment UBSan: Undefined Behavior in ../../../../arch/x86/pci/pci_machdep.c:1161:15, member access within misaligned address 0x85a87c7c for type 'struct btinfo_framebuffer' which requires 8 byte alignment UBSan: Undefined Behavior in ../../../../arch/x86/pci/pci_machdep.c:1169:15, member access within misaligned address 0x85a87c7c for type 'struct btinfo_framebuffer' which requires 8 byte alignment UBSan: Undefined Behavior in ../../../../kern/subr_disk_mbr.c:620:10, member access within misaligned address 0xe967daa66804 for type 'struct disklabel' which requires 8 byte alignment UBSan: Undefined Behavior in ../../../../kern/subr_disk_mbr.c:623:8, member access within misaligned address 0xe967daa66804 for type 'struct disklabel' which requires 8 byte alignment UBSan: Undefined Behavior in ../../../../kern/subr_disk_mbr.c:623:8, member access within misaligned address 0xe967daa66804 for type 'struct disklabel' which requires 8 byte alignment ? (NetBSD-8.99.41/amd64) P