Skip to contentSkip to conversation

binder: check offset alignment in binder_get_object()

PATCH In review Carlos Llamas 3 participants 3 messages Mar 30, 2024 – Apr 18, 2024

Subsystems (2)
lore
Share & tools
lore

Carlos Llamas

author maintainer
#0 lore raw

PATCH 1/1 binder: check offset alignment in binder_get_object()

Commit 6d98eb95b450 ("binder: avoid potential data leakage when copying txn") introduced changes to how binder objects are copied. In doing so, it unintentionally removed an offset alignment check done through calls to binder_alloc_copy_from_buffer() -> check_buffer().

These calls were replaced in binder_get_object() with copy_from_user(), so now an explicit offset alignment check is needed here. This avoids later complications when unwinding the objects gets harder.

It is worth noting this check existed prior to commit 7a67a39320df ("binder: add function to copy binder object from buffer"), likely removed due to redundancy at the time.

Fixes 6d98eb95b450 ("binder: avoid potential data leakage when copying txn")
---
 drivers/android/binder.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/android/binder.c +3 -1
index bad28cf42010..dd6923d37931 100644
@@ -1708,8 +1708,10 @@ static size_t binder_get_object(struct binder_proc *proc,
 	size_t object_size = 0;
 
 	read_size = min_t(size_t, sizeof(*object), buffer->data_size - offset);
-	if (offset > buffer->data_size || read_size < sizeof(*hdr))
+	if (offset > buffer->data_size || read_size < sizeof(*hdr) ||
+	    !IS_ALIGNED(offset, sizeof(u32)))
 		return 0;
+
 	if (u) {
 		if (copy_from_user(object, u + offset, read_size))
 			return 0;
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Carlos Llamas

Commit 6d98eb95b450 ("binder: avoid potential data leakage when copying txn") introduced changes to how binder objects are copied. In doing so, it unintentionally removed an offset alignment check done through calls to binder_alloc_copy_from_buffer() -> check_buffer().

These calls were replaced in binder_get_object() with copy_from_user(), so now an explicit offset alignment check is needed here. This avoids later complications when unwinding the objects gets harder.

Quoted 7 lines

It is worth noting this check existed prior to commit 7a67a39320df ("binder: add function to copy binder object from buffer"), likely removed due to redundancy at the time.

Fixes 6d98eb95b450 ("binder: avoid potential data leakage when copying txn")
Quoted 23 lines
---
 drivers/android/binder.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/android/binder.c +3 -2
index bad28cf42010..dd6923d37931 100644
@@ -1708,8 +1708,10 @@ static size_t binder_get_object(struct binder_proc *proc,
        size_t object_size = 0;
 
        read_size = min_t(size_t, sizeof(*object), buffer->data_size - offset);
-       if (offset > buffer->data_size || read_size < sizeof(*hdr))
+       if (offset > buffer->data_size || read_size < sizeof(*hdr) ||
+           !IS_ALIGNED(offset, sizeof(u32)))
                return 0;
+
        if (u) {
                if (copy_from_user(object, u + offset, read_size))
                        return 0;
--

2.44.0.478.gd926399ef9-goog

Reviewed-by on v1 1/1
#2 lore raw
In reply to Carlos Llamas
Quoted 13 lines · Carlos Llamas

Commit 6d98eb95b450 ("binder: avoid potential data leakage when copying txn") introduced changes to how binder objects are copied. In doing so, it unintentionally removed an offset alignment check done through calls to binder_alloc_copy_from_buffer() -> check_buffer().

These calls were replaced in binder_get_object() with copy_from_user(), so now an explicit offset alignment check is needed here. This avoids later complications when unwinding the objects gets harder.

It is worth noting this check existed prior to commit 7a67a39320df ("binder: add function to copy binder object from buffer"), likely removed due to redundancy at the time.

Quoted 6 lines
Fixes 6d98eb95b450 ("binder: avoid potential data leakage when copying txn")
---
 drivers/android/binder.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Thanks for chasing this one down Carlos.

Signature · 1 line
Lee Jones [李琼斯]