Commit graph

1526 commits

Author SHA1 Message Date
Elliott Hughes
9591df5294 Fix vdso system call fallback failures.
When a vdso call falls back to making a regular system call, the inline
code for the system call doesn't know about errno and just leaves the
usual kernel result to be translated. Add the missing translation.

Also fix the defaults for non-vdso systems so we actually take the
fallback path (and so avoid unintentionally doing the errno translation
twice in those cases).

Bug: http://b/69626243
Test: ran new tests from http://b/63737556
Change-Id: If379632ea2e059e3d3bc3ff41bf3608dc05fb0a3
2017-11-28 09:09:01 -08:00
Elliott Hughes
8c75675ec6 Merge "Change ARG_MAX/_SC_ARG_MAX back to a constant." 2017-11-16 21:46:49 +00:00
Elliott Hughes
c3f1b6a23d Merge "Simplify the posix_spawn sigdefault logic." 2017-11-16 00:08:31 +00:00
Elliott Hughes
baed51ee3a Change ARG_MAX/_SC_ARG_MAX back to a constant.
As per the lkml thread https://lkml.org/lkml/2017/11/1/946.

Bug: http://b/65818597
Test: ran tests
Change-Id: I7a0610e6903e6761f2b31416e2f5017bd7a60659
2017-11-15 15:14:35 -08:00
Tom Cherry
4362f897f7 Only use uids and gids for which we've allocated AIDs
Currently, getpwnam, getpwent, etc return successfully for any uid
from AID_APP_START (10000) to AID_USER_OFFSET (100000) for each user.
This is not correct however, as only specific ranges above
AID_APP_START are reserved as valid ranges.  This change corrects this.

This is particularly important as the newly added AID_OVERFLOWUID is
65534, which is above AID_APP_START but not in any reserved range,
collided with the faulty returned values.

Bug: 69119022
Bug: 69128408
Test: pwd/grp bionic unit tests
Change-Id: I3dae97a90597915fa30a88fe27cda88b107e9c35
2017-11-15 10:31:49 -08:00
Elliott Hughes
2b8ab4b5da Simplify the posix_spawn sigdefault logic.
I don't think there's any observable difference, but this is certainly
simpler.

Bug: http://b/68707996
Test: ran tests
Change-Id: Id9e1a7d40533c90d073ebf391a72bbdfe79627de
2017-11-14 22:31:43 -08:00
Tom Cherry
fd44b9f8d8 Split system_properties.cpp into its component pieces
system_properties.cpp is a little bit unmanageable in its current
form, and is overdue for a refactoring into more clearly defined
components.

Of particular interest, is creating of a Contexts interface that
handles mapping of system property name -> SEContext and its
associated prop_area, and creating two classes that implement the
current and legacy functionality.  This is needed as there will likely
be a third even newer way to do this mapping.

Bug: 36001741
Test: boot bullhead, system property unit tests
Change-Id: Ie75ec6fea1a95f90813918f54669d533e51327c6
2017-11-14 08:50:52 -08:00
Elliott Hughes
38f01e05ef Preserve historical pthread_create scheduler behavior better.
At the cost of two flag bits for what POSIX thinks should be a boolean
choice, plus somewhat confusing behavior from pthread_attr_getinheritsched
depending on when you call it/what specific scheduler attributes you've
set in the pthread_attr_t, we can emulate the old behavior exactly and
prevent annoying SELinux denial spam caused by calls to sched_setscheduler.

Bug: http://b/68391226
Test: adb logcat on boot contains no sys_nice avc denials
Change-Id: I4f759c2c4fd1d80cceb0912d7da09d35902e2e5e
2017-10-27 15:40:15 -07:00
dimitry
fa432524a6 Mark __BIONIC_WEAK_FOR_NATIVE_BRIDGE symbols
To make it easier for Native Bridge implementations
to override these symbols.

Bug: http://b/67993967
Test: make
Change-Id: I4c53e53af494bca365dd2b3305ab0ccc2b23ba44
2017-10-27 10:01:46 +02:00
Elliott Hughes
343d1c4953 Don't allow LIBC_DEBUG_MALLOC_OPTIONS to cross security boundaries.
Bug: http://b/68003719
Test: LIBC_DEBUG_MALLOC_OPTIONS=isbad1 MALLOC_CONF=isbad2 su 0 /system/bin/sh -c '/system/bin/echo opt=$LIBC_DEBUG_MALLOC_OPTIONS conf=$MALLOC_CONF'
Change-Id: I796cc21b230a96cb0ed87d02ddcb1706a7749a90
2017-10-26 18:25:19 -07:00
Treehugger Robot
8ae3fe2c50 Merge "Add null checks to <dirent.h> functions." 2017-10-27 01:03:32 +00:00
Elliott Hughes
cc3d04f03a Add null checks to <dirent.h> functions.
Move all the new checks over to the existing __fortify_fatal.

Bug: http://b/67455242
Test: ran tests
Change-Id: Idb899c58c32d52d3b423caf1a91feb7defcba9b3
2017-10-26 16:16:33 -07:00
Elliott Hughes
374848a16e The main thread should just INHERIT its scheduler attributes.
Explicitly setting SCHED_OTHER/0 was causing SELinux denials:

  02-08 09:58:05.430   661   661 I auditd  : type=1400 audit(0.0:20): avc: denied { sys_nice } for comm="grep" capability=23 scontext=u:r:init-qcom-devstart-sh:s0 tcontext=u:r:init-qcom-devstart-sh:s0 tclass=capability permissive=0
  02-08 09:58:05.430   662   662 I auditd  : type=1400 audit(0.0:21): avc: denied { sys_nice } for comm="sed" capability=23 scontext=u:r:init-qcom-devstart-sh:s0 tcontext=u:r:init-qcom-devstart-sh:s0 tclass=capability permissive=0

Also use public pthread API rather than modifying the main thread's
pthread_attr_t directly.

Bug: http://b/68328561
Test: strace -f -e true
Change-Id: I65b7ab3ce285a2901a6eaacb243000c780883c3a
2017-10-26 12:56:21 -07:00
Elliott Hughes
c8a2612ffc Merge "Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched." 2017-10-26 16:12:04 +00:00
Elliott Hughes
8aecba7aa6 Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched.
Historically, Android defaulted to EXPLICIT but with a special case
because SCHED_NORMAL/priority 0 was awkward. Because the code couldn't
actually tell whether SCHED_NORMAL/priority 0 was a genuine attempt to
explicitly set those attributes (because the parent thread is SCHED_FIFO,
say) or just because the pthread_attr_t was left at its defaults.

Now we support INHERIT, we could call sched_getscheduler to see whether
we actually need to call sched_setscheduler, but since the major cost
is the fixed syscall overhead, we may as well just conservatively
call sched_setscheduler and let the kernel decide whether it's a
no-op. (Especially because we'd then have to add both sched_getscheduler
and sched_setscheduler to any seccomp filter.)

Platform code (or app code that only needs to support >= P) can actually
add a call to pthread_attr_setinheritsched to say that they just want
to inherit (if they know that none of their threads actually mess with
scheduler attributes at all), which will save them a sched_setscheduler
call except in the doubly-special case of SCHED_RESET_ON_FORK (which we
do handle).

An alternative would be "make pthread_attr_setschedparams and
pthread_attr_setschedprio set EXPLICIT and change the platform default
to INHERIT", but even though I can only think of weird pathological
examples where anyone would notice that change, that behavior -- of
pthread_attr_setschedparams/pthread_attr_setschedprio overriding an
earlier call to pthread_attr_setinheritsched -- isn't allowed by POSIX
(whereas defaulting to EXPLICIT is).

If we have a lot of trouble with this change in the app compatibility
testing phase, though, we'll want to reconsider this decision!

 -*-

This change also removes a comment about setting the scheduler attributes
in main_thread because we'd have to actually keep them up to date,
and it's not clear that doing so would be worth the trouble.

Also make async_safe_format_log preserve errno so we don't have to be
so careful around it.

Bug: http://b/67471710
Test: ran tests
Change-Id: Idd026c4ce78a536656adcb57aa2e7b2c616eeddf
2017-10-25 14:28:42 -07:00
Elliott Hughes
1d01fe8980 Fix LP32 large pid detection.
Bug: http://b/68046352
Test: ran tests
Change-Id: I89cb99173ca77e9457e677187430b61cedb55c04
2017-10-23 10:07:55 -07:00
Treehugger Robot
8f348a0cce Merge "Remove some legacy declarations from <math.h>." 2017-10-20 18:40:17 +00:00
Treehugger Robot
ac29d9f3b9 Merge "Add POSIX swab." 2017-10-19 21:49:29 +00:00
Elliott Hughes
5c6a7bf0dc Remove some legacy declarations from <math.h>.
These are still needed for backwards compatibility with code built by old
versions of the NDK, but we don't need to pollute the headers with them.

Also lose the hand-written code for these. The compiler-generated code
is either the same or better, and no new code is calling these functions
anyway.

Bug: N/A
Test: ran tests
Change-Id: Ib01ad9805034433e0105aec882608cc8e6526f78
2017-10-19 14:15:31 -07:00
Dimitry Ivanov
1b6de87889 Merge "Make __libc_init_main_thread and android_set_abort_message weak" 2017-10-19 19:53:07 +00:00
dimitry
b6d2b87d2d Make __libc_init_main_thread and android_set_abort_message weak
Bug: http://b/67672033
Bug: http://b/67934730
Test: make && flash and boot angler.
Test: run bionic-unit-tests
Change-Id: Ibf47f00dd7fae19014f56c857eb9712711363029
2017-10-19 18:18:23 +02:00
Elliott Hughes
4d215aad85 Add POSIX fexecve.
I'm skeptical about the usefulness of this, but it's in POSIX, it's
in glibc (but not iOS), and it is used in some internal source (test
runners and container code).

Bug: N/A
Test: ran tests
Change-Id: I92c5398f2a679b21a33fba92bc8e67e3ae2eb76f
2017-10-18 16:26:17 -07:00
Elliott Hughes
fa386e0d1e Add POSIX swab.
Surprisingly to me, there are actual uses of `swab` in the codebases
I have available to search, including one with a #ifndef __ANDROID__
around it.

Bug: N/A
Test: ran tests
Change-Id: Ic91b78ae22bb65c346cb46dd38916f48d979abe0
2017-10-18 13:34:32 -07:00
Elliott Hughes
dff08ced56 Add pthread_setschedprio.
Bug: http://b/26204555
Test: ran tests
Change-Id: Ic34062b9b6036a1ce2642a069514bab48a893338
2017-10-17 09:14:05 -07:00
Elliott Hughes
bf886f621b Merge "Complete <netdb.h>." 2017-10-17 16:03:54 +00:00
Josh Gao
0e0e370154 Add libc_nopthread.
Add a static library containing the non-pthread dependent parts of
libc.

Bug: http://b/64400027
Test: sailfish boots
Test: bionic-unit-tests32/64, no new failures
Test: bionic-unit-tests-static32/64, no new failures
Change-Id: I93dc3811acddad7936d11b369b98cefd945ee2d5
2017-10-16 21:31:37 -07:00
Elliott Hughes
5033918092 Complete <netdb.h>.
Add all the missing <netdb.h> functions.

Also fix getservbyport to handle a null protocol correctly.

Also fix getservbyname/getservbyport to not interfere with getservent.

Also fix endservent to reset getservent iteration.

Also reduce unnecessary differences from upstream NetBSD sethostent.c.

The servent implementation is still horrific, and we should
probably support protoent too so that debugging tools can use
getprotobyname/getprotobynumber.

Bug: N/A
Test: ran tests
Change-Id: I639108c46df0a768af297cf3bbce857cb1bef9d9
2017-10-15 10:37:51 -07:00
Dan Albert
c972ea7da0 Fix missing includes, again.
Test: mma
Bug: None
Change-Id: I17f07e51ebb425ebbcd2cd48e2aa173ab728c498
2017-10-13 14:38:55 -07:00
Elliott Hughes
01bb7bf6fb Merge "Implement <spawn.h>." 2017-10-12 21:02:54 +00:00
Tom Cherry
a08f704e2a Merge "Allow read-only system properties to have arbitrary lengths" 2017-10-12 00:22:57 +00:00
Elliott Hughes
14e3ff9f09 Implement <spawn.h>.
As described here:

  http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html

And here:

  http://man7.org/linux/man-pages/man3/posix_spawn.3.html

Bug: N/A (but mentioned in my inbox since 2013)
Test: ran tests
Change-Id: I0b27b2919b660779e3bd8a25fb429527c16dc621
2017-10-11 14:57:49 -07:00
Dan Albert
1c78cb0fee Add missing includes.
Test: mma
Bug: None
Change-Id: I0221b213e08d07cc5ac0b704a86e98ae8c0f456f
2017-10-11 11:25:52 -07:00
Tom Cherry
8a311631ed Allow read-only system properties to have arbitrary lengths
We need to be able to store build fingerprints that are over 92 characters
long, which is the current restriction for system property value
length.

Increasing the value maximum across the board has plenty of caveats,
particularly that an allocator would be required to handle
deallocation when replacing long property values with short values.
There is also no compelling reasons to do this.

But, increasing the length of simply read-only properties, such as the
build fingerprint, has less caveats as there will never be a
deallocation of these strings.

This change uses spare bits in the top of serial (only spare for
read-only properties) to indicate if a property is 'long' or not.  The
information required to access these 'long' properties is stored in a
union where the legacy property value is located.  An error message is
retained for legacy callers.

The new property is readable via __system_property_read_callback() and
most importantly android::base::GetProperty and higher level (Java,
`getprop`) callers.  All code should move to these higher level
functions as much as possible.

Bug: 23102347
Bug: 34954705
Test: bionic unit tests
Change-Id: Ia85e0d979b92afff601cc52b39114379617a0c64
2017-10-10 15:52:25 -07:00
Treehugger Robot
3dacc47642 Merge "Add a legacy inline for mmap64." 2017-10-06 22:20:54 +00:00
Christopher Ferris
e387c2f088 Merge "Add directives to force stop unwinding." 2017-10-06 17:08:34 +00:00
Dan Albert
a613d0df5c Add a legacy inline for mmap64.
While this was never an inline, this function alone has caused most of
the bug reports related to _FILE_OFFSET_BITS=64. Providing an inline
for it should allow a lot more code to build with _FILE_OFFSET_BITS=64
when targeting pre-L.

Test: make checkbuild
Test: built trivial cc_binary for LP32 against API 14 with
      _FILE_OFFSET_BITS=64 set
Bug: lots
Change-Id: I8479d34af4da358c11423bee43d45b59e9d4143e
2017-10-05 23:41:47 -07:00
Christopher Ferris
93ea09f65c Add directives to force stop unwinding.
On aarch64/x86/x86_64 add a macro that inserts a cfi directive that will
stop unwinding.

For arm, clang doesn't allow emitting .cantunwind, so add a comment and
leave it the same as it current is.

Add this macro to __libc_init and __start_thread.

Also, remove duplicate compilation of libc_init_static.cpp that already
includes the static library that includes that file.

Bug: 15469122

Test: Did unwinds using new unwinder tool (unwind) and debuggerd -b
Test: and verified new unwinder works on aarch64/x86/x86_64.
Test: Verified that it works on old unwinder for aarch64/x86, but
Test: x86_64 doesn't work properly, but as well as before.
Change-Id: I77302e8f6c7ba1549d98a4a164106ee82c9ecadc
2017-10-05 15:18:47 -07:00
Elliott Hughes
3a8f75d8b0 POSIX clock cleanup.
The newest of these clocks was added in Linux 2.6.12, so no need for runtime
checks.

Add CTS tests that we can actually use the various clocks.

Bug: http://b/67458266
Test: ran tests
Change-Id: I3cfd7982043d6f8d4ebdc2b29e8722334f443ce5
2017-10-05 10:33:18 -07:00
Elliott Hughes
c51a404b1a All architectures have AT_SYSINFO_EHDR now.
Bug: N/A
Test: builds
Change-Id: Ibc894be98ed0781c8b991ffadff34f616b934aa7
2017-09-22 13:08:50 -07:00
Elliott Hughes
53dc9dd701 Improve pthread_create failure handling.
Return EAGAIN rather than aborting if we fail to set up the TLS for a new
thread.

Add a test that uses all the VMAs so we can properly test these edge cases.

Add an explicit test for pthread_attr_setdetachstate, which we use in the
previous test, but other than that has no tests.

Remove support for ro.logd.timestamp/persist.logd.timestamp, which doesn't
seem to be used, and which prevents us from logging failures in cases where
mmap fails (because we need to mmap in the system property implementation).

Bug: http://b/65608572
Test: ran tests
Change-Id: I9009f06546e1c2cc55eff996d08b55eff3482343
2017-09-19 14:02:50 -07:00
Treehugger Robot
dacbb04cde Merge "Support larger guard regions." 2017-09-19 01:08:25 +00:00
Christopher Ferris
7a5bb687f4 Merge "Drop thread list lock before abort." 2017-09-19 00:15:32 +00:00
Elliott Hughes
d6c678ca90 Support larger guard regions.
This also fixes a long-standing bug where the guard region would be taken
out of the stack itself, rather than being -- as POSIX demands -- additional
space after the stack. Historically a 128KiB stack with a 256KiB guard would
have given you an immediate crash.

Bug: http://b/38413813
Test: builds, boots
Change-Id: Idd12a3899be1d92fea3d3e0fa6882ca2216bd79c
2017-09-18 16:09:43 -07:00
Christopher Ferris
7982914fae Drop thread list lock before abort.
Bug: 65656273

Test: Ran the app and verified it crashes instead of deadlocks.
Change-Id: I7dbe653d50a635a23993c99c5f73ca094ee80b28
2017-09-18 14:40:35 -07:00
Treehugger Robot
0c9ea17e0c Merge "Always log errno when aborting." 2017-09-18 21:33:54 +00:00
Elliott Hughes
7b0af7ad82 Always log errno when aborting.
(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
2017-09-15 16:18:49 -07:00
Elliott Hughes
50cda38f1d Use __RENAME for long double functions.
We can cut a lot of stuff out of the NDK's libandroid_support with this,
and reduce unnecessary relocations for all LP32 code. LP64 code should
be unaffected.

Bug: https://issuetracker.google.com/64450768
Bug: https://github.com/android-ndk/ndk/issues/507
Test: ran tests, plus manual readelf on the _test.o files
Change-Id: I3de6015921195304ea9c829ef31665cd34664066
2017-09-14 16:10:43 -07:00
Elliott Hughes
4c9d528a25 Merge "Finish <search.h>." 2017-09-11 18:39:30 +00:00
Jayant Chowdhary
ab2f79c0da For devices which are not treble enabled, return the system shell.
For treble enabled devices, still return the appropriate shell depending
on whether the process is a vendor process or a system one.

Test: Manual testing: on a bullhead device, ran test programs from
      /vendor/bin which used popen() and system(). The calls succeeded.

Bug: 65054230

Bug: 64516799

Merged-In: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
Change-Id: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
(cherry picked from commit 1e52871773)
2017-09-07 17:19:21 -07:00
Elliott Hughes
7379018162 <stdbool.h> not necessary in C++.
Bug: N/A
Test: builds
Change-Id: I40fffe92d4273eab5a98bd65013bb9da2aea2171
2017-09-07 13:28:14 -07:00