Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

#4759 closed defect (fixed)

TLS support is broken for ARMv6

Reported by: jkillelea Owned by: Sebastian Huber <sebastian.huber@…>
Priority: normal Milestone: 6.1
Component: arch/arm Version: 6
Severity: normal Keywords:
Cc: Blocked By:
Blocking:

Description

I have found two possible memory exceptions under rtems_shell_init when running on the raspberry pi 1 BSP.

First, a possible null pointer dereference from getpwuid_r(0, &pwd, NULL, 0, &pwd_res); in rtems_shell_init_once. The NULL pointer is never checked before it is used as a backing buffer for pwd.

Second, usage of stdin, stdout, and stderr cause memory exceptions in rtems_shell_run when used, for example shell_env->parent_stdin = stdin;.

Attachments (1)

getpwuid_r_patch.txt (605 bytes) - added by jkillelea on 11/14/22 at 00:32:43.

Download all attachments as: .zip

Change History (9)

Changed on 11/14/22 at 00:32:43 by jkillelea

Attachment: getpwuid_r_patch.txt added

comment:1 Changed on 11/30/22 at 00:10:13 by Chris Johns

Component: adminshell

comment:2 Changed on 12/11/22 at 15:06:45 by jkillelea

It appears that raspberry pi does not support _Thread_Local attributes. Rebuilding GCC with the flag --without_newlib_tls seems to fix most errors. The null pointer error in getpwuid_r is actually ok, it's the call to set errno later in the function that causes failures.

comment:3 Changed on 12/15/22 at 07:18:06 by Sebastian Huber

What happens if you run the sptls01, sptls02, and sptls03 tests on this BSP?

After a tool update, did you recompile everything?

comment:4 Changed on 12/18/22 at 18:03:05 by jkillelea

I recompiled everything with the same --without_newlib_tls flag, yes. That seemed to fix most issues. Certain miscellaneous packages fail to compile, but the kernel, BSP, and libbsd all work. I can reach an interactive terminal inside qemu now, and can reach the terminal prompt over serial on real hardware (unclear why I can't type yet, but that feels unrelated).

comment:5 Changed on 12/19/22 at 06:43:45 by Sebastian Huber

Disabling the Newlib TLS configuration is really not a long term option. We should figure out why the TLS support is broken on this BSP. What happens if you run the sptls01, sptls02, and sptls03 tests on this BSP?

comment:6 Changed on 12/26/22 at 23:22:52 by jkillelea

Hi there, sorry for the delay. Here's the result of running each test on real hardware.
`
* BEGIN OF TEST SPTLS 1 *
* TEST VERSION: 6.0.0.240987228f7f7bab90c20efb8d219e26cf5f51c5
* TEST STATE: EXPECTED_PASS
* TEST BUILD: RTEMS_POSIX_API
* TEST TOOLS: 12.2.1 20221121 (RTEMS 6, RSB 65f83cf973d6f1f8974ea1818e653753b83eaea8, Newlib b9898fc)

* FATAL *
fatal source: 9 (RTEMS_FATAL_SOURCE_EXCEPTION)

R0 = 0x0000007b R8 = 0x770e8bde
R1 = 0x0000000a R9 = 0x5f4cdb15
R2 = 0x00000001 R10 = 0xe38f3ff7
R3 = 0x0024c068 R11 = 0xb1bc579f
R4 = 0x00000000 R12 = 0x01010101
R5 = 0x0000007b SP = 0x00303998
R6 = 0x00000008 LR = 0x00200600
R7 = 0x002001e8 PC = 0x0020059c
CPSR = 0x600001d3 VEC = 0x00000004
RTEMS version: 6.0.0.240987228f7f7bab90c20efb8d219e26cf5f51c5
RTEMS tools: 12.2.1 20221121 (RTEMS 6, RSB 65f83cf973d6f1f8974ea1818e653753b83eaea8, Newlib b9898fc)
executing thread ID: 0x09010001
executing th�
`

`
* BEGIN OF TEST SPTLS 2 *
* TEST VERSION: 6.0.0.240987228f7f7bab90c20efb8d219e26cf5f51c5
* TEST STATE: EXPECTED_PASS
* TEST BUILD: RTEMS_POSIX_API
* TEST TOOLS: 12.2.1 20221121 (RTEMS 6, RSB 65f83cf973d6f1f8974ea1818e653753b83eaea8, Newlib b9898fc)
A::globalCounter() = 0

* FATAL *
fatal source: 9 (RTEMS_FATAL_SOURCE_EXCEPTION)

R0 = 0x00000017 R8 = 0x00000000
R1 = 0x0000000a R9 = 0x00000000
R2 = 0x00003008 R10 = 0x00000000
R3 = 0x00000000 R11 = 0x00000000
R4 = 0x00226158 R12 = 0x00000000
R5 = 0x00302888 SP = 0x0030b290
R6 = 0x00000000 LR = 0x002006ac
R7 = 0x00000000 PC = 0x00200ff0
CPSR = 0x20000153 VEC = 0x00000004
RTEMS version: 6.0.0.240987228f7f7bab90c20efb8d219e26cf5f51c5
RTEMS tools: 12.2.1 20221121 (RTEMS 6, RSB 65f83cf973d6f1f8974ea1818e653753b83eaea8, Newlib b9898fc)
executing thread ID: 0x0a010001
executing th�
`

`
* BEGIN OF TEST SPTLS 3 *
* TEST VERSION: 6.0.0.240987228f7f7bab90c20efb8d219e26cf5f51c5
* TEST STATE: EXPECTED_PASS
* TEST BUILD: RTEMS_POSIX_API
* TEST TOOLS: 12.2.1 20221121 (RTEMS 6, RSB 65f83cf973d6f1f8974ea1818e653753b83eaea8, Newlib b9898fc)

* END OF TEST SPTLS 3 *

[ RTEMS shutdown ]
`

GCC was compiled via rsb using the flag --without_newlib_tls, but the kernel was built from source. Couldn't find where to use the same flag for that.

Last edited on 12/26/22 at 23:24:18 by jkillelea (previous) (diff)

comment:7 Changed on 01/03/23 at 07:49:36 by Sebastian Huber <sebastian.huber@…>

Owner: set to Sebastian Huber <sebastian.huber@…>
Resolution: fixed
Status: newclosed

In [changeset:"f8cb1f483db81f7c99020032fe578e94d62d8bc5/rtems" f8cb1f48/rtems]:

arm: Enable thread ID register for ARMv6

Close #4759.

comment:8 Changed on 01/03/23 at 07:53:06 by Sebastian Huber

Component: shellarch/arm
Summary: RPi: crashes when shell startsTLS support is broken for ARMv6
Note: See TracTickets for help on using tickets.