[RAMEN9610-21231]UPSTREAM: binder: check for overflow when alloc for security context
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / drivers / android / binder.c
index afa11e410d33ce8755480942f11797bd3c7ac495..12ec925c954e91b5280112cd1f1cbc60007cf411 100644 (file)
@@ -3242,6 +3242,7 @@ static void binder_transaction(struct binder_proc *proc,
 
        if (target_node && target_node->txn_security_ctx) {
                u32 secid;
+               size_t added_size;
 
                security_task_getsecid(proc->tsk, &secid);
                ret = security_secid_to_secctx(secid, &secctx, &secctx_sz);
@@ -3251,7 +3252,15 @@ static void binder_transaction(struct binder_proc *proc,
                        return_error_line = __LINE__;
                        goto err_get_secctx_failed;
                }
-               extra_buffers_size += ALIGN(secctx_sz, sizeof(u64));
+               added_size = ALIGN(secctx_sz, sizeof(u64));
+               extra_buffers_size += added_size;
+               if (extra_buffers_size < added_size) {
+                       /* integer overflow of extra_buffers_size */
+                       return_error = BR_FAILED_REPLY;
+                       return_error_param = EINVAL;
+                       return_error_line = __LINE__;
+                       goto err_bad_extra_size;
+               }
        }
 
 #ifdef CONFIG_DEBUG_SNAPSHOT_BINDER
@@ -3559,6 +3568,7 @@ err_copy_data_failed:
        t->buffer->transaction = NULL;
        binder_alloc_free_buf(&target_proc->alloc, t->buffer);
 err_binder_alloc_buf_failed:
+err_bad_extra_size:
        if (secctx)
                security_release_secctx(secctx, secctx_sz);
 err_get_secctx_failed: