From patchwork Mon Jun 27 10:30:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhou Chengming X-Patchwork-Id: 9200295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5DC860752 for ; Mon, 27 Jun 2016 10:35:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2D0528566 for ; Mon, 27 Jun 2016 10:35:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2E7F28587; Mon, 27 Jun 2016 10:35:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A711C28566 for ; Mon, 27 Jun 2016 10:35:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHTr1-0007DN-Ee; Mon, 27 Jun 2016 10:33:23 +0000 Received: from szxga03-in.huawei.com ([119.145.14.66]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bHTqw-0007A1-7T for linux-arm-kernel@lists.infradead.org; Mon, 27 Jun 2016 10:33:20 +0000 Received: from 172.24.1.137 (EHLO szxeml432-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CDZ10624; Mon, 27 Jun 2016 18:31:03 +0800 (CST) Received: from [127.0.0.1] (10.177.236.183) by szxeml432-hub.china.huawei.com (10.82.67.209) with Microsoft SMTP Server id 14.3.235.1; Mon, 27 Jun 2016 18:30:53 +0800 Message-ID: <5771005B.3060605@huawei.com> Date: Mon, 27 Jun 2016 18:30:51 +0800 From: zhouchengming User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Yury Norov Subject: Re: [PATCH] ilp32: fix {GET,SET}SIGMASK request for ptrace References: <1466207668-10549-1-git-send-email-ynorov@caviumnetworks.com> <1466207668-10549-13-git-send-email-ynorov@caviumnetworks.com> <5770B041.3040509@huawei.com> <20160627053916.GA305@yury-N73SV> In-Reply-To: <20160627053916.GA305@yury-N73SV> X-Originating-IP: [10.177.236.183] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.57710069.007B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 06023bf1960e5def1aad9a2474dde5f2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160627_033319_113598_4BB769BA X-CRM114-Status: GOOD ( 21.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-doc@vger.kernel.org, szabolcs.nagy@arm.com, catalin.marinas@arm.com, heiko.carstens@de.ibm.com, philipp.tomsich@theobroma-systems.com, joseph@codesourcery.com, linux-arch@vger.kernel.org, Prasun.Kapoor@caviumnetworks.com, agraf@suse.de, geert@linux-m68k.org, kilobyte@angband.pl, manuel.montezelo@gmail.com, arnd@arndb.de, pinskia@gmail.com, linyongting@huawei.com, klimov.linux@gmail.com, broonie@kernel.org, bamvor.zhangjian@huawei.com, linux-arm-kernel@lists.infradead.org, maxim.kuvyrkov@linaro.org, libc-alpha@sourceware.org, Nathan_Lynch@mentor.com, linux-kernel@vger.kernel.org, schwidefsky@de.ibm.com, davem@davemloft.net, christoph.muellner@theobroma-systems.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 2016/6/27 13:39, Yury Norov wrote: > Hi Zhou, > > Thank you for the patch. The idea is ok, but patch format got broken > for some reason. Could you re-send it? > > Yury. Sorry for the broken patch, maybe my mail guest has some problems. So I send the patch as an attachment. Thanks! > > On Mon, Jun 27, 2016 at 12:49:05PM +0800, zhouchengming wrote: >> atus: RO >> Content-Length: 4732 >> Lines: 181 >> >> The function compat_ptrace_request(used by ilp32) don't handle >> {GET,SET}SIGMASK request, so it will be handled by ptrace_request. >> But it's wrong because the compat_sigset_t of ilp32 differs from >> the sigset_t of aarch64. The patch fixes it. >> >> Signed-off-by: Zhou Chengming >> --- >> arch/arm64/include/asm/signal_ilp32.h | 22 ++++++++++++ >> arch/arm64/kernel/ptrace.c | 62 >> +++++++++++++++++++++++++++++++++ > > Here - unneeded line break > >> arch/arm64/kernel/signal_ilp32.c | 23 +------------ >> 3 files changed, 85 insertions(+), 22 deletions(-) >> >> diff --git a/arch/arm64/include/asm/signal_ilp32.h >> b/arch/arm64/include/asm/signal_ilp32.h > > and here > >> index 30eff23..ed52607 100644 >> --- a/arch/arm64/include/asm/signal_ilp32.h >> +++ b/arch/arm64/include/asm/signal_ilp32.h >> @@ -21,6 +21,28 @@ >> int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, >> struct pt_regs *regs); >> >> +static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) >> +{ >> + compat_sigset_t cset; >> + >> + cset.sig[0] = set->sig[0]& 0xffffffffull; >> + cset.sig[1] = set->sig[0]>> 32; >> + >> + return copy_to_user(uset,&cset, sizeof(*uset)); >> +} >> + >> +static inline int get_sigset_t(sigset_t *set, >> + const compat_sigset_t __user *uset) >> +{ >> + compat_sigset_t s32; >> + >> + if (copy_from_user(&s32, uset, sizeof(*uset))) >> + return -EFAULT; >> + >> + set->sig[0] = s32.sig[0] | (((long)s32.sig[1])<< 32); >> + return 0; >> +} >> + >> #else >> >> static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, >> sigset_t *set, > > and here > >> diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c >> index a861105..8d4cad1 100644 >> --- a/arch/arm64/kernel/ptrace.c >> +++ b/arch/arm64/kernel/ptrace.c >> @@ -44,6 +44,7 @@ >> #include >> #include >> #include >> +#include >> >> #define CREATE_TRACE_POINTS >> #include >> @@ -1231,12 +1232,73 @@ COMPAT_SYSCALL_DEFINE4(aarch32_ptrace, >> compat_long_t, request, compat_long_t, pi > > and later on the patch > >> >> #endif /* CONFIG_AARCH32_EL0 */ >> >> +#ifdef CONFIG_ARM64_ILP32 >> + >> +static int compat_ilp32_ptrace(struct task_struct *child, compat_long_t >> request, >> + compat_ulong_t addr, compat_ulong_t data) >> +{ >> + compat_ulong_t __user *datap = compat_ptr(data); >> + int ret; >> + >> + switch (request) { >> + case PTRACE_GETSIGMASK: >> + if (addr != sizeof(compat_sigset_t)) { >> + ret = -EINVAL; >> + break; >> + } >> + >> + if (put_sigset_t((compat_sigset_t __user *)datap,&child->blocked)) >> + ret = -EFAULT; >> + else >> + ret = 0; >> + break; >> + >> + case PTRACE_SETSIGMASK: { >> + sigset_t new_set; >> + if (addr != sizeof(compat_sigset_t)) { >> + ret = -EINVAL; >> + break; >> + } >> + >> + if (get_sigset_t(&new_set, (compat_sigset_t __user *)datap)) { >> + ret = -EFAULT; >> + break; >> + } >> + >> + sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); >> + >> + /* >> + * Every thread does recalc_sigpending() after resume, so >> + * retarget_shared_pending() and recalc_sigpending() are not >> + * called here. >> + */ >> + spin_lock_irq(&child->sighand->siglock); >> + child->blocked = new_set; >> + spin_unlock_irq(&child->sighand->siglock); >> + >> + ret = 0; >> + break; >> + } >> + >> + default: >> + ret = compat_ptrace_request(child, request, addr, data); >> + } >> + >> + return ret; >> +} >> + >> +#endif /* CONFIG_ARM64_ILP32 */ >> + >> #ifdef CONFIG_COMPAT >> >> long compat_arch_ptrace(struct task_struct *child, compat_long_t request, >> compat_ulong_t caddr, compat_ulong_t cdata) >> { >> +#ifdef CONFIG_ARM64_ILP32 >> + return compat_ilp32_ptrace(child, request, caddr, cdata); >> +#else >> return compat_ptrace_request(child, request, caddr, cdata); >> +#endif >> } >> >> #endif /* CONFIG_COMPAT */ >> diff --git a/arch/arm64/kernel/signal_ilp32.c >> b/arch/arm64/kernel/signal_ilp32.c >> index 8ca64b9..3ef2749 100644 >> --- a/arch/arm64/kernel/signal_ilp32.c >> +++ b/arch/arm64/kernel/signal_ilp32.c >> @@ -28,6 +28,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -58,28 +59,6 @@ struct ilp32_rt_sigframe { >> struct ilp32_sigframe sig; >> }; >> >> -static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) >> -{ >> - compat_sigset_t cset; >> - >> - cset.sig[0] = set->sig[0]& 0xffffffffull; >> - cset.sig[1] = set->sig[0]>> 32; >> - >> - return copy_to_user(uset,&cset, sizeof(*uset)); >> -} >> - >> -static inline int get_sigset_t(sigset_t *set, >> - const compat_sigset_t __user *uset) >> -{ >> - compat_sigset_t s32; >> - >> - if (copy_from_user(&s32, uset, sizeof(*uset))) >> - return -EFAULT; >> - >> - set->sig[0] = s32.sig[0] | (((long)s32.sig[1])<< 32); >> - return 0; >> -} >> - >> static int restore_ilp32_sigframe(struct pt_regs *regs, >> struct > > . > From 06f5abeca59069cb41b0b4fdfa06240d3f78910d Mon Sep 17 00:00:00 2001 From: Zhou Chengming Date: Mon, 27 Jun 2016 12:57:02 +0800 Subject: [PATCH] ilp32: fix {GET,SET}SIGMASK request for ptrace The function compat_ptrace_request(used by ilp32) don't handle {GET,SET}SIGMASK request, so it will be handled by ptrace_request. But it's wrong because the compat_sigset_t of ilp32 differs from the sigset_t of aarch64. The patch fixes it. Signed-off-by: Zhou Chengming --- arch/arm64/include/asm/signal_ilp32.h | 22 ++++++++++++ arch/arm64/kernel/ptrace.c | 62 +++++++++++++++++++++++++++++++++ arch/arm64/kernel/signal_ilp32.c | 23 +------------ 3 files changed, 85 insertions(+), 22 deletions(-) diff --git a/arch/arm64/include/asm/signal_ilp32.h b/arch/arm64/include/asm/signal_ilp32.h index 30eff23..ed52607 100644 --- a/arch/arm64/include/asm/signal_ilp32.h +++ b/arch/arm64/include/asm/signal_ilp32.h @@ -21,6 +21,28 @@ int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, struct pt_regs *regs); +static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) +{ + compat_sigset_t cset; + + cset.sig[0] = set->sig[0] & 0xffffffffull; + cset.sig[1] = set->sig[0] >> 32; + + return copy_to_user(uset, &cset, sizeof(*uset)); +} + +static inline int get_sigset_t(sigset_t *set, + const compat_sigset_t __user *uset) +{ + compat_sigset_t s32; + + if (copy_from_user(&s32, uset, sizeof(*uset))) + return -EFAULT; + + set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32); + return 0; +} + #else static inline int ilp32_setup_rt_frame(int usig, struct ksignal *ksig, sigset_t *set, diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index a861105..8d4cad1 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -44,6 +44,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -1231,12 +1232,73 @@ COMPAT_SYSCALL_DEFINE4(aarch32_ptrace, compat_long_t, request, compat_long_t, pi #endif /* CONFIG_AARCH32_EL0 */ +#ifdef CONFIG_ARM64_ILP32 + +static int compat_ilp32_ptrace(struct task_struct *child, compat_long_t request, + compat_ulong_t addr, compat_ulong_t data) +{ + compat_ulong_t __user *datap = compat_ptr(data); + int ret; + + switch (request) { + case PTRACE_GETSIGMASK: + if (addr != sizeof(compat_sigset_t)) { + ret = -EINVAL; + break; + } + + if (put_sigset_t((compat_sigset_t __user *)datap, &child->blocked)) + ret = -EFAULT; + else + ret = 0; + break; + + case PTRACE_SETSIGMASK: { + sigset_t new_set; + if (addr != sizeof(compat_sigset_t)) { + ret = -EINVAL; + break; + } + + if (get_sigset_t(&new_set, (compat_sigset_t __user *)datap)) { + ret = -EFAULT; + break; + } + + sigdelsetmask(&new_set, sigmask(SIGKILL)|sigmask(SIGSTOP)); + + /* + * Every thread does recalc_sigpending() after resume, so + * retarget_shared_pending() and recalc_sigpending() are not + * called here. + */ + spin_lock_irq(&child->sighand->siglock); + child->blocked = new_set; + spin_unlock_irq(&child->sighand->siglock); + + ret = 0; + break; + } + + default: + ret = compat_ptrace_request(child, request, addr, data); + } + + return ret; +} + +#endif /* CONFIG_ARM64_ILP32 */ + #ifdef CONFIG_COMPAT long compat_arch_ptrace(struct task_struct *child, compat_long_t request, compat_ulong_t caddr, compat_ulong_t cdata) { +#ifdef CONFIG_ARM64_ILP32 + return compat_ilp32_ptrace(child, request, caddr, cdata); +#else return compat_ptrace_request(child, request, caddr, cdata); +#endif } #endif /* CONFIG_COMPAT */ diff --git a/arch/arm64/kernel/signal_ilp32.c b/arch/arm64/kernel/signal_ilp32.c index 8ca64b9..3ef2749 100644 --- a/arch/arm64/kernel/signal_ilp32.c +++ b/arch/arm64/kernel/signal_ilp32.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -58,28 +59,6 @@ struct ilp32_rt_sigframe { struct ilp32_sigframe sig; }; -static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set) -{ - compat_sigset_t cset; - - cset.sig[0] = set->sig[0] & 0xffffffffull; - cset.sig[1] = set->sig[0] >> 32; - - return copy_to_user(uset, &cset, sizeof(*uset)); -} - -static inline int get_sigset_t(sigset_t *set, - const compat_sigset_t __user *uset) -{ - compat_sigset_t s32; - - if (copy_from_user(&s32, uset, sizeof(*uset))) - return -EFAULT; - - set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32); - return 0; -} - static int restore_ilp32_sigframe(struct pt_regs *regs, struct ilp32_sigframe __user *sf) {