[MDEV-23491] __bss_start breaks compilation of various platforms Created: 2020-08-16  Updated: 2020-10-06  Resolved: 2020-08-18

Status: Closed
Project: MariaDB Server
Component/s: Compiling
Affects Version/s: 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.1.48, 10.2.35, 10.3.26, 10.4.16, 10.5.7

Type: Bug Priority: Major
Reporter: Sergei Golubchik Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-23496 Fix build issue for MariaDB-10.5 on D... Closed
Problem/Incident
is caused by MDEV-15961 Fix stacktraces under FreeBSD Closed

 Description   

when printing various strings from a SIGSEGV handler, stacktrace.c uses various tricks to make sure the pointer to a string is valid and can be resolved.

It particular it reads /proc/self/task/%d/mem map and checks the pointer against the __bss_start address. Getting this __bss_start is a very fragile piece of code and it breaks linking on various linux versions depending on what libraries are linked and what compiler/binutil version is used.

But this is all completely unnecessary, because the string is directly printed using kernel syscall write() — and kernel validates all user space pointers anyway. We should remove all pointer checks and just let the kernel vet them as it always does.

Note that on other OSes stacktrace.c does not validate any pointers (neither via proc map nor against __bss_start). User space pointer validation is Linux-only and completely redundant.

The trick is not to resolve the pointer before write(). In particular, at least one function does isprint(*c) — this should be removed. It doesn't add much, the crash information is printed to a log, not to a terminal, so we don't have to filter out control codes.



 Comments   
Comment by Oleksandr Byelkin [ 2020-08-16 ]

commit eaf707984683b2ab4b5e35c5b598b23fd24c4c09 (HEAD -> bb-10.1-release, origin/bb-10.1-release)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date: Sun Aug 16 22:14:59 2020 +0200

MDEV-23491: __bss_start breaks compilation of various platforms

remove __bss_start & Co

Comment by Oleksandr Byelkin [ 2020-08-17 ]

commit 14f9f95beecf7374f7741ec804b931cfb382d369 (HEAD -> bb-10.1-release, origin/bb-10.1-release)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date: Sun Aug 16 22:14:59 2020 +0200

MDEV-23491: __bss_start breaks compilation of various platforms

Remove __bss_start & Co, because systen call "write" check buffer address and return EFAULT if it is wrong.

Comment by Oleksandr Byelkin [ 2020-08-18 ]

rebased versions (where were conflicts):
10.2 623eafb734b26e468f232faf3506c6f4346439c1
10.3 40aabfff1f28e16085e6cd6755ce8d6ab0862d4e
10.5 86be5bda2412bc627a8b708b9cc32cf16a0a736f

Generated at Thu Feb 08 09:22:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.