Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp477701pxf; Wed, 10 Mar 2021 09:59:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlUx0s6pLv7nmLoSzgs2nzj46AZ6EmNAKMrRRsWC6l7im656IWwjW0FFoG4jzm+a5aUSwn X-Received: by 2002:a05:6402:26c9:: with SMTP id x9mr4592093edd.322.1615399175399; Wed, 10 Mar 2021 09:59:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615399175; cv=none; d=google.com; s=arc-20160816; b=Ky5n1fyZ5wmNyQF7frSRYvxOyZjxae/JG7n0grsLigMPsqKEebad6EB1Rl55KstmAa HLifL4o8oQq7afCAZ26Z9ku+BjP8+nJ2tmGlYD3pHi0WY4k7zp4JMjROJSOBcEFH4FAU ISZE6Bg6UuoTM9UU/FVu/y0itqafdEwaP+QrzahyfqtCOXbzV+l0GfJhl0NCoXHb2XTQ /LYp56mEcN73FEyuXR+HT+anZ6ktzqt6G9nSlBE6EvCoK/c2l0jTopNFkGX2Oj2S33ih hdJyAEOY41rxNpovRdzSTIeP7xUnKWIiOWLJqUQU1uxOZNDRtGeiYxUQtNwJ93f8qVXC sWRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:cc:to:subject:from:references:in-reply-to :message-id; bh=xqTExC7mTkNh1+fQkK5Xqp1OFu1qVN/lvpyEU9b1bVo=; b=bZFfACwjg9GypGqm3B5HbTfwQR85+sjfjmWDVkF3TiiGACFKVhaY6fdCQNmOdtxhBk ChH/qQadqeK9V5x1Z1x/XqEgxcqC+P+e/HiRgvbOkP8KFPxRtGSTRGf5RXtHiLwHHT5K 0ncJ9sGHurBSqAYybK1OXeYiA6uILvdlOF3qex1jhDVvNrOgCSSaE8JLD8vXZHksIWcP Rc+/W7KndHEfXGWutx31lJWzjtl5v/qnJ4rjFYhSvVPYQuvPfESnS6qD5EDnseJfQ/gM oEjzMy19VhpSdeZRfuenVbdsUb7WY556NqNpSgyygpPl+Qil/UpkifqevscE7L4KJQ1Y 86mA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t8si87522edd.473.2021.03.10.09.59.12; Wed, 10 Mar 2021 09:59:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233509AbhCJR5W (ORCPT + 99 others); Wed, 10 Mar 2021 12:57:22 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:41328 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233416AbhCJR5K (ORCPT ); Wed, 10 Mar 2021 12:57:10 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4Dwfsv2Q51z9tytT; Wed, 10 Mar 2021 18:57:07 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id Dg8VJeDLXicS; Wed, 10 Mar 2021 18:57:07 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4Dwfsv1g16zB09Zh; Wed, 10 Mar 2021 18:57:07 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id CA8218B78D; Wed, 10 Mar 2021 18:57:08 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id f0QSKwE9ox9m; Wed, 10 Mar 2021 18:57:08 +0100 (CET) Received: from po16121vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4E5958B77E; Wed, 10 Mar 2021 18:57:08 +0100 (CET) Received: by po16121vm.idsi0.si.c-s.fr (Postfix, from userid 0) id ACC486756B; Wed, 10 Mar 2021 17:57:07 +0000 (UTC) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 8/8] powerpc/ptrace: Convert gpr32_set_common() to user access block To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 10 Mar 2021 17:57:07 +0000 (UTC) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use user access block in gpr32_set_common() instead of repetitive __get_user() which imply repetitive KUAP open/close. To get it clean, force inlining of the small set of tiny functions called inside the block. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/ptrace.h | 2 +- arch/powerpc/kernel/ptrace/ptrace-view.c | 30 ++++++++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h index 975ba260006a..cb154fb7b605 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -222,7 +222,7 @@ do { \ } while (0) #endif /* __powerpc64__ */ -static inline void set_trap(struct pt_regs *regs, unsigned long val) +static __always_inline void set_trap(struct pt_regs *regs, unsigned long val) { regs->trap = (regs->trap & TRAP_FLAGS_MASK) | (val & ~TRAP_FLAGS_MASK); } diff --git a/arch/powerpc/kernel/ptrace/ptrace-view.c b/arch/powerpc/kernel/ptrace/ptrace-view.c index 2bad8068f598..0923c94f684e 100644 --- a/arch/powerpc/kernel/ptrace/ptrace-view.c +++ b/arch/powerpc/kernel/ptrace/ptrace-view.c @@ -111,7 +111,7 @@ static unsigned long get_user_msr(struct task_struct *task) return task->thread.regs->msr | task->thread.fpexc_mode; } -static int set_user_msr(struct task_struct *task, unsigned long msr) +static __always_inline int set_user_msr(struct task_struct *task, unsigned long msr) { task->thread.regs->msr &= ~MSR_DEBUGCHANGE; task->thread.regs->msr |= msr & MSR_DEBUGCHANGE; @@ -147,7 +147,7 @@ static int set_user_dscr(struct task_struct *task, unsigned long dscr) * We prevent mucking around with the reserved area of trap * which are used internally by the kernel. */ -static int set_user_trap(struct task_struct *task, unsigned long trap) +static __always_inline int set_user_trap(struct task_struct *task, unsigned long trap) { set_trap(task->thread.regs, trap); return 0; @@ -661,6 +661,9 @@ int gpr32_set_common(struct task_struct *target, const compat_ulong_t __user *u = ubuf; compat_ulong_t reg; + if (!kbuf && !user_read_access_begin(u, count)) + return -EFAULT; + pos /= sizeof(reg); count /= sizeof(reg); @@ -669,8 +672,7 @@ int gpr32_set_common(struct task_struct *target, regs[pos++] = *k++; else for (; count > 0 && pos < PT_MSR; --count) { - if (__get_user(reg, u++)) - return -EFAULT; + unsafe_get_user(reg, u++, Efault); regs[pos++] = reg; } @@ -678,8 +680,8 @@ int gpr32_set_common(struct task_struct *target, if (count > 0 && pos == PT_MSR) { if (kbuf) reg = *k++; - else if (__get_user(reg, u++)) - return -EFAULT; + else + unsafe_get_user(reg, u++, Efault); set_user_msr(target, reg); ++pos; --count; @@ -692,24 +694,24 @@ int gpr32_set_common(struct task_struct *target, ++k; } else { for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) { - if (__get_user(reg, u++)) - return -EFAULT; + unsafe_get_user(reg, u++, Efault); regs[pos++] = reg; } for (; count > 0 && pos < PT_TRAP; --count, ++pos) - if (__get_user(reg, u++)) - return -EFAULT; + unsafe_get_user(reg, u++, Efault); } if (count > 0 && pos == PT_TRAP) { if (kbuf) reg = *k++; - else if (__get_user(reg, u++)) - return -EFAULT; + else + unsafe_get_user(reg, u++, Efault); set_user_trap(target, reg); ++pos; --count; } + if (!kbuf) + user_read_access_end(); kbuf = k; ubuf = u; @@ -717,6 +719,10 @@ int gpr32_set_common(struct task_struct *target, count *= sizeof(reg); return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, (PT_TRAP + 1) * sizeof(reg), -1); + +Efault: + user_read_access_end(); + return -EFAULT; } static int gpr32_get(struct task_struct *target, -- 2.25.0