Skip to contentSkip to conversation

binder: add flag to clear buffer on txn complete

PATCH In review Todd Kjos 2 participants 3 messages Nov 20, 2020 – Nov 21, 2020 Android drivers

lore
Share & tools
lore

Todd Kjos

author
#0 lore raw

PATCH 1/1 binder: add flag to clear buffer on txn complete

Add a per-transaction flag to indicate that the buffer must be cleared when the transaction is complete to prevent copies of sensitive data from being preserved in memory.

---
 drivers/android/binder.c            |  1 +
 drivers/android/binder_alloc.c      | 48 +++++++++++++++++++++++++++++
 drivers/android/binder_alloc.h      |  4 ++-
 include/uapi/linux/android/binder.h |  1 +
 4 files changed, 53 insertions(+), 1 deletion(-)
drivers/android/binder.c +1 -0
index b5117576792b..2a3952925855 100644
@@ -3146,6 +3146,7 @@ static void binder_transaction(struct binder_proc *proc,
 	t->buffer->debug_id = t->debug_id;
 	t->buffer->transaction = t;
 	t->buffer->target_node = target_node;
+	t->buffer->clear_on_free = !!(t->flags & TF_CLEAR_BUF);
 	trace_binder_transaction_alloc_buf(t->buffer);
 
 	if (binder_alloc_copy_user_to_buffer(
drivers/android/binder_alloc.c +48 -0

72 lines not on this page · raw message

drivers/android/binder_alloc.h +3 -1
index 55d8b4106766..6e8e001381af 100644
@@ -23,6 +23,7 @@ struct binder_transaction;
  * @entry:              entry alloc->buffers
  * @rb_node:            node for allocated_buffers/free_buffers rb trees
  * @free:               %true if buffer is free
+ * @clear_on_free:      %true if buffer must be zeroed after use
  * @allow_user_free:    %true if user is allowed to free buffer
  * @async_transaction:  %true if buffer is in use for an async txn
  * @debug_id:           unique ID for debugging
@@ -41,9 +42,10 @@ struct binder_buffer {
 	struct rb_node rb_node; /* free entry by size or allocated entry */
 				/* by address */
 	unsigned free:1;
+	unsigned clear_on_free:1;
 	unsigned allow_user_free:1;
 	unsigned async_transaction:1;
-	unsigned debug_id:29;
+	unsigned debug_id:28;
 
 	struct binder_transaction *transaction;
 
include/uapi/linux/android/binder.h +1 -0
index f1ce2c4c077e..ec84ad106568 100644
@@ -248,6 +248,7 @@ enum transaction_flags {
 	TF_ROOT_OBJECT	= 0x04,	/* contents are the component's root object */
 	TF_STATUS_CODE	= 0x08,	/* contents are a 32-bit status code */
 	TF_ACCEPT_FDS	= 0x10,	/* allow replies with file descriptors */
+	TF_CLEAR_BUF	= 0x20,	/* clear buffer on txn complete */
 };
 
 struct binder_transaction_data {
Signature · 1 line
2.29.2.454.gaff20da3a2-goog
maintainer
#1 lore raw
Quoted 7 lines · Todd Kjos

Add a per-transaction flag to indicate that the buffer must be cleared when the transaction is complete to prevent copies of sensitive data from being preserved in memory.

---

DOes this need to be backported to stable kernels as well?

thanks,

greg k-h

author
#2 lore raw
Quoted 11 lines · Greg KH
Quoted 7 lines · Todd Kjos

Add a per-transaction flag to indicate that the buffer must be cleared when the transaction is complete to prevent copies of sensitive data from being preserved in memory.

---

DOes this need to be backported to stable kernels as well?

It doesn't technically qualify for stable since it is a new feature -- not a bug fix. We will want it for Android S launch devices (5.4+), so it would be handy to have it in 5.4.y and later.

Quoted 8 lines

thanks,

greg k-h

--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].