Commit graph

484 commits

Author SHA1 Message Date
Mark Salyzyn
e37111d751 libcutils: ashmem print error message for invalid fd
NB: We decided to not sniff for the constant saved __ashmem_rdev in
the early error path; requiring either the use of atomic operations,
or acquiring a lock to do it correctly. The heroics are not worth it.

Bug: 26871259
Change-Id: I46249838850ae32063eb5b7d08c731c5bb0fbf6b
2016-02-03 15:06:45 -08:00
Mark Salyzyn
1186f3a5ad libcutils: ashmem check fd validity
- collect st_rdev on open, or when required, for /dev/ashmem.
- check in all cases if fd is a character device and matches rdev.
- requires that we have open, read and write access to /dev/ashmem
  to check, assumption being that if we can not, then we have no
  right playing with the associated misdirected file descriptor.

NB: ashmem libcutil library entry points can no longer be called in
    signal context.

Bug: 26871259
Change-Id: I9a17e33317a9be795131473a51c16f761b5f7407
2016-02-03 13:05:22 -08:00
David Pursell
f6f800ef3c Merge "libcutils/fastboot: improve multi-buffer write." 2016-02-03 18:03:00 +00:00
David Pursell
b34e4a06ee libcutils/fastboot: improve multi-buffer write.
Fixes libcutils multi-buffer write interface to be more friendly and
hooks into it from the fastboot Socket class.

Bug: http://b/26558551
Change-Id: Ibb3a8428fc379755602de52722c1260f9e345bc0
2016-02-03 10:01:38 -08:00
Mark Salyzyn
c2d8aad8d7 libcutils: ashmem fortify and comply with Android coding standard
- sort header order and in groups
- remove all tabs, use only spaces
- use TEMP_FAILURE_RETRY in system calls
- preserve errno for -1 return

Bug: 26871259
Change-Id: I94fffbcaeba01fcc18a3ed07c02389c06c54d3b7
2016-02-02 12:38:06 -08:00
David Pursell
8385fb299f libcutils: add multi-buffer socket send.
Unix and Windows both have functions to write multiple buffers to a
socket with a single call but they have very different signatures. This
CL creates some cross-platform functions to be able to perform these
operations in a uniform way, which will be required for upcoming
fastboot functionality.

This CL also fixes some inconsistent spacing in the touched files.

Bug: http://b/26558551
Change-Id: I8f14d52d3a1de1f3b464267666d6cd3b54263238
2016-02-02 11:18:56 -08:00
David Pursell
756e1c81e8 libcutils: add socket_get_local_port().
Tests that require a local server currently hardcode a test value,
which can run into conflicts depending on what's currently running on
the machine.

This CL adds socket_get_local_port(), which lets us pass 0 so the
system picks an open port and we can query which port it chose.

Bug: http://b/26236380
Change-Id: I01d1558884e7636081d9a357db6faa86929934f6
2016-02-02 09:52:02 -08:00
David Pursell
572bce2908 fastboot: use cutils socket functions.
Now that cutils has cross-platform socket functionality, we can
restructure fastboot to remove platform-dependent networking code.

This CL adds socket_set_receive_timeout() to libcutils and combines the
fastboot socket code into a single implementation. It also adds TCP
functionality to fastboot sockets, but nothing uses it yet except for
the unit tests. A future CL will add the TCP protocol which will use
this TCP socket implementation.

Bug: http://b/26558551

Change-Id: If613fb348f9332b31fa2c88d67fb1e839923768a
2016-01-21 09:53:11 -08:00
David Pursell
1906de1e0f Merge "libcutils: share Windows networking code." 2016-01-21 16:40:00 +00:00
Nick Kralevich
5db8d6aafa logging: avoid unnecessary printfs
Don't spend CPU cycles formatting a bunch of strings if we're
just going to throw them away later. Maybe make booting faster.

Change-Id: I4d8eb99fb3fa873ca91cf776933d0ad01988abf5
2016-01-16 16:20:24 -08:00
David Pursell
0eb8e1b706 libcutils: share Windows networking code.
This CL moves Windows networking code from fastboot to libcutils so
that it can be shared with other host programs such as adb.

Not all libcutils networking functions have been implemented for
Windows, just those necessary for fastboot. In the next CL I will do
the same for adb, adding any additional required functions.

Unit tests have also been added to test the functions using a loopback
connection.

Bug: http://b/26236380.
Change-Id: Ibc51a67030fe69a04c23512eefa9d19b055c7c12
2016-01-15 15:57:35 -08:00
Nick Kralevich
dee1ef48a9 trace-dev.c: more O_CLOEXEC
Stop the file descriptors from leaking.

Change-Id: Ib5ca1c2e5031fbec8751bde9e86b32e51e10fcbc
2015-12-16 12:32:26 -08:00
Elliott Hughes
3918090252 Make host ashmem_create_region more robust.
Don't clobber errno if mkstemp failed, always unlink, and only count
mkstemp/ftruncate failures as real failures --- if only the unlink
fails, there's no point not using what we have.

Change-Id: I6bc788682c88651a50a6316b9ca07ba07e9fefa2
2015-12-16 08:33:52 -08:00
Erik Kline
c40da92e5b Listen on dualstack sockets.
Change-Id: Id6eff59c65a7f7e190ab9aa93625e32a9806ae6c
2015-12-07 16:09:39 +09:00
Nick Kralevich
cbbc66174c fs_config.c: Remove obsolete reference to /system/bin/pppd-ril
Codesearch finds no reference to this in the Android tree. It was
added in 2010 in commit bbf1c64527.

Change-Id: I8cd1153912b78b4b23b8f5ba2577a58c5c49e316
2015-11-30 09:17:18 -08:00
Nick Kralevich
3e6356834f fs_config: remove setuid bit from librank
Anyone wanting to call /system/xbin/librank can execute "su"
beforehand. There's no need for it to be setuid root.

Bug: 25739721
Change-Id: Ie3d68701397d21e901bf1ec17b4b4a9f12128d2d
2015-11-27 18:08:22 -08:00
Josh Gao
1175d0fdb0 libcutils: turn on -Werror on Win32, fix resulting build break.
Mingw doesn't provide strndup or strtok_r used in str_parms.c, resulting in
-Wimplicit-function-declaration being emitted for the Windows build.
None of the consumers of str_parms.c appear to be compiled for Windows,
so we can just remove it from the Windows build.

Change-Id: I36b66fc54ed261d38f5294bc8662ddb2db4fe64f
2015-11-24 09:35:45 -08:00
Josh Gao
9e86f8e036 libcutils: add prefix to local variables in Android.mk.
Change-Id: I0561affbcc306c20f8aa87beb2d9728a9bb79f5e
2015-11-24 08:45:07 -08:00
Josh Gao
cab716f101 Revert "libcutils: don't build for Windows."
This reverts commit bb3f9ce0aa.
2015-11-17 14:28:33 -08:00
Josh Gao
bb3f9ce0aa libcutils: don't build for Windows.
Change-Id: Ice07f892a346bbba2ed6bfdcddf7222799e76f9d
2015-11-16 16:21:22 -08:00
Gilad Arnold
1bc7888104 Fix permissions for /data/nativetest{,64}/tests.txt.
This is not an executable so we have to specifically set its permissions
accordingly.

Bug: 25668833
Change-Id: I502f69bad75b4da4fdc29eb3ebaa42a19ae04d27
2015-11-14 18:25:31 -08:00
Gilad Arnold
47af47f4c1 Sane ownership/permissions for directories in /data/nativetest{,64}.
This makes native test directories 750 root:shell. This matches the
value for files within those directories, and results in a more usable
access paradigm when (say) unprivileged test tools need to discover
these test binaries.

Bug: 25668833
Change-Id: I9bd2081b2c211b4383b5873238aaf64597756714
2015-11-12 14:34:57 -08:00
Daniel Erat
5510c13991 libcutils: Make /data/nativetest{,64}/* executable.
Make test files under /data/nativetest{,64} 0750 root:shell
to avoid needing to manually chmod them.

Bug: 25340994
Change-Id: I174cc226195907c0effa99063a8aa0082f85722b
2015-11-02 09:45:04 -07:00
Christopher Ferris
634df89db6 Make allocations use unique_ptr.
Change-Id: I4b84b8106faeaeb61847f8f9d13fd6444f474efd
2015-10-14 14:03:29 -07:00
Nick Kralevich
e2b2996d96 fs_config.c: remove setuid from procrank
procrank only exists on userdebug/eng builds. For those builds,
procrank can be executed by running "su 0 procrank" instead of
relying on the binary being setuid root. This reduces the number
of setuid binaries on Android and allows for the deletion of
SELinux policy to support this.

Bug: 18342188
Change-Id: I982283f2e0f6fbe5efaffc08501c1ec175f65373
2015-10-07 16:41:47 -07:00
Jorge Lucangeli Obes
fd7a9f79f2 am 66d32c74: Merge "Use CAP_MASK_LONG for file capabilities."
* commit '66d32c7488e12545218e83195738c95c183760ef':
  Use CAP_MASK_LONG for file capabilities.
2015-09-03 15:55:32 +00:00
Jorge Lucangeli Obes
66d32c7488 Merge "Use CAP_MASK_LONG for file capabilities." 2015-09-03 15:48:01 +00:00
Dan Willemsen
a4b8f9f1c2 am bfe32228: Merge "Remove USE_MINGW/CYGWIN; Whitelist windows modules"
* commit 'bfe322285fdbe86fdc01fdc4c711e22e894bdaee':
  Remove USE_MINGW/CYGWIN; Whitelist windows modules
2015-09-03 00:39:19 +00:00
Jorge Lucangeli Obes
e920c46e7d Use CAP_MASK_LONG for file capabilities.
Extract the |1ULL << $CAP_NAME| construct to a macro, to avoid
repeating it.

Change-Id: I9312c27130d7e6c5b6ab3b4cc5c70a6b98378b98
2015-09-02 17:18:44 -07:00
Dan Willemsen
87a419c8b1 Remove USE_MINGW/CYGWIN; Whitelist windows modules
CYGWIN is not supported, USE_MINGW and HOST_OS==windows are being
replaced with LOCAL_..._windows variables.

Bug: 23566667
Change-Id: I3e4a1e4097dc994cf5abdce6939e83a91758fd75
2015-09-02 17:10:35 -07:00
Nick Kralevich
eb45890579 am f4355868: Merge "android_memset.c: Use sanitized shifts"
* commit 'f4355868cbce0713331bbb04b063515d6de4c795':
  android_memset.c: Use sanitized shifts
2015-08-27 23:24:35 +00:00
Duane Sand
c348a88376 android_memset.c: Use sanitized shifts
Avoid checks and traps on msb=1 unsigned shifts.

Change-Id: I5203a4290296b5557c0420ce0debad3b60d48233
2015-08-27 14:32:17 -07:00
Nick Kralevich
b7699c6550 am e6d3cf39: Merge "android_memset.c: Use __attribute__((no_sanitize("integer")))"
* commit 'e6d3cf393749556d6bb6b8ea51bb1252cfb061f3':
  android_memset.c: Use __attribute__((no_sanitize("integer")))
2015-08-27 20:44:40 +00:00
Nick Kralevich
d9eda62875 android_memset.c: Use __attribute__((no_sanitize("integer")))
Turn off integer sanitization on android_memset. memset()ing is
expected to be a fast operation.

Avoid the use of the "while (size--) { }" construct, which harmlessly
underflows.

Change-Id: Ia61ff2323c759bf52df7e70b8be2fae0b0366dda
2015-08-27 13:14:36 -07:00
Nick Kralevich
212e4f1fe1 am d34f4198: Merge "strdup16to8.c: fix benign integer underflow."
* commit 'd34f419826e74640dfe88c50d171a0cd8580eeda':
  strdup16to8.c: fix benign integer underflow.
2015-08-27 18:01:44 +00:00
Nick Kralevich
2b98a9eec0 strdup16to8.c: fix benign integer underflow.
A size_t value is not allowed to go below zero.

Change-Id: Ic888c6605d911e0b5dbee1a2fe1daf41e616e106
2015-08-27 10:30:50 -07:00
Nick Kralevich
3192689b21 am 63141512: am 53f11b62: Merge "libcutils: enable LOCAL_SANITIZE := integer"
* commit '631415129c51a24cd5c9843694bd5283fe3b9345':
  libcutils: enable LOCAL_SANITIZE := integer
2015-08-26 18:51:02 +00:00
Nick Kralevich
78d632a01d am 38f4a139: am 532e6cde: Merge "libcutils: cleanups for -fsanitize=integer"
* commit '38f4a1391e499c2392cd8136061153cc35438eb3':
  libcutils: cleanups for -fsanitize=integer
2015-08-26 18:51:00 +00:00
Nick Kralevich
fc82dd9179 libcutils: enable LOCAL_SANITIZE := integer
Call abort() on undefined or sketchy integer behavior.
Protects against integer overflow attacks.

Tested on Nexus 5 and Nexus 9 with no obvious problems.

Change-Id: I6cb28b4a0f5feed69ea472dfac8804fb0bf99719
2015-08-26 11:32:31 -07:00
Nick Kralevich
7390478f19 libcutils: cleanups for -fsanitize=integer
Hash functions rely on overflow behavior, so whitelist them.

ATRACE_TAG_NOT_READY: use an unsigned constant when shifting bits.
Otherwise, the value overflows on shift. The users of this constant
assign it to a uint64_t variable.

Change-Id: I21c437ce2083525e906c3ead3259ec34a1ef4b66
2015-08-26 10:40:00 -07:00
Elliott Hughes
145afc2cc4 am fb1ecbc5: am e6e71608: Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS."
* commit 'fb1ecbc55e7edeafb138eb2a60ca89ba9a7b1f0f':
  Use __ANDROID__ instead of HAVE_ANDROID_OS.
2015-07-30 16:50:15 +00:00
Elliott Hughes
e6e71608bd Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS." 2015-07-30 16:34:47 +00:00
Elliott Hughes
9b828adfad Use __ANDROID__ instead of HAVE_ANDROID_OS.
Change-Id: I9967f3fd758c2a5b40be5b60ae72be7e2fb75136
2015-07-30 09:33:43 -07:00
Elliott Hughes
c6dbc85845 am 42dbc4b1: am 44443bea: Merge "Use _WIN32 rather than HAVE_WINSOCK."
* commit '42dbc4b1859fe4de16b19e9b74324b345c5fcb9d':
  Use _WIN32 rather than HAVE_WINSOCK.
2015-07-30 15:17:07 +00:00
Elliott Hughes
adbf442a51 Use _WIN32 rather than HAVE_WINSOCK.
Change-Id: I9855b6fe72e2f2f3a8360c0993a67cb988024ee4
2015-07-29 17:45:24 -07:00
Tao Bao
5c151c4a4b am beb13044: am 1cae8cc1: Merge "Set mode bits for /system/etc/recovery.img."
* commit 'beb1304469c916bedf625ab126d75b38a688c62f':
  Set mode bits for /system/etc/recovery.img.
2015-07-28 21:24:21 +00:00
Tao Bao
1cae8cc13a Merge "Set mode bits for /system/etc/recovery.img." 2015-07-28 20:47:00 +00:00
Tao Bao
c6e93fec84 Set mode bits for /system/etc/recovery.img.
/system/etc/recovery.img defaults to 0644. Change it to 0440.

Bug: 22641135
Change-Id: I45cdb0cc1b58f35fbcd0f16e7cc6c4eef63b0b74
(cherry picked from commit b602e6f9a3)
2015-07-27 19:17:15 -07:00
Elliott Hughes
8a8953bb3d Fix libcutils build.
Change-Id: I4df2065f60f5363877809161298c1f9718252934
2015-07-24 20:28:31 -07:00
Elliott Hughes
3dced0d2c6 am 12d912bc: am ed217967: Merge "Fix socket_network_client_timeout error check."
* commit '12d912bc4facd9490becd9d1306a54fd079a8800':
  Fix socket_network_client_timeout error check.
2015-07-25 03:06:47 +00:00