From fca02ee248d2d41977f601cc4c0c7c7fd6aaf972 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Mon, 30 Jul 2018 10:24:07 +0900 Subject: [PATCH] uti: Add error checks to kmalloc of struct uti_attr --- kernel/syscall.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index f54faa2a..7dfa6a01 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -2641,9 +2641,13 @@ retry_tid: if (old->mod_clone_arg) { new->mod_clone_arg = kmalloc(sizeof(struct uti_attr), IHK_MC_AP_NOWAIT); - if (new->mod_clone_arg) - memcpy(new->mod_clone_arg, old->mod_clone_arg, - sizeof(struct uti_attr)); + if (!new->mod_clone_arg) { + kprintf("%s: error: allocating mod_clone_arg\n", + __func__); + return -ENOMEM; + } + memcpy(new->mod_clone_arg, old->mod_clone_arg, + sizeof(struct uti_attr)); } } chain_thread(new); @@ -9239,7 +9243,11 @@ SYSCALL_DECLARE(util_indicate_clone) mod != SPAWN_TO_REMOTE) return -EINVAL; if (arg) { - kattr = kmalloc(sizeof(struct uti_attr), IHK_MC_AP_NOWAIT); + if (!(kattr = kmalloc(sizeof(struct uti_attr), IHK_MC_AP_NOWAIT))) { + kprintf("%s: error: allocating kattr\n", __func__); + return -ENOMEM; + } + if (copy_from_user(kattr, arg, sizeof(struct uti_attr))) { kfree(kattr); return -EFAULT;