From 934036aefee196b29107a5607b515b2f5d247112 Mon Sep 17 00:00:00 2001 From: Xi_Yuhao Date: Tue, 18 Jan 2022 10:46:42 +0800 Subject: [PATCH] Add accesstokenid support and sub-version info to binder driver ohos inclusion category: feature issue: #I4IIRC CVE: NA ----------- tokendid is used for special app security control sub-version info is used for user space ipc version control Signed-off-by: Xi_Yuhao --- drivers/android/binder.c | 14 +++++++++++++- include/uapi/linux/android/binder.h | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index d9977ce0be76..e58dd44eee3d 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -591,6 +591,10 @@ struct binder_transaction { * during thread teardown */ spinlock_t lock; +#ifdef CONFIG_ACCESS_TOKENID + u64 sender_tokenid; + u64 first_tokenid; +#endif /* CONFIG_ACCESS_TOKENID */ }; /** @@ -3088,6 +3092,10 @@ static void binder_transaction(struct binder_proc *proc, else t->from = NULL; t->sender_euid = task_euid(proc->tsk); +#ifdef CONFIG_ACCESS_TOKENID + t->sender_tokenid = current->token; + t->first_tokenid = current->ftoken; +#endif /* CONFIG_ACCESS_TOKENID */ t->to_proc = target_proc; t->to_thread = target_thread; t->code = tr->code; @@ -4447,6 +4455,10 @@ static int binder_thread_read(struct binder_proc *proc, trd->code = t->code; trd->flags = t->flags; trd->sender_euid = from_kuid(current_user_ns(), t->sender_euid); +#ifdef CONFIG_ACCESS_TOKENID + trd->sender_tokenid = t->sender_tokenid; + trd->first_tokenid = t->first_tokenid; +#endif /* CONFIG_ACCESS_TOKENID */ t_from = binder_get_txn_from(t); if (t_from) { @@ -5081,7 +5093,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ret = -EINVAL; goto err; } - if (put_user(BINDER_CURRENT_PROTOCOL_VERSION, + if (put_user(BINDER_CURRENT_PROTOCOL_VERSION + BINDER_SUB_VERSION, &ver->protocol_version)) { ret = -EINVAL; goto err; diff --git a/include/uapi/linux/android/binder.h b/include/uapi/linux/android/binder.h index ec84ad106568..1b75626269a3 100644 --- a/include/uapi/linux/android/binder.h +++ b/include/uapi/linux/android/binder.h @@ -195,6 +195,15 @@ struct binder_version { #define BINDER_CURRENT_PROTOCOL_VERSION 8 #endif +#ifdef CONFIG_ACCESS_TOKENID +#define ENABLE_ACCESS_TOKENID 1 +#else +#define ENABLE_ACCESS_TOKENID 0 +#endif /* CONFIG_ACCESS_TOKENID */ + +#define BINDER_SUB_VERSION_SHIFT_BASE 16 +#define BINDER_SUB_VERSION (ENABLE_ACCESS_TOKENID << BINDER_SUB_VERSION_SHIFT_BASE) + /* * Use with BINDER_GET_NODE_DEBUG_INFO, driver reads ptr, writes to all fields. * Set ptr to NULL for the first call to get the info for the first node, and @@ -284,6 +293,10 @@ struct binder_transaction_data { } ptr; __u8 buf[8]; } data; +#ifdef CONFIG_ACCESS_TOKENID + __u64 sender_tokenid; + __u64 first_tokenid; +#endif /* CONFIG_ACCESS_TOKENID */ }; struct binder_transaction_data_secctx { -- Gitee