Drop upstreamed patches

This commit is contained in:
Marius Gripsgard
2024-12-13 05:06:36 +00:00
parent 460e62371d
commit bed242b406
5 changed files with 0 additions and 511 deletions

View File

@@ -1,172 +0,0 @@
From: Ratchanan Srirattanamet <ratchanan@ubports.com>
Date: Sun, 22 Sep 2024 21:52:57 +0700
Subject: [gbinder] correct stability field wire format on Android 12
On Android 12, the wire format of stability field is changed to also
include so-called "Binder wire format version", which starts at 1 [1].
A 32-bit-sized struct is re-interpreted into a 32-bit integer, with a
layout which makes it incompatible with the old version. Interestingly,
they reverted this idea in Android 13 [2], which makes the wire format
of the stability field the same as Android 11 again (as far as I know).
Add a new RPC protocol variant 'aidl4' to account for this difference.
Use this protocol on API level 31 through 32 and use 'aidl3' from API
level 33 onwards. The only difference from 'aidl3' is `finish_flatten_
binder()` function.
Interestingly, there is also a 16-bit-sized struct variant of the field
too [3]. However, to the best of my knowledge, this version is not used
in any of the released Android versions.
[1]: https://github.com/LineageOS/android_frameworks_native/commit/89ddfc5f8c1c9f5bacc6d6d5133bb910d63663a3
[2]: https://github.com/LineageOS/android_frameworks_native/commit/16a4106cb7bc18d473a428d9f19c7561a21e3f06
[3]: https://github.com/LineageOS/android_frameworks_native/commit/14e4cfae36aa878c6a9838299bc7b9aa42a16dfa
Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/133
---
src/gbinder_config.c | 17 ++++++++++++++++-
src/gbinder_rpc_protocol.c | 41 +++++++++++++++++++++++++++++++++++++++++
unit/unit_config/unit_config.c | 18 ++++++++++++++++--
3 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/src/gbinder_config.c b/src/gbinder_config.c
index b467ac5..e0d4bd2 100644
--- a/src/gbinder_config.c
+++ b/src/gbinder_config.c
@@ -135,6 +135,12 @@ static const GBinderConfigPresetGroup gbinder_config_30[] = {
/* API level 31 */
+static const GBinderConfigPresetEntry gbinder_config_31_protocol[] = {
+ { "/dev/binder", "aidl4" },
+ { "/dev/vndbinder", "aidl4" },
+ { NULL, NULL }
+};
+
static const GBinderConfigPresetEntry gbinder_config_31_servicemanager[] = {
{ "/dev/binder", "aidl4" },
{ "/dev/vndbinder", "aidl4" },
@@ -142,14 +148,23 @@ static const GBinderConfigPresetEntry gbinder_config_31_servicemanager[] = {
};
static const GBinderConfigPresetGroup gbinder_config_31[] = {
- { GBINDER_CONFIG_GROUP_PROTOCOL, gbinder_config_30_protocol },
+ { GBINDER_CONFIG_GROUP_PROTOCOL, gbinder_config_31_protocol },
{ GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_31_servicemanager },
{ NULL, NULL }
};
+/* API level 33 - reverts back to AIDL3 protocol */
+
+static const GBinderConfigPresetGroup gbinder_config_33[] = {
+ { GBINDER_CONFIG_GROUP_PROTOCOL, gbinder_config_30_protocol },
+ { GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_30_servicemanager },
+ { NULL, NULL }
+};
+
/* Presets sorted by API level in descending order */
static const GBinderConfigPreset gbinder_config_presets[] = {
+ { 33, gbinder_config_33 },
{ 31, gbinder_config_31 },
{ 30, gbinder_config_30 },
{ 29, gbinder_config_29 },
diff --git a/src/gbinder_rpc_protocol.c b/src/gbinder_rpc_protocol.c
index a4756b1..6bb3169 100644
--- a/src/gbinder_rpc_protocol.c
+++ b/src/gbinder_rpc_protocol.c
@@ -37,6 +37,8 @@
#include "gbinder_log.h"
#include "gbinder_local_object_p.h"
+#include <string.h>
+
#define STRICT_MODE_PENALTY_GATHER (0x40 << 16)
#define BINDER_RPC_FLAGS (STRICT_MODE_PENALTY_GATHER)
#define UNSET_WORK_SOURCE (-1)
@@ -236,6 +238,44 @@ static const GBinderRpcProtocol gbinder_rpc_protocol_aidl3 = {
.finish_flatten_binder = gbinder_rpc_protocol_aidl3_finish_flatten_binder
};
+/*==========================================================================*
+ * AIDL protocol appeared in Android 12 (API level 31), but reverted in
+ * Android 13 (API level 33).
+ *==========================================================================*/
+
+#define BINDER_WIRE_FORMAT_VERSION_AIDL4 1
+struct stability_category {
+ guint8 binder_wire_format_version;
+ guint8 reserved[2];
+ guint8 stability_level;
+};
+G_STATIC_ASSERT(sizeof(struct stability_category) == sizeof(guint32));
+
+static
+void
+gbinder_rpc_protocol_aidl4_finish_flatten_binder(
+ void* out,
+ GBinderLocalObject* obj)
+{
+ struct stability_category cat = {
+ .binder_wire_format_version = BINDER_WIRE_FORMAT_VERSION_AIDL4,
+ .reserved = { 0, 0, },
+ .stability_level = obj ? obj->stability : GBINDER_STABILITY_UNDECLARED,
+ };
+
+ memcpy(out, &cat, sizeof(cat));
+}
+
+static const GBinderRpcProtocol gbinder_rpc_protocol_aidl4 = {
+ .name = "aidl4",
+ .ping_tx = GBINDER_PING_TRANSACTION,
+ .write_ping = gbinder_rpc_protocol_aidl_write_ping, /* no payload */
+ .write_rpc_header = gbinder_rpc_protocol_aidl3_write_rpc_header,
+ .read_rpc_header = gbinder_rpc_protocol_aidl3_read_rpc_header,
+ .flat_binder_object_extra = 4,
+ .finish_flatten_binder = gbinder_rpc_protocol_aidl4_finish_flatten_binder
+};
+
/*==========================================================================*
* The original /dev/hwbinder protocol.
*==========================================================================*/
@@ -289,6 +329,7 @@ static const GBinderRpcProtocol* gbinder_rpc_protocol_list[] = {
&gbinder_rpc_protocol_aidl,
&gbinder_rpc_protocol_aidl2,
&gbinder_rpc_protocol_aidl3,
+ &gbinder_rpc_protocol_aidl4,
&gbinder_rpc_protocol_hidl
};
diff --git a/unit/unit_config/unit_config.c b/unit/unit_config/unit_config.c
index 92fd489..423bed5 100644
--- a/unit/unit_config/unit_config.c
+++ b/unit/unit_config/unit_config.c
@@ -531,11 +531,25 @@ static const TestPresetsData test_presets_data [] = {
"[General]\n"
"ApiLevel = 31\n"
"[Protocol]\n"
- "/dev/binder = aidl3\n"
- "/dev/vndbinder = aidl3\n"
+ "/dev/binder = aidl4\n"
+ "/dev/vndbinder = aidl4\n"
"[ServiceManager]\n"
"/dev/binder = aidl4\n"
"/dev/vndbinder = aidl4\n"
+ },{
+ "33",
+
+ "[General]\n"
+ "ApiLevel = 33",
+
+ "[General]\n"
+ "ApiLevel = 33\n"
+ "[Protocol]\n"
+ "/dev/binder = aidl3\n"
+ "/dev/vndbinder = aidl3\n"
+ "[ServiceManager]\n"
+ "/dev/binder = aidl3\n"
+ "/dev/vndbinder = aidl3\n"
}
};

View File

@@ -1,44 +0,0 @@
From: Ratchanan Srirattanamet <ratchanan@ubports.com>
Date: Wed, 2 Oct 2024 23:16:49 +0700
Subject: [gbinder] use BINDER_TYPE_BINDER for NULL local object
3 reasons:
- This is what encode_remote_object() does. I see no reason a NULL local
object should be encoded differently than a NULL remote object.
- This is what Parcel.cpp does when flattening a NULL binder [1]. This
is contrary to what is said in PR #99 [2]; I'm not sure why PR #99
said it uses BINDER_TYPE_HANDLE.
- More importantly, BINDER_TYPE_HANDLE number 0 does NOT represent a
NULL binder. According to the comment at [3], handle number 0 actually
represent the context manager. So, by sending BINDER_TYPE_HANDLE
number 0, we're sending context manager, not a NULL binder.
[1]: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-14.0.0_r1/libs/binder/Parcel.cpp#277
[2]: https://github.com/mer-hybris/libgbinder/pull/99
[3]: https://android.googlesource.com/platform/frameworks/native/+/refs/tags/android-14.0.0_r1/libs/binder/ProcessState.cpp#336
Origin: vendor
Bug-UBports: https://gitlab.com/ubports/development/core/packaging/libgbinder/-/merge_requests/9#note_2138653925
Forwarded: https://github.com/mer-hybris/libgbinder/pull/135
---
src/gbinder_io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/gbinder_io.c b/src/gbinder_io.c
index 4e37d78..097f278 100644
--- a/src/gbinder_io.c
+++ b/src/gbinder_io.c
@@ -175,12 +175,10 @@ GBINDER_IO_FN(encode_local_object)(
struct flat_binder_object* dest = out;
memset(dest, 0, sizeof(*dest));
+ dest->hdr.type = BINDER_TYPE_BINDER;
if (obj) {
- dest->hdr.type = BINDER_TYPE_BINDER;
dest->flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
dest->binder = (uintptr_t)obj;
- } else {
- dest->hdr.type = BINDER_TYPE_HANDLE;
}
if (protocol->finish_flatten_binder) {
protocol->finish_flatten_binder(dest + 1, obj);

View File

@@ -1,65 +0,0 @@
From: Ratchanan Srirattanamet <ratchanan@ubports.com>
Date: Sun, 13 Oct 2024 02:42:18 +0700
Subject: [gbinder] uses aidl3 servicemanager on API level 31 & 32
Nikita (@NotKit) noticed that the change in commit f227ae4291b3
("[gbinder] All binder objects need stability field in Android 11.
JB#58951") has made the aidl4 servicemanager variant redundant. In fact,
using aidl4 variant will cause an extra stability field to be sent on
the wire (luckily it has not caused any problem).
I've tried using aidl3 variant on Volla Phone X23 which runs Halium 12
(API level 32), and service registration still work, which seems to
validate this theory. Thus, stop using aidl4 servicemanager variant on
any of the API level-based config, as it no longer correspond to any of
Android versions.
Note that this commit doesn't outright remove aidl4 variant, as doing so
would break configurations which explicitly request its use. This commit
doesn't doesn't alias the aidl4 variant to aidl3 variant either.
Manually requesting a certain variant could mean some unusual setup;
aliasing aidl4 to aidl3 could break such setup.
Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/133
---
src/gbinder_config.c | 8 +-------
unit/unit_config/unit_config.c | 4 ++--
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/gbinder_config.c b/src/gbinder_config.c
index e0d4bd2..ac99990 100644
--- a/src/gbinder_config.c
+++ b/src/gbinder_config.c
@@ -141,15 +141,9 @@ static const GBinderConfigPresetEntry gbinder_config_31_protocol[] = {
{ NULL, NULL }
};
-static const GBinderConfigPresetEntry gbinder_config_31_servicemanager[] = {
- { "/dev/binder", "aidl4" },
- { "/dev/vndbinder", "aidl4" },
- { NULL, NULL }
-};
-
static const GBinderConfigPresetGroup gbinder_config_31[] = {
{ GBINDER_CONFIG_GROUP_PROTOCOL, gbinder_config_31_protocol },
- { GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_31_servicemanager },
+ { GBINDER_CONFIG_GROUP_SERVICEMANAGER, gbinder_config_30_servicemanager },
{ NULL, NULL }
};
diff --git a/unit/unit_config/unit_config.c b/unit/unit_config/unit_config.c
index 423bed5..9f526b7 100644
--- a/unit/unit_config/unit_config.c
+++ b/unit/unit_config/unit_config.c
@@ -534,8 +534,8 @@ static const TestPresetsData test_presets_data [] = {
"/dev/binder = aidl4\n"
"/dev/vndbinder = aidl4\n"
"[ServiceManager]\n"
- "/dev/binder = aidl4\n"
- "/dev/vndbinder = aidl4\n"
+ "/dev/binder = aidl3\n"
+ "/dev/vndbinder = aidl3\n"
},{
"33",

View File

@@ -1,226 +0,0 @@
From: Ratchanan Srirattanamet <ratchanan@ubports.com>
Date: Sat, 5 Oct 2024 17:41:55 +0700
Subject: [gbinder] writer: don't write object offset for NULL binder object
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Writing offset will trigger the kernel-side code to transform the flat
binder object into the handle form, which (in my understanding) is not
a valid operation for a NULL binder object. Meanwhile, the receiving
side will create a corresponding Binder object from such handle,
tripping the stability check as it will no longer accept UNDECLARED.
OTOH, if the offset is not written, then the receiving side will receive
the flat binder object as-is, with type BINDER and pointer NULL, which
will be interpreted as NULL binder. This is also what Android's
Parcel.cpp does [1][2].
IMO, this is sort of a hack. Binder kernel driver should handle the NULL
binder internally, and not relying on the sender doing the correct
thing. Meanwhile, the receiver should always reject a flat binder object
of type BINDER. But that's how Android work, so... 🤷
[1]: https://github.com/LineageOS/android_frameworks_native/blob/lineage-19.1/libs/binder/Parcel.cpp#L1327-L1332
[2]: https://github.com/LineageOS/android_frameworks_native/blob/lineage-19.1/libs/binder/Parcel.cpp#L2023-L2029
Origin: vendor
Forwarded: https://github.com/mer-hybris/libgbinder/pull/135
---
src/gbinder_writer.c | 14 ++++++++---
unit/unit_local_reply/unit_local_reply.c | 11 ++-------
unit/unit_local_request/unit_local_request.c | 37 +++++++++++++++++++---------
unit/unit_writer/unit_writer.c | 11 ++-------
4 files changed, 39 insertions(+), 34 deletions(-)
diff --git a/src/gbinder_writer.c b/src/gbinder_writer.c
index d7f8425..1e93700 100644
--- a/src/gbinder_writer.c
+++ b/src/gbinder_writer.c
@@ -1176,8 +1176,11 @@ gbinder_writer_data_append_local_object(
n = data->io->encode_local_object(buf->data + offset, obj, data->protocol);
/* Fix the data size */
g_byte_array_set_size(buf, offset + n);
- /* Record the offset */
- gbinder_writer_data_record_offset(data, offset);
+
+ if (obj) {
+ /* Record the offset */
+ gbinder_writer_data_record_offset(data, offset);
+ }
}
void
@@ -1308,8 +1311,11 @@ gbinder_writer_data_append_remote_object(
n = data->io->encode_remote_object(buf->data + offset, obj);
/* Fix the data size */
g_byte_array_set_size(buf, offset + n);
- /* Record the offset */
- gbinder_writer_data_record_offset(data, offset);
+
+ if (obj) {
+ /* Record the offset */
+ gbinder_writer_data_record_offset(data, offset);
+ }
}
static
diff --git a/unit/unit_local_reply/unit_local_reply.c b/unit/unit_local_reply/unit_local_reply.c
index 6a4abc4..5222e4c 100644
--- a/unit/unit_local_reply/unit_local_reply.c
+++ b/unit/unit_local_reply/unit_local_reply.c
@@ -454,10 +454,7 @@ test_local_object(
reply = test_local_reply_new();
gbinder_local_reply_append_local_object(reply, NULL);
data = gbinder_local_reply_data(reply);
- offsets = gbinder_output_data_offsets(data);
- g_assert(offsets);
- g_assert_cmpuint(offsets->count, == ,1);
- g_assert_cmpuint(offsets->data[0], == ,0);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert_cmpuint(gbinder_output_data_buffers_size(data), == ,0);
g_assert_cmpuint(data->bytes->len, == ,BINDER_OBJECT_SIZE_32);
gbinder_local_reply_unref(reply);
@@ -475,14 +472,10 @@ test_remote_object(
{
GBinderLocalReply* reply = test_local_reply_new();
GBinderOutputData* data;
- GUtilIntArray* offsets;
gbinder_local_reply_append_remote_object(reply, NULL);
data = gbinder_local_reply_data(reply);
- offsets = gbinder_output_data_offsets(data);
- g_assert(offsets);
- g_assert(offsets->count == 1);
- g_assert(offsets->data[0] == 0);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(data->bytes->len == BINDER_OBJECT_SIZE_32);
gbinder_local_reply_unref(reply);
diff --git a/unit/unit_local_request/unit_local_request.c b/unit/unit_local_request/unit_local_request.c
index 9bc6db7..5434cb5 100644
--- a/unit/unit_local_request/unit_local_request.c
+++ b/unit/unit_local_request/unit_local_request.c
@@ -33,6 +33,7 @@
#include "test_common.h"
#include "test_binder.h"
+#include "gbinder_local_object.h"
#include "gbinder_local_request_p.h"
#include "gbinder_output_data.h"
#include "gbinder_rpc_protocol.h"
@@ -40,6 +41,7 @@
#include "gbinder_driver.h"
#include "gbinder_writer.h"
#include "gbinder_io.h"
+#include "gbinder_ipc.h"
#include <gutil_intarray.h>
@@ -432,19 +434,36 @@ void
test_local_object(
void)
{
- GBinderLocalRequest* req = test_local_request_new();
+ GBinderLocalRequest* req;
GBinderOutputData* data;
GUtilIntArray* offsets;
+ GBinderIpc* ipc = gbinder_ipc_new(NULL, NULL);
+ const char* const ifaces[] = { "android.hidl.base@1.0::IBase", NULL };
+ GBinderLocalObject* obj = gbinder_local_object_new(ipc, ifaces, NULL, NULL);
- gbinder_local_request_append_local_object(req, NULL);
+ /* Append a real object */
+ req = test_local_request_new();
+ gbinder_local_request_append_local_object(req, obj);
data = gbinder_local_request_data(req);
offsets = gbinder_output_data_offsets(data);
g_assert(offsets);
- g_assert(offsets->count == 1);
- g_assert(offsets->data[0] == 0);
+ g_assert_cmpuint(offsets->count, == ,1);
+ g_assert_cmpuint(offsets->data[0], == ,0);
+ g_assert_cmpuint(gbinder_output_data_buffers_size(data), == ,0);
+ g_assert_cmpuint(data->bytes->len, == ,BINDER_OBJECT_SIZE_32);
+ gbinder_local_request_unref(req);
+
+ /* Append NULL object */
+ req = test_local_request_new();
+ gbinder_local_request_append_local_object(req, NULL);
+ data = gbinder_local_request_data(req);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(data->bytes->len == BINDER_OBJECT_SIZE_32);
gbinder_local_request_unref(req);
+
+ gbinder_local_object_unref(obj);
+ gbinder_ipc_unref(ipc);
}
/*==========================================================================*
@@ -458,14 +477,10 @@ test_remote_object(
{
GBinderLocalRequest* req = test_local_request_new();
GBinderOutputData* data;
- GUtilIntArray* offsets;
gbinder_local_request_append_remote_object(req, NULL);
data = gbinder_local_request_data(req);
- offsets = gbinder_output_data_offsets(data);
- g_assert(offsets);
- g_assert(offsets->count == 1);
- g_assert(offsets->data[0] == 0);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(data->bytes->len == BINDER_OBJECT_SIZE_32);
gbinder_local_request_unref(req);
@@ -539,12 +554,10 @@ test_remote_request_obj_validate_data(
const GByteArray* bytes = data->bytes;
GUtilIntArray* offsets = gbinder_output_data_offsets(data);
- offsets = gbinder_output_data_offsets(data);
g_assert(offsets);
- g_assert(offsets->count == 3);
+ g_assert(offsets->count == 2);
g_assert(offsets->data[0] == 4);
g_assert(offsets->data[1] == 4 + BUFFER_OBJECT_SIZE_64);
- g_assert(offsets->data[2] == 4 + 2*BUFFER_OBJECT_SIZE_64);
g_assert(bytes->len == 4 + 2*BUFFER_OBJECT_SIZE_64 + BINDER_OBJECT_SIZE_64);
/* GBinderHidlString + the contents (2 bytes) aligned at 8-byte boundary */
g_assert(gbinder_output_data_buffers_size(data) ==
diff --git a/unit/unit_writer/unit_writer.c b/unit/unit_writer/unit_writer.c
index 55565d2..a24a1c1 100644
--- a/unit/unit_writer/unit_writer.c
+++ b/unit/unit_writer/unit_writer.c
@@ -1359,10 +1359,7 @@ test_local_object(
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_local_object(&writer, NULL);
data = gbinder_local_request_data(req);
- offsets = gbinder_output_data_offsets(data);
- g_assert(offsets);
- g_assert_cmpuint(offsets->count, == ,1);
- g_assert_cmpuint(offsets->data[0], == ,0);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert_cmpuint(gbinder_output_data_buffers_size(data), == ,0);
g_assert_cmpuint(data->bytes->len, == ,test->objsize);
gbinder_local_request_unref(req);
@@ -1380,7 +1377,6 @@ test_remote_object(
{
GBinderLocalRequest* req = test_local_request_new_64();
GBinderOutputData* data;
- GUtilIntArray* offsets;
GBinderWriter writer;
TestContext test;
@@ -1388,10 +1384,7 @@ test_remote_object(
gbinder_local_request_init_writer(req, &writer);
gbinder_writer_append_remote_object(&writer, NULL);
data = gbinder_local_request_data(req);
- offsets = gbinder_output_data_offsets(data);
- g_assert(offsets);
- g_assert(offsets->count == 1);
- g_assert(offsets->data[0] == 0);
+ g_assert(!gbinder_output_data_offsets(data));
g_assert(!gbinder_output_data_buffers_size(data));
g_assert(data->bytes->len == BINDER_OBJECT_SIZE_64);
gbinder_local_request_unref(req);

View File

@@ -1,4 +0,0 @@
0001-gbinder-correct-stability-field-wire-format-on-Andro.patch
0002-gbinder-uses-aidl3-servicemanager-on-API-level-31-32.patch
0002-gbinder-use-BINDER_TYPE_BINDER-for-NULL-local-object.patch
0003-gbinder-writer-don-t-write-object-offset-for-NULL-bi.patch