From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76DC2C433E0 for ; Tue, 23 Jun 2020 20:56:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D58220702 for ; Tue, 23 Jun 2020 20:56:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592945815; bh=hCGzX3Xu/Hpancbw3z3g4E5LxuqQw193GktQeyXp204=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=w/f3rtOjf/6m1t6lu3uphJQdmnFw4qWAdIA7kzsiIChY1p8YB+AEBjHB/JGxo6HMU buRrYzhW2dyRrfD3NVNPRK/rUVT4CVoFxxY3Vd1IyuHVJrRvW+J97H1b/ZbX/+FPz/ 4gCkbhccl4uTN+zUAzknwNJHVM25OZJk6I4SKTXc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392509AbgFWU4x (ORCPT ); Tue, 23 Jun 2020 16:56:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:40180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392510AbgFWUnU (ORCPT ); Tue, 23 Jun 2020 16:43:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 78E9F2070E; Tue, 23 Jun 2020 20:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592945001; bh=hCGzX3Xu/Hpancbw3z3g4E5LxuqQw193GktQeyXp204=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dA+GQvqAUzzp3d4VCN1KOC3cNq9yzJiRRDDLVypZmoK7TipFaUXiYxGIO1cETtLQ8 ZlKtFWd64joda25VocVhtiIC/qpJGxYKzQuYpZs05u/ZQgd9qIbeeKXAURHZ1nPofI hf4IWSYcgzFK5EChmq6pvjhFNRGXVNKbHv+iXycw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Elvira Khabirova , "Dmitry V. Levin" , Heiko Carstens , Vasily Gorbik Subject: [PATCH 4.19 195/206] s390: fix syscall_get_error for compat processes Date: Tue, 23 Jun 2020 21:58:43 +0200 Message-Id: <20200623195326.629457027@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195316.864547658@linuxfoundation.org> References: <20200623195316.864547658@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry V. Levin commit b3583fca5fb654af2cfc1c08259abb9728272538 upstream. If both the tracer and the tracee are compat processes, and gprs[2] is assigned a value by __poke_user_compat, then the higher 32 bits of gprs[2] are cleared, IS_ERR_VALUE() always returns false, and syscall_get_error() always returns 0. Fix the implementation by sign-extending the value for compat processes the same way as x86 implementation does. The bug was exposed to user space by commit 201766a20e30f ("ptrace: add PTRACE_GET_SYSCALL_INFO request") and detected by strace test suite. This change fixes strace syscall tampering on s390. Link: https://lkml.kernel.org/r/20200602180051.GA2427@altlinux.org Fixes: 753c4dd6a2fa2 ("[S390] ptrace changes") Cc: Elvira Khabirova Cc: stable@vger.kernel.org # v2.6.28+ Signed-off-by: Dmitry V. Levin Signed-off-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Greg Kroah-Hartman --- arch/s390/include/asm/syscall.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/arch/s390/include/asm/syscall.h +++ b/arch/s390/include/asm/syscall.h @@ -38,7 +38,17 @@ static inline void syscall_rollback(stru static inline long syscall_get_error(struct task_struct *task, struct pt_regs *regs) { - return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0; + unsigned long error = regs->gprs[2]; +#ifdef CONFIG_COMPAT + if (test_tsk_thread_flag(task, TIF_31BIT)) { + /* + * Sign-extend the value so (int)-EFOO becomes (long)-EFOO + * and will match correctly in comparisons. + */ + error = (long)(int)error; + } +#endif + return IS_ERR_VALUE(error) ? error : 0; } static inline long syscall_get_return_value(struct task_struct *task,