From f5a250ce09e30ea7f2ee4e8b4bef5b3512b8bde8 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 12 Mar 2021 11:39:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A0=E5=85=A5map=5Frange=E5=BF=AB?= =?UTF-8?q?=E9=80=9F=E6=A3=80=E6=9F=A5=EF=BC=8C=E5=A6=82=E6=9E=9Celf?= =?UTF-8?q?=E7=9A=84text=E5=92=8Cdata=E6=9C=89=E9=87=8D=E5=90=88=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E7=AD=89=E5=88=B0=E6=98=A0=E5=B0=84=E6=97=B6?= =?UTF-8?q?=E6=89=8D=E8=BF=94=E5=9B=9E=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/lwp/lwp.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/components/lwp/lwp.c b/components/lwp/lwp.c index 48a820dc99..3826306d98 100644 --- a/components/lwp/lwp.c +++ b/components/lwp/lwp.c @@ -348,6 +348,31 @@ static void expand_map_range(struct map_range *m, void *start, size_t size) } } +static int map_range_ckeck(struct map_range *m1, struct map_range *m2) +{ + int ret = 0; + void *m1_start = (void *)((size_t)m1->start & ~ARCH_PAGE_MASK); + void *m1_end = (void *)((((size_t)m1->start + m1->size) + ARCH_PAGE_MASK) & ~ARCH_PAGE_MASK); + void *m2_start = (void *)((size_t)m2->start & ~ARCH_PAGE_MASK); + void *m2_end = (void *)((((size_t)m2->start + m2->size) + ARCH_PAGE_MASK) & ~ARCH_PAGE_MASK); + + if (m1_start < m2_start) + { + if (m1_end > m2_start) + { + ret = -1; + } + } + else /* m2_start <= m1_start */ + { + if (m2_end > m1_start) + { + ret = -1; + } + } + return ret; +} + static int load_elf(int fd, int len, struct rt_lwp *lwp, uint8_t *load_addr, struct process_aux *aux) { uint32_t i; @@ -507,6 +532,11 @@ static int load_elf(int fd, int len, struct rt_lwp *lwp, uint8_t *load_addr, str break; } } + if (map_range_ckeck(&text_area, &data_area) != 0) + { + result = -RT_ERROR; + goto _exit; + } if (text_area.start) { va = lwp_map_user(lwp, text_area.start, text_area.size, 1); -- Gitee From 76bbc6742bf711f67d74839fb421d942ba1937cf Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Fri, 12 Mar 2021 11:41:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8A=A0=E5=85=A5sys=5Fexecve=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E5=BD=93=E5=89=8Dthread=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E5=8A=9F=E8=83=BD=E5=8F=8Apath=E5=8F=AF=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/lwp/lwp_syscall.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/components/lwp/lwp_syscall.c b/components/lwp/lwp_syscall.c index 14ea2b1c99..ccbcdcc1d1 100644 --- a/components/lwp/lwp_syscall.c +++ b/components/lwp/lwp_syscall.c @@ -1636,6 +1636,12 @@ int sys_execve(const char *path, char *const argv[], char *const envp[]) goto quit; } + len = lwp_user_strlen(path, &access_err); + if (access_err) + { + rt_set_errno(EFAULT); + goto quit; + } if (argv) { while (1) @@ -1758,9 +1764,29 @@ int sys_execve(const char *path, char *const argv[], char *const envp[]) ret = lwp_load(path, new_lwp, RT_NULL, 0, aux); if (ret == RT_EOK) { - /* load ok, now swap the data of lwp and new_lwp */ + int off = 0; + int last_backslash = 0; + + /* find last \ or / */ + while (1) + { + char c = path[off++]; + + if (c == '\0') + { + break; + } + if (c == '\\' || c == '/') + { + last_backslash = off; + } + } + + /* load ok, now set thread name and swap the data of lwp and new_lwp */ rt_hw_interrupt_disable(); + rt_strncpy(thread->name, path + last_backslash, RT_NAME_MAX); + #ifdef RT_USING_USERSPACE _swap_lwp_data(lwp, new_lwp, rt_mmu_info, mmu_info); _swap_lwp_data(lwp, new_lwp, struct lwp_avl_struct *, map_area); -- Gitee