7
32
Fork
You've already forked blackmagic
23

Y2038 compatibility #2038

Open
opened 2024年12月30日 15:48:53 +01:00 by ALTracer · 1 comment
ALTracer commented 2024年12月30日 15:48:53 +01:00 (Migrated from github.com)
Copy link

Please clarify whether any BMP firmware platform or BMDA supported OS is affected by the Y2038 superbug.

  1. BMP/STM32 does not use RTC peripherals, relies on newlib with 64-bit time_t (AFAIK) with arm-none-eabi-gcc from Arm GNU Tools. Do you need to ensure that the toolchain and/or libc is good? (in case someone tries to build against picolibc or NuttX libc etc.) Same for BMP/LM4F, and there are no other vendors among in-tree platforms.
  2. BMP has Semihosting support. Does it pass timestamps (like SYS_TIME) around correctly? Does ARM semihosting ABI impose limitations on BMD?
  3. BMP has rudimentary timekeeping for SysTick-based delays in milliseconds. When does this overflow and is this a problem?
  4. BMDA when compiled for 32-bit OS has to rely on OS libc (glibc, musl, etc.) and kernel (vDSO) to provide time64_t; if time_t is 32-bit and BMDA compares timestamps, this is a potential problem. Are any mitigations required?
  5. BMDA-supported 3rd party adapters are assumed to be unaffected because they don't retain datetime when unpowered or don't have to parse timestamps for pure USB/SWD/JTAG bridge manipulations. Is the BMP HL remote protocol affected?

Less sure about battery-powered ctxLink, Farpatch, etc. And 3rd party desktop software is not considered here, especially if they have their own issue trackers.

Please clarify whether any BMP firmware platform or BMDA supported OS is affected by the Y2038 superbug. 1. BMP/STM32 does not use RTC peripherals, relies on newlib with 64-bit time_t (AFAIK) with arm-none-eabi-gcc from Arm GNU Tools. Do you need to ensure that the toolchain and/or libc is good? (in case someone tries to build against picolibc or NuttX libc etc.) Same for BMP/LM4F, and there are no other vendors among in-tree platforms. 2. BMP has Semihosting support. Does it pass timestamps (like SYS_TIME) around correctly? Does ARM semihosting ABI impose limitations on BMD? 3. BMP has rudimentary timekeeping for SysTick-based delays in milliseconds. When does this overflow and is this a problem? 4. BMDA when compiled for 32-bit OS has to rely on OS libc (glibc, musl, etc.) and kernel (vDSO) to provide time64_t; if `time_t` is 32-bit and BMDA compares timestamps, this is a potential problem. Are any mitigations required? 5. BMDA-supported 3rd party adapters are assumed to be unaffected because they don't retain datetime when unpowered or don't have to parse timestamps for pure USB/SWD/JTAG bridge manipulations. Is the BMP HL remote protocol affected? Less sure about battery-powered ctxLink, Farpatch, etc. And 3rd party desktop software is not considered here, especially if they have their own issue trackers.

👋🏼 going to answer each of the points in turn, though in practice the problem you're asking about is more a function of the semihosting protocol spec itself and what firmware being debugged supports (or doesn't):

BMP/STM32 does not use RTC peripherals, relies on newlib with 64-bit time_t (AFAIK) with arm-none-eabi-gcc from Arm GNU Tools. Do you need to ensure that the toolchain and/or libc is good? (in case someone tries to build against picolibc or NuttX libc etc.) Same for BMP/LM4F, and there are no other vendors among in-tree platforms.

We control for this by saying that other libc's are just unsupported as that's way too many variables to even begin to try and control in practice. If a user manages to even get a good build of the firmware out that way (which we currently doubt they would), then if they run into problems with 2038 then from the project's perspective, that's firmly on them for running an unsupported configuration. This is the only viable way we have to control for this.

BMP has Semihosting support. Does it pass timestamps (like SYS_TIME) around correctly? Does ARM semihosting ABI impose limitations on BMD?

On 32-bit targets, SYS_TIME is 32-bit, but it is unsigned, thus pushing the problem out past 2038. This is currently a problem we don't deal with properly under BMDA as we never got back to addressing the C API used to grab the time (never actually use time() in production code, it's fundamentally broken..) and which will be addressed in v2.1; but under the firmware we are constrained by GDB's correctness and as long as it gives us valid answers for the gettimeofday upcall, then the time representation structure we use internally will handle it just fine and even though we do an unsigned-signed conversion on the way out, the result will wind up correct in the MCU registers. This is contingent on things outside our control though.

BMP has rudimentary timekeeping for SysTick-based delays in milliseconds. When does this overflow and is this a problem?

It overflows every UINT32_MAX miliseconds, which is well defined by C. We then specifically take the overflow case into account in the timeout handling code. #1812 has more details about that. It used to be a problem and is a reason for people to migrate of their v1.x firmware once the release has been made of v2.0.

BMDA when compiled for 32-bit OS has to rely on OS libc (glibc, musl, etc.) and kernel (vDSO) to provide time64_t; if time_t is 32-bit and BMDA compares timestamps, this is a potential problem. Are any mitigations required?

In practice, this is only a problem on really ancient glibc's and such. All modern Linux distros have a time_t that is suitable. Meson also fixed a bug around this for us by passing -D_FILE_OFFSET_BITS=64 for all compilations automatically. There isn't an equivalent define for time_t that we know of, but we'll get what we can automatically. We're not aware of any timestamp comparisons made using anything other than internal unsigned structures and types.

BMDA itself uses gettimeofday() for the moment to get a suitable time value for timeouts and such. This calculation is carefully kept unsigned to prevent problems. It should give the same behaviour as the firmware's version with a counter.

BMDA-supported 3rd party adapters are assumed to be unaffected because they don't retain datetime when unpowered or don't have to parse timestamps for pure USB/SWD/JTAG bridge manipulations. Is the BMP HL remote protocol affected?

Yes, no time primitives exist in that protocol.

👋🏼 going to answer each of the points in turn, though in practice the problem you're asking about is more a function of the semihosting protocol spec itself and what firmware being debugged supports (or doesn't): > BMP/STM32 does not use RTC peripherals, relies on newlib with 64-bit time_t (AFAIK) with arm-none-eabi-gcc from Arm GNU Tools. Do you need to ensure that the toolchain and/or libc is good? (in case someone tries to build against picolibc or NuttX libc etc.) Same for BMP/LM4F, and there are no other vendors among in-tree platforms. We control for this by saying that other libc's are just unsupported as that's way too many variables to even begin to try and control in practice. If a user manages to even get a good build of the firmware out that way (which we currently doubt they would), then if they run into problems with 2038 then from the project's perspective, that's firmly on them for running an unsupported configuration. This is the *only* viable way we have to control for this. > BMP has Semihosting support. Does it pass timestamps (like SYS_TIME) around correctly? Does ARM semihosting ABI impose limitations on BMD? On 32-bit targets, [SYS_TIME](https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#620sys_time-0x11) is 32-bit, but it is unsigned, thus pushing the problem out past 2038. This is [currently a problem](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/target/semihosting.c#L702-L705) we don't deal with properly under BMDA as we never got back to addressing the C API used to grab the time (never actually use `time()` in production code, it's fundamentally broken..) and which will be addressed in v2.1; but under the firmware we are constrained by GDB's correctness and as long as it gives us [valid answers for the gettimeofday](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/target/semihosting.c#L653) upcall, then the [time representation structure we use internally](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/target/semihosting_internal.h#L62-L65) will handle it just fine and even though we do an unsigned-signed conversion on the way out, the result will wind up correct in the MCU registers. This is contingent on things outside our control though. > BMP has rudimentary timekeeping for SysTick-based delays in milliseconds. When does this overflow and is this a problem? It overflows every [UINT32_MAX miliseconds](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/platforms/common/stm32/timing_stm32.c#L32), which is well defined by C. We then [specifically take the overflow case into account](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/timing.c#L34-L43) in the timeout handling code. #1812 has more details about that. It used to be a problem and is a reason for people to migrate of their v1.x firmware once the release has been made of v2.0. > BMDA when compiled for 32-bit OS has to rely on OS libc (glibc, musl, etc.) and kernel (vDSO) to provide time64_t; if time_t is 32-bit and BMDA compares timestamps, this is a potential problem. Are any mitigations required? In practice, this is only a problem on really ancient glibc's and such. All modern Linux distros have a time_t that is suitable. Meson also fixed a bug around this for us by passing `-D_FILE_OFFSET_BITS=64` for all compilations automatically. There isn't an equivalent define for time_t that we know of, but we'll get what we can automatically. We're not aware of any timestamp comparisons made using anything other than internal unsigned structures and types. BMDA itself uses [`gettimeofday()` for the moment](https://github.com/blackmagic-debug/blackmagic/blob/86704be968af4a8aa16e01a5f409e04028819391/src/platforms/hosted/utils.c#L46-L51) to get a suitable time value for timeouts and such. This calculation is carefully kept unsigned to prevent problems. It should give the same behaviour as the firmware's version with a counter. > BMDA-supported 3rd party adapters are assumed to be unaffected because they don't retain datetime when unpowered or don't have to parse timestamps for pure USB/SWD/JTAG bridge manipulations. Is the BMP HL remote protocol affected? Yes, no time primitives exist in that protocol.
Sign in to join this conversation.
No Branch/Tag specified
main
fix/pre-bmp-v3-cross-file-cleanup
feature/bmda-remote-comms
ALTracer/feature/aarch64-ident
feature/better-meson-optimisation-handling
feature/am335x-support
feature/esp32-c3-support
feature/cortex-ar-software-breakpoints
feature/unit-testing
feature/windows-usb-serial-interface-naming
fix/bmp-external-spi
ALTracer/feature/bluepillplus-platform
ALTracer/feature/at32f43x-unrdp
feature/const-correctness
ALTracer/feature/fault_handlers
ALTracer/feature/hazard3-ice40-support
fix/ci-cleanup
ALTracer/fix/gdb-10-12-thread
ALTracer/feature/blackpill-f4-adc
ALTracer/fix/cortex-desc-allocfail-report
ALTracer/feature/spi-perf
ALTracer/feature/calibrate_swd
ALTracer/feature/blank-check
feature/avr
v2.0
v1.9
v1.10
v1.8
v2.1.0-rc1
v2.0.0
v2.0.0-rc2
v2.0.0-rc1
v1.9.3
v1.10.2
v1.10.1
v1.10.0
v1.10.0-rc1
v1.10.0-rc0
v1.9.2
v1.8.3
v1.9.1
v1.9.0
v1.9.0-rc1
v1.9.0-rc0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
v1.7
v1.6.2-rc1
1.6.2-rc0
v1.6.1
v1.6
v1.6-rc1
v1.6-rc0
production_01
production_00
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic#2038
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?