Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3024691ybt; Mon, 29 Jun 2020 13:12:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoMPkhSQF3QN4Vx3KwtSLUvhUVYQV9zJcGj2rb0JdIFOl0Vu6aZBZkb27hyqpfdIqap8tN X-Received: by 2002:a50:a701:: with SMTP id h1mr18943055edc.170.1593461574244; Mon, 29 Jun 2020 13:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593461574; cv=none; d=google.com; s=arc-20160816; b=FcVgDPQsUOXOu2QIIU2tUm0LBkJJfngX4Tml+BS/UwYeCHjtsvydakmMLm1LVDgHZn qctWw4yLyWQRBjX94TOuI+acbJdcjGBVk0QXcybSqDlRoQCZWwtaGk17SP1OAnT6hrvI 031f1fud4wa14ILeaOFZTC0V0+7YVWcunAx6763nqFftB+HWemDwpnsZlq8eg7vk7Dab 3LTTT4GEJRqI2jzGqgOWlvi7ti9zi9CKKkb4b3f+belBORxM3N44NeK2pGJ8jGeGC7zI 8UgWCeRgZ0FjQ8u14T2Es3M/6YrQRc3KynX+OyO68zz4ubDgHmToSPoIWhBUANvWiTr0 70Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h/S5faNadB3dWcIPwznA+M7GjHpI3z4kcObo2CjDiug=; b=uRwEYyTCnny+Jp1LM/aNflFUEhVkL4mYPuleEKYXa/Nda0LJcdDKL/r6JtCmdFG0N3 ljyaJkWOpi4CBWBa01zz9XNQsAVcmvo9/iT2NLWA5Q2p2WvO2VfD1qQRwBWYxM4CmI3n nHPsEH+4uUBzHwmP7bh7b+APNjB6attb/mMBhvqIQEuWfZjs6RdyQUhCBBjUmazma0yG 8GGo1b/fPcKk8qzeinh9VqmOrgAVJ3E7T4KM0LQiEQZjp5NI8+hrjqsFLNXFGsgd5juB y52eYlT5LyzNMhFwb/aGj3cx8/5LA7oPnBEE4k56bwcyXwSEAADqybkKhucouLGrTyot A3eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gc5piati; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pw26si396567ejb.240.2020.06.29.13.12.30; Mon, 29 Jun 2020 13:12:54 -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=@kernel.org header.s=default header.b=gc5piati; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729658AbgF2ULF (ORCPT + 99 others); Mon, 29 Jun 2020 16:11:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:40570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732892AbgF2TaV (ORCPT ); Mon, 29 Jun 2020 15:30:21 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 77C172528A; Mon, 29 Jun 2020 15:36:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444998; bh=b0j2mIs3XUjOXxVpOjvPT/hMw0I3XoANlSSZiHVK85k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gc5piatigOs3Pdcb/s35N9WmNkOHR/SFHjVPTmtqC3AseCgyhrC81BeFMv3cOEGnl o8BEqATZoFiasa2GxIOXqJnJ478ZiUfp1n1PtevOzWH0xc1fvNY25oo3zwkfaQ9iGV t1ad63yoClnIjdOH3sArmqmXtfhpj9kJ959REav0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sven Schnelle , Vasily Gorbik , Sasha Levin Subject: [PATCH 4.19 098/131] s390/ptrace: fix setting syscall number Date: Mon, 29 Jun 2020 11:34:29 -0400 Message-Id: <20200629153502.2494656-99-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629153502.2494656-1-sashal@kernel.org> References: <20200629153502.2494656-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.131-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.131-rc1 X-KernelTest-Deadline: 2020-07-01T15:34+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sven Schnelle [ Upstream commit 873e5a763d604c32988c4a78913a8dab3862d2f9 ] When strace wants to update the syscall number, it sets GPR2 to the desired number and updates the GPR via PTRACE_SETREGSET. It doesn't update regs->int_code which would cause the old syscall executed on syscall restart. As we cannot change the ptrace ABI and don't have a field for the interruption code, check whether the tracee is in a syscall and the last instruction was svc. In that case assume that the tracer wants to update the syscall number and copy the GPR2 value to regs->int_code. Signed-off-by: Sven Schnelle Signed-off-by: Vasily Gorbik Signed-off-by: Sasha Levin --- arch/s390/kernel/ptrace.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c index cd3df5514552c..65fefbf61e1ca 100644 --- a/arch/s390/kernel/ptrace.c +++ b/arch/s390/kernel/ptrace.c @@ -325,6 +325,25 @@ static inline void __poke_user_per(struct task_struct *child, child->thread.per_user.end = data; } +static void fixup_int_code(struct task_struct *child, addr_t data) +{ + struct pt_regs *regs = task_pt_regs(child); + int ilc = regs->int_code >> 16; + u16 insn; + + if (ilc > 6) + return; + + if (ptrace_access_vm(child, regs->psw.addr - (regs->int_code >> 16), + &insn, sizeof(insn), FOLL_FORCE) != sizeof(insn)) + return; + + /* double check that tracee stopped on svc instruction */ + if ((insn >> 8) != 0xa) + return; + + regs->int_code = 0x20000 | (data & 0xffff); +} /* * Write a word to the user area of a process at location addr. This * operation does have an additional problem compared to peek_user. @@ -336,7 +355,9 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) struct user *dummy = NULL; addr_t offset; + if (addr < (addr_t) &dummy->regs.acrs) { + struct pt_regs *regs = task_pt_regs(child); /* * psw and gprs are stored on the stack */ @@ -354,7 +375,11 @@ static int __poke_user(struct task_struct *child, addr_t addr, addr_t data) /* Invalid addressing mode bits */ return -EINVAL; } - *(addr_t *)((addr_t) &task_pt_regs(child)->psw + addr) = data; + + if (test_pt_regs_flag(regs, PIF_SYSCALL) && + addr == offsetof(struct user, regs.gprs[2])) + fixup_int_code(child, data); + *(addr_t *)((addr_t) ®s->psw + addr) = data; } else if (addr < (addr_t) (&dummy->regs.orig_gpr2)) { /* @@ -720,6 +745,10 @@ static int __poke_user_compat(struct task_struct *child, regs->psw.mask = (regs->psw.mask & ~PSW_MASK_BA) | (__u64)(tmp & PSW32_ADDR_AMODE); } else { + + if (test_pt_regs_flag(regs, PIF_SYSCALL) && + addr == offsetof(struct compat_user, regs.gprs[2])) + fixup_int_code(child, data); /* gpr 0-15 */ *(__u32*)((addr_t) ®s->psw + addr*2 + 4) = tmp; } -- 2.25.1