Commit Graph

118 Commits

Author SHA1 Message Date
Michael Wachenschwanz 7bb08cbd0c Increment when attempting to read protected Parcel Data
Make sure to increment the parcel data position even when trying to
improperly read from protected data

Bug: 29833520

Test (M): cts-tradefed run cts -c android.os.cts.ParcelTest -m testBinderDataProtection
Test (M): cts-tradefed run cts -c android.os.cts.ParcelTest -m testBinderDataProtectionIncrements
Test: cts-tradefed run cts -m CtsOsTestCases -t android.os.cts.ParcelTest#testBinderDataProtection
Test: cts-tradefed run cts -m CtsOsTestCases -t android.os.cts.ParcelTest#testBinderDataProtectionIncrements

Change-Id: Ie4aae6277fc5f5c924f603d9828c3a608998b986
Merged-In: Ie4aae6277fc5f5c924f603d9828c3a608998b986
(cherry picked from commit 6a825e8ad1a3928dd872bb7c3fbcd94784d77267)
2018-07-16 20:31:32 +02:00
Michael Wachenschwanz d53a5c4aa9 Disallow reading object data from Parcels with non-object reads
The check added to each non-object reads adds an overhead. If the
objects (binders and file descriptors) were written to the Parcel in
sequential order then check adds a small O(1) overhead to each read,
plus an O(N) overhead to the first read (to verify the N objects were
added in order).
If the objects were written out of order (as in by jumping around the
Parcel
with setDataPosition and writing Binder, DON'T DO THIS!!) (writing non
objects out of order is fine), the first read is forced to sort the
objects
in the internal bookkeeping. Based on the assumption non sequential
writes
are infrequent and overall Parcels are probably mostly sorted, insertion
sort was used. Worst case sorts will add an O(N^2) overhead to the first
non object read from the Parcel.

Test: run cts -m CtsOsTestCases -t android.os.cts.ParcelTest

Bug: 29833520
Change-Id: I82de8eb5f5eb56f869542d5358e96884c24301b2
(cherry picked from commit c517681c66a1a387be657e0cf06da8d19659dd14)
2018-07-16 20:31:22 +02:00
Martijn Coenen 057269956b Don't pad before calling writeInPlace().
writeInplace() itself already pads securely, by masking off
the padded bytes. If the padding is done before calling
writeInplace(), no mask is applied, and heap data can leak.

Bug: 77237570
Test: builds
Change-Id: Ide27a0002d4ed4196530430760245b971f6a3f44
Merged-In: Ide27a0002d4ed4196530430760245b971f6a3f44

(cherry picked from commit f8542381b72a7bb2452a5278a00ca8c34edbf8a0)
(cherry picked from commit 732132b765cd7b667f16cf32f0fe4c852d7d44dd)

Change-Id: Id65e4573e18ab68b804f1cf63a6977a71da01e5d
2018-07-16 20:24:36 +02:00
Christopher Tate 0ff545d4a7 Correct overflow check in Parcel resize code
Fix merge conflict into nyc-mr1-release
Bug 31929765

Change-Id: Ie27b9945f1de056624668869bdf9a5578abff467
(cherry picked from commit 65dd433f0db2fe402dc725f7012c6e26769b3224)
(cherry picked from commit b4d6b292bce7d82c93fd454078dedf5a1302b9fa)
2017-03-13 04:55:32 +00:00
Mark Salyzyn 839f0dd964 system_server BINDER_TYPE_FD driver ashmem accessors
check if device matches the ashmem rdev, before calling
ashmem_get_size_region. This eliminates making this call
when associated with other driver file descriptors.

Bug: 26374183
Bug: 26918423
Bug: 26871259
Change-Id: I1f88c2c93ea35a73c8e14125f3d1a6c67fa4f15b
2016-07-15 13:04:30 -07:00
Mark Salyzyn d70043eaf4 system_server BINDER_TYPE_FD sockets using ashmem accessors
check if device is a character device, before calling
ashmem_get_size_region. We do not check if the st_rdev
matches /dev/ashmem. So this at least eliminates making
this call when associated with a socket.

Bug: 26374183
Change-Id: I68ed9d1c2cd4c47228ed065e3e18eb4151f038f4
2016-07-15 13:04:30 -07:00
Mark Salyzyn e481771aa3 Parcel: file descriptor leak
Resolve a file descriptor leak when a request for
ashmem size adjustment is not filed.

Change-Id: I4ebccfd096ec5313725fd99dc3e025f9561d061f
2016-07-15 13:04:30 -07:00
Jessica Wagantall cf27ee8089 Merge remote-tracking branch 'remotes/android-6.0.1_r52' into HEAD
Ticket: CYNGNOS-3020

Change-Id: I13076de5caf1546b8eef44417ee83cd9b2cb9d62
2016-07-07 14:15:35 -07:00
Marco Nelissen 54cb02ad73 Correctly handle dup() failure in Parcel::readNativeHandle
bail out if dup() fails, instead of creating an invalid native_handle_t

Bug: 28395952

Change-Id: Ia1a6198c0f45165b9c6a55a803e5f64d8afa0572
2016-05-27 11:31:22 -07:00
forkbomb 7cacf26abb libbinder: allow devices to disable ashmem size tracking
The addition of ashmem size tracking can lead to parcel objects
overwriting other values on the stack in old binary blobs.

Change-Id: Ife8514be1ba639c4061de38b59794c46bcc2d7f8
2015-12-10 10:15:49 +11:00
Adrian Roos 6bb3114246 Maintain Parcel ABI
Makes sure we don't change the memory layout of the Parcel class
to maintain binary compatibility with prebuilts linking against
libbinder.

Bug: 25004154
Change-Id: I656687497f08bb85cefda796aafa2341e601e30a
2015-10-22 17:48:16 -07:00
Adrian Roos cbf3726357 Revert "Revert "Track ashmem memory usage in Parcel""
This reverts commit 6880307e8e.

Bug: 25004154
Change-Id: I9b432d1ebc39f3bbcd7afdefc403f0fb6ced8158
2015-10-22 17:47:27 -07:00
Ian Pedowitz 6880307e8e Revert "Track ashmem memory usage in Parcel"
This reverts commit e2f499fb73.

Bug: 25169267
Bug: 25191602
Bug: 25004154
Change-Id: I24bb0da4e8739ee5a0c251e4adac9904827144e0
2015-10-22 22:09:16 +00:00
Adrian Roos e2f499fb73 Track ashmem memory usage in Parcel
Bug: 25004154
Change-Id: Id9d5656dd0605f1b50525596b75601309f67ebdc
2015-10-21 22:32:35 +00:00
Chad Brubaker e59cb43eda Fix writeByteArray/writeInt32Array size on x64
writeByteArray writes the size using sizeof(size_t), however it is always
read using readInt32(). On devices where sizeof(size_t) != 4 this causes
extra bytes to be written.

BUG: 22204736
Change-Id: I8d4507b6b616857ef5827f1fe9da0907d09abf0e
2015-06-30 14:50:09 -07:00
Christopher Tate ed7a50cc7d Prevent integer overflow when calculating buffer resizes
Make sure that we don't go haywire if an exponential buffer growth
operation winds up wrapping integer range.  Along the way, fix a
bookkeeping bug in BufferedTextOutput that would cause it to keep
spuriously realloc()ing on every append().

Bug 20674694

Change-Id: Ia845b7de36b90672a151a918ffc26c7da68e20a2
2015-06-08 14:49:09 -07:00
Christopher Tate 98e67d352b Don't corrupt parcel when writeFileDescriptor() fails
We now check for fd-legality before committing binder objects to
the flattened data buffer rather than after.  Previously we would
wind up corrupting the parcel and incurring driver-level errors,
as well as potentially leaking FDs.

Bug 21428802

Change-Id: Ice0d641b3dcc41fb1b8c68ce2e2ebd744c2863a1
2015-06-08 13:13:19 -07:00
Jeff Brown 13b1604018 Enable more flexible usage of blobs in parcels.
Add functions to allow a client to take over the ashmem region
that was transferred so that it can claim it for its own and
reuse it.

Add support for mutable ashmem regions too.

Bug: 21428802
Change-Id: I16eca338cdb99b07d81fc43573d53ce86dbc60c8
2015-06-05 17:40:59 -07:00
Tim Kilbourn 9e6d2ee030 DO NOT MERGE Remove unused ParcelFileDescriptor methods in parcel.
Attempts to replicate Java parceling in native code is fraught with
peril.

Change-Id: I4359036c5dddd1b886d886beef1d060523e53e5f
(cherry picked from commit f47a381001)
2015-06-04 21:36:21 +00:00
Christopher Tate 27182be9f2 Disregard alleged binder entities beyond parcel bounds
When appending one parcel's contents to another, ignore binder
objects within the source Parcel that appear to lie beyond the
formal bounds of that Parcel's data buffer.

Bug 17312693

Change-Id: If592a260f3fcd9a56fc160e7feb2c8b44c73f514
2015-05-27 19:20:15 -07:00
Adam Lesinski eaac99a717 Verify that the native handle was created
The inputs to native_handle_create can cause an overflowed allocation,
so check the return value of native_handle_create before accessing
the memory it returns.

Bug:19334482
Change-Id: I1f489382776c2a1390793a79dc27ea17baa9b2a2
2015-05-12 17:35:48 -07:00
Nick Kralevich e9881a3961 Parcel.cpp: use calloc instead of malloc
(cherrypicked from commit 6329f0199e)

Bug: 20669363
Change-Id: Ia4c8d8ca9d8b4b87954d7267e8b1c94cf4e570e1
2015-04-28 21:31:20 -07:00
Dan Sandler aa5c2346c7 Add ashmem stats to Parcels
Requires change Ifaf115da in frameworks/base.

Bug: 20079551
Change-Id: Ifaf115dabd1a59cdb1b46e2d49c41f64ac107de4
2015-04-16 04:08:53 +00:00
Nick Kralevich b6b1423c87 Parcel.cpp: reject size_t arguments greater than INT32_MAX
It's a security best practice for size_t values to be rejected if
they are greater than INT32_SIZE. This is intended to prevent the
common error of inadvertently passing a negative int value to a
function, which after conversion to an unsigned type, becomes a huge
number, defeating the purpose of bounds checking.

This patch also addresses a bug where the call to:
  Parcel::write(buf, (size_t) -1);
would call writeInPlace() which uses PAD_SIZE on the supplied
argument. This would then cause an integer overflow, with PAD_SIZE
returning a small value, but the memcpy in Parcel::write using the
old large length value.

Bug: 19573085
Change-Id: Ib11bfb3dae4f3be91cd17b2c676926700972c7b8
2015-04-02 10:56:12 -07:00
Ronghua Wu 2d13afdfa1 binder: add uint64 support to Parcel.
Bug: 19620911
Change-Id: Ifce5319e4e35afd344dead67ab7ba1cd399476a3
2015-03-19 16:45:04 -07:00
Jeff Sharkey 499127eab8 am 8f3ade0c: Merge "Follow StrictMode refactoring."
* commit '8f3ade0c9ab52a1e4f13d6ff1922dd98e3ccdbcc':
  Follow StrictMode refactoring.
2015-01-16 06:07:31 +00:00
Jeff Sharkey 0c1f5cbb8a Follow StrictMode refactoring.
Bug: 18335678
Change-Id: Iea920cfa26b5ebfd77b4601c9e6e65b21599342a
2015-01-14 10:58:52 -08:00
Dan Stoza e4ea03f74d am 80e81505: Merge "binder: Add {read,write}Uint32 methods to Parcel"
* commit '80e8150549c9d8380dadf942336d41ab3d92bf78':
  binder: Add {read,write}Uint32 methods to Parcel
2014-12-01 19:27:00 +00:00
Dan Stoza 41a0f2f86c binder: Add {read,write}Uint32 methods to Parcel
Adds readUint32 and writeUint32 methods to the Parcel class. This
saves a lot of static_casting in anything implementing a Binder
interface on the native side.

Change-Id: Iafc73b0633654a3a4c49767f41806b56906c924f
2014-12-01 11:13:11 -08:00
Dan Albert c1ced8bbcd am c894c204: Merge "C++11 compatibility."
* commit 'c894c2045f589571c80af0648e7a9dcd7e97b6a8':
  C++11 compatibility.
2014-11-20 23:00:48 +00:00
Dan Albert 3bdc5b8268 C++11 compatibility.
* Explicit conversion for atomic_uintptr_t initialization.
 * Fix string literal concatenation to not be a UD literal.
 * Use __typeof__ instead of typeof (should become decltype once this
   actually moves to C++11).

Bug: 18466763
Change-Id: I4eedddfb945a2a703ed27317cb6e2b3041b1ebfc
2014-11-20 21:04:35 +00:00
Dianne Hackborn a4cff88d80 Fix issue #18356768: some app process may hang at Runtime#exit...
...in Parcel destructor

Don't use a Mutux object, just use simple posix mutex primitives,
to avoid static init/destroy order problems.

Change-Id: Ic012d94297564c0a55d58869f8276d7d10545fbc
2014-11-13 17:09:59 -08:00
Dianne Hackborn 7e790af756 Add tracking of parcel memory allocations.
Change-Id: I76ffed0e69ccfe70e87d98646f11d4de7c3fd980
2014-11-11 16:23:04 -08:00
Jesse Hall fee99040de Revert "Add more logging for dup(fd) failure"
Underlying bug has been fixed, extra debug code no longer needed

This reverts commit 36273c991b.

Change-Id: Ia47f1ae9ee7338329bfb8d710aff57e15e944f20
2014-11-04 08:48:16 -08:00
Jesse Hall 8e5cf83afb Revert "Parcel: extra validation/debug code for writeDupFileDescriptor"
Underlying bug has been fixed, extra debug code no longer needed.

This reverts commit ccf851f108.

Change-Id: I19ad9239efdf1d8f70cd74af9b7c2ae97713208f
2014-11-04 08:47:57 -08:00
Narayan Kamath 9ea09757fa Fix broken error check in Parcel::readBlob
mmap returns MAP_FAILED (which is -1) and not NULL on
failure.

Diagnosed by cferris.

bug: 17909809

Change-Id: I609788ebf94742ef88af002d2d3f3bc9b9e520ac
2014-10-08 17:37:38 +01:00
Jesse Hall ccf851f108 Parcel: extra validation/debug code for writeDupFileDescriptor
Temporary extra debug validation for b/17477219: a Parcel recipient is
getting a positive but invalid fd unexpectedly. Trying to track down
where it's coming from.

Debug code for bug: 17477219
Change-Id: Idb1e71621025a3928c7adc88fd44790e1abd2a01
2014-10-06 15:23:56 -07:00
Michael Lentine 36273c991b Add more logging for dup(fd) failure
Bug: 17477219
Change-Id: Ide0ae16d777c9af783023c705c18a93c00999147
2014-10-02 18:13:02 +00:00
Narayan Kamath 7da40c0a84 Remove Parcel::writeIntPtr.
All uses of this API have been removed. It should
never have been made public in the first place.

bug: 15424960
Change-Id: Id07d24ec95b2b393e6da138a7e8a9a4ecebeca94
2014-06-12 15:26:39 +01:00
Narayan Kamath 87947be618 Merge "Fix mips build for libbinder." 2014-06-04 14:32:59 +00:00
Narayan Kamath 2c68d380c9 Fix mips build for libbinder.
Mips specific code was using an uninitialized variable.

Change-Id: I445043c76ebfa420b26376ade60f8068b4ea0b11
2014-06-04 15:05:13 +01:00
Mark Salyzyn b09b936d8e am f0a24759: am a28750ee: Merge "binder: Turn on -Werror"
* commit 'f0a2475905786d5457e7af838ac714acbfdafa4f':
  binder: Turn on -Werror
2014-06-03 20:54:48 +00:00
Mark Salyzyn f0a2475905 am a28750ee: Merge "binder: Turn on -Werror"
* commit 'a28750eec38c848230adfeef28725b29cc36a9da':
  binder: Turn on -Werror
2014-06-03 20:48:35 +00:00
Mark Salyzyn d4ecccfd20 binder: Turn on -Werror
Change-Id: I0ee785927a7ae5f731b02176b0b781b87c22a24e
2014-06-03 11:11:45 -07:00
Jesse Hall 13de7f1def am 57fdbbda: am 4314ccd1: am 70278fbf: Merge "Add error message for hints when exceptions occur during binder transactions."
* commit '57fdbbda2c475d2abdd828177f942ddb6d164bef':
  Add error message for hints when exceptions occur during binder transactions.
2014-05-05 17:33:01 +00:00
Jesse Hall 57fdbbda2c am 4314ccd1: am 70278fbf: Merge "Add error message for hints when exceptions occur during binder transactions."
* commit '4314ccd1ba9fe773b0fc91f0a08dc536ebce8dfe':
  Add error message for hints when exceptions occur during binder transactions.
2014-05-05 17:30:19 +00:00
Jesse Hall 4314ccd1ba am 70278fbf: Merge "Add error message for hints when exceptions occur during binder transactions."
* commit '70278fbfe012c1fce3e63a41ffb9feaf1e53a64a':
  Add error message for hints when exceptions occur during binder transactions.
2014-05-05 17:27:46 +00:00
Jun Jiang abf8a2c608 Add error message for hints when exceptions occur during binder transactions.
It can help to detect some kind of error, such as why GraphicBuffer::flatten
will crash when handle is null.

Change-Id: I703cd035b96edb7afb324cf24d8230d4e55f4f52
Signed-off-by: Jun Jiang <jun.a.jiang@intel.com>
2014-04-29 14:22:10 +08:00
Kenny Root 75d8406934 am ca609e43: am 38e2aaaa: am 5b61ad2c: Check the padded size of the read byte array
* commit 'ca609e4300d88ad1e815581ebc6a478b446d3882':
  Check the padded size of the read byte array
2014-03-17 23:32:59 +00:00
Kenny Root ca609e4300 am 38e2aaaa: am 5b61ad2c: Check the padded size of the read byte array
* commit '38e2aaaa3dd62a20eb211808ae6fe45ec37ee6d5':
  Check the padded size of the read byte array
2014-03-17 21:31:04 +00:00