Bug 246215 - [rtld] fails for i386 on amd64 if auxv does not contain PAGESIZES
Summary: [rtld] fails for i386 on amd64 if auxv does not contain PAGESIZES
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 12.1-RELEASE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Konstantin Belousov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-05 06:55 UTC by Paul Floyd
Modified: 2020-05-24 21:43 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Floyd 2020-05-05 06:55:47 UTC
I came across this issue whilst working on getting Valgrind to work.

When Valgrind runs, the guest application is loaded by Valgrind rather than the usual FreeBSD mechanisms. Thus Valgrind will synthesize an auxv, mmap rtld and run the rtld text in Valgrind's JIT compiled virtual CPU. However, to avoid memory space issues between the host and the guest, Valgrind does not provide auxv entries that contain pointers. This includes PAGESIZES.

Normally rtld obtains the pagesizes from auxv, but it has fallback code to use syscalls. This works OK for an amd64 exe on an amd64 kernel and i386 on i386. But there is a problem for i386 on amd64. The i386 application will see MAXPAGESLEN as 3 from the amd64 headers. But the i386 kernel sees this as only 2 [I might have gotten this the wrong way around]. The sysctl copy out code sees this discrepancy and sets ENOMEM and the application terminates without finishing the execution of rtld.

(I analysed all this with dtrace and looking at the source code, I don't know how to use gdb/lldb to step through rtld code).
Comment 1 Konstantin Belousov freebsd_committer 2020-05-06 20:07:19 UTC
Please test this https://reviews.freebsd.org/D24737
Comment 2 commit-hook freebsd_committer 2020-05-09 13:01:26 UTC
A commit references this bug:

Author: kib
Date: Sat May  9 13:00:39 UTC 2020
New revision: 360845
URL: https://svnweb.freebsd.org/changeset/base/360845

Log:
  Avoid spurious ENOMEMs from sysctl hw.pagesizes.

  Reported by:	Paul Floyd <paulf@free.fr>
  PR:	246215
  Reviewed by:	emaste
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D24737

Changes:
  head/sys/kern/kern_mib.c
Comment 3 commit-hook freebsd_committer 2020-05-16 09:04:19 UTC
A commit references this bug:

Author: kib
Date: Sat May 16 09:03:18 UTC 2020
New revision: 361108
URL: https://svnweb.freebsd.org/changeset/base/361108

Log:
  MFC r360845:
  Avoid spurious ENOMEMs from sysctl hw.pagesizes.

  PR:	246215

Changes:
_U  stable/12/
  stable/12/sys/kern/kern_mib.c
Comment 4 commit-hook freebsd_committer 2020-05-16 09:40:23 UTC
A commit references this bug:

Author: kib
Date: Sat May 16 09:40:18 UTC 2020
New revision: 361109
URL: https://svnweb.freebsd.org/changeset/base/361109

Log:
  MFC r360845:
  Avoid spurious ENOMEMs from sysctl hw.pagesizes.

  PR:	246215

Changes:
_U  stable/11/
  stable/11/sys/kern/kern_mib.c
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2020-05-24 21:43:25 UTC
Assign to committer.