Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3547079pxj; Mon, 24 May 2021 09:06:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRyYgcpSvtyOazX6E3ueXKeLmZoFgQV/Nsa9PF8lDrVxqfQPDxZPelnR6Nt8DLNN8pYpS9 X-Received: by 2002:a05:6638:cc9:: with SMTP id e9mr25640708jak.46.1621872394212; Mon, 24 May 2021 09:06:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621872394; cv=none; d=google.com; s=arc-20160816; b=R5FzUlyFgl7Z1R770uoOJb3cNf+C1z4YGpvrK/01lVQ3cf279IH4lVncCd1EHr6ZIO gvEDsddqNlCkHD2vcZpcWunPxHLI0BiUbxGq5zF+9AQ7lfc7LsUqrj+k1Nhcw+BrNy64 Wk1k6pk2xqc7vkk7A4JApkATDtndQ9jLh8XtbuVN9Kssx9qZ9Pjw2muKztZEOqRlJosD AV9lyiwkabSOZnPtEzhhX2OC4yOMevHOWIW087x4ziJ7YuNACdLNdDMLJrofZ+tnEio1 Fq/xZTdzo7x3jTB1fXVy9tnDtZJFSUODpzoDd/u8E/5SDQO0V3dqCp0rNxI44dQfV9Do xYHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aA3CaqAe6fqPztcZXFiQpKwnO8uzeRWrizP48PDDJpI=; b=SL8VFHTeOa5kjgb7MDzGWJYjdDCjn9JSp68JgFFtyLqmoCfubFdCElVWGH8grV5ZVt ZRRn1TJWsMwAiO5EVT+dpOGGZrk3pQoyTNmmYMJnyj4LmjcUC4xmmAKmFq4nAgAhRNck mSXwKhXEhG1+pJCR9hU5COi8UsOqe3iDBUMkrJqVZqxI2HlDTF89C0kR5qy0P/coZMMB 75iI98fKD0wODVGsiHy+NJk5YUDQIigch0sTJAHQLl6m8RlTsOJTD+ConQuAWPE4OHHP sggOaLn6Ym0cghNPZ2aPNIA6zuf0xwVgzflVyUYmVnaAKl0gv8FSDV4LPH1KUZEOWTra cDkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LwHQ5iOC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si16809368ils.62.2021.05.24.09.06.15; Mon, 24 May 2021 09:06:34 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LwHQ5iOC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236057AbhEXQGQ (ORCPT + 99 others); Mon, 24 May 2021 12:06:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:40492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233126AbhEXP72 (ORCPT ); Mon, 24 May 2021 11:59:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 230C161973; Mon, 24 May 2021 15:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621871122; bh=pWEP2KSu5qBCjYQtK+BZ3ZnRIjvVR0OCYadDq5qMKQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwHQ5iOCthxVHK2+xKWBhCnJdvAQTRsRiWbp4hmnidPltN00LpfNPdcOJA7mVHZ0h hZnrrqAbCFMw1+NV+nFN4iyJ99ahbU3C8aOSxbNKaYbUHLFFsEHoi+OcJ9dM58Upzm lFHUOl4xvBjQPG6ny0pwFv/x4CHlEeBV0utv3xvc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Dmitry V. Levin" , Nicholas Piggin , Michael Ellerman Subject: [PATCH 5.12 083/127] powerpc/64s/syscall: Fix ptrace syscall info with scv syscalls Date: Mon, 24 May 2021 17:26:40 +0200 Message-Id: <20210524152337.656749585@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210524152334.857620285@linuxfoundation.org> References: <20210524152334.857620285@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicholas Piggin commit d72500f992849d31ebae8f821a023660ddd0dcc2 upstream. The scv implementation missed updating syscall return value and error value get/set functions to deal with the changed register ABI. This broke ptrace PTRACE_GET_SYSCALL_INFO as well as some kernel auditing and tracing functions. Fix. tools/testing/selftests/ptrace/get_syscall_info now passes when scv is used. Fixes: 7fa95f9adaee ("powerpc/64s: system call support for scv/rfscv instructions") Cc: stable@vger.kernel.org # v5.9+ Reported-by: "Dmitry V. Levin" Signed-off-by: Nicholas Piggin Reviewed-by: Dmitry V. Levin Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210520111931.2597127-2-npiggin@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/include/asm/ptrace.h | 45 +++++++++++++++++++++---------------- arch/powerpc/include/asm/syscall.h | 42 +++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 35 deletions(-) --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -19,6 +19,7 @@ #ifndef _ASM_POWERPC_PTRACE_H #define _ASM_POWERPC_PTRACE_H +#include #include #include @@ -152,25 +153,6 @@ extern unsigned long profile_pc(struct p long do_syscall_trace_enter(struct pt_regs *regs); void do_syscall_trace_leave(struct pt_regs *regs); -#define kernel_stack_pointer(regs) ((regs)->gpr[1]) -static inline int is_syscall_success(struct pt_regs *regs) -{ - return !(regs->ccr & 0x10000000); -} - -static inline long regs_return_value(struct pt_regs *regs) -{ - if (is_syscall_success(regs)) - return regs->gpr[3]; - else - return -regs->gpr[3]; -} - -static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) -{ - regs->gpr[3] = rc; -} - #ifdef __powerpc64__ #define user_mode(regs) ((((regs)->msr) >> MSR_PR_LG) & 0x1) #else @@ -252,6 +234,31 @@ static inline void set_trap_norestart(st regs->trap |= 0x10; } +#define kernel_stack_pointer(regs) ((regs)->gpr[1]) +static inline int is_syscall_success(struct pt_regs *regs) +{ + if (trap_is_scv(regs)) + return !IS_ERR_VALUE((unsigned long)regs->gpr[3]); + else + return !(regs->ccr & 0x10000000); +} + +static inline long regs_return_value(struct pt_regs *regs) +{ + if (trap_is_scv(regs)) + return regs->gpr[3]; + + if (is_syscall_success(regs)) + return regs->gpr[3]; + else + return -regs->gpr[3]; +} + +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) +{ + regs->gpr[3] = rc; +} + #define arch_has_single_step() (1) #define arch_has_block_step() (true) #define ARCH_HAS_USER_SINGLE_STEP_REPORT --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -41,11 +41,17 @@ static inline void syscall_rollback(stru static inline long syscall_get_error(struct task_struct *task, struct pt_regs *regs) { - /* - * If the system call failed, - * regs->gpr[3] contains a positive ERRORCODE. - */ - return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0; + if (trap_is_scv(regs)) { + unsigned long error = regs->gpr[3]; + + return IS_ERR_VALUE(error) ? error : 0; + } else { + /* + * If the system call failed, + * regs->gpr[3] contains a positive ERRORCODE. + */ + return (regs->ccr & 0x10000000UL) ? -regs->gpr[3] : 0; + } } static inline long syscall_get_return_value(struct task_struct *task, @@ -58,18 +64,22 @@ static inline void syscall_set_return_va struct pt_regs *regs, int error, long val) { - /* - * In the general case it's not obvious that we must deal with CCR - * here, as the syscall exit path will also do that for us. However - * there are some places, eg. the signal code, which check ccr to - * decide if the value in r3 is actually an error. - */ - if (error) { - regs->ccr |= 0x10000000L; - regs->gpr[3] = error; + if (trap_is_scv(regs)) { + regs->gpr[3] = (long) error ?: val; } else { - regs->ccr &= ~0x10000000L; - regs->gpr[3] = val; + /* + * In the general case it's not obvious that we must deal with + * CCR here, as the syscall exit path will also do that for us. + * However there are some places, eg. the signal code, which + * check ccr to decide if the value in r3 is actually an error. + */ + if (error) { + regs->ccr |= 0x10000000L; + regs->gpr[3] = error; + } else { + regs->ccr &= ~0x10000000L; + regs->gpr[3] = val; + } } }