From patchwork Mon Mar 22 22:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 12156289 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=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 8F429C433C1 for ; Mon, 22 Mar 2021 22:55:19 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1A83861972 for ; Mon, 22 Mar 2021 22:55:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A83861972 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/o0JBoeY0Tiphz/V2Hi9xBxg15Ov6uFyexq4tyhNArE=; b=k+9QK8syxRoERuczA5IwE5Fgw wj0ZApipkhtN+2nXEHGtowjsB+EupE5nkxyFUs7No6DmvWE++qoBUCx4/bM9O1l6zSNMZac8jFtQN ngCMSkEpunhlgc5P22H9C+mglt1TtVMnDDWJlxemDKCvpaKLuCmgsa+c3HRENye3cB/ABz/Ah4Lyh 4JnRWeBmyKwYD84RJgT5nHS+PYw8mpOWAsE//BJV1cfchbc4TCzmuVsc1kKmqxDINGJg8daSE5L1W zOzlAA4ONSIJxJqmqZ0GvpNqSmlryq6BQ4W9q29wAOJj1HaqDmqrNYfHcTA7DL478Q9LB4/RLwgBU GUFIDETyQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lOTQW-00ClE0-4J; Mon, 22 Mar 2021 22:53:36 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lOTQE-00Cl9p-Q2 for linux-arm-kernel@lists.infradead.org; Mon, 22 Mar 2021 22:53:20 +0000 Received: by mail-pf1-x436.google.com with SMTP id 11so12249284pfn.9 for ; Mon, 22 Mar 2021 15:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xdPAri8WoNsvA6cnhWTwn4LuVR0p31oI0eOUDse1ymU=; b=o9q20IOjrMTNEMELiAE+McnFDmEU2NeXPn2ko/gUHyiZgS1jUYp0Xu1rmqBioWYI5z YqVjqqs5dNckbDiyZSqacUd8um6FoRBsTp2hbx85JPUrxvRgsuJ8mAR8PFuZBI0am4cB rij/jU3nk8puii6J6vNO+/3nPsnxFRyPjw1cjBDaRvPFYKU2bmVNVLvpcJ+uFrRzCtd6 5Oz7gbP4gcTORSAAXu2uzsAGrSH3VZoxjONDroHWXMsPl5yCKqpvfh0cIOKwtTIfYpup 0neIfRYYMhJ980XYJgfXLoGj/vSF/ywjBs1CLudb+59g7uwa6S+liubZ5Ls4/wMkUfLN F6Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xdPAri8WoNsvA6cnhWTwn4LuVR0p31oI0eOUDse1ymU=; b=hzSCrYLeIbdIwzE8FKLHU32YK3PX/qQ3G5jEmK82iBH8BKPCO4uQuet9vHjuamdtes 9JfcmqcPDO7Oe9yRRx4aaqLSQOD/PErUKIhMZLPrRweWClL5oAV/1TQHhjYahfV3ROnn JDkOj8ydWKHwJCO0/+TpcHcVAxrUJcpgTn0pSDQYqgs9ot5o18YBxYCfNYOSxjtF1MFz u1kwKAzW8+ps/dicu/bfoWUWLXd2iTG6PhW+XiTH4iit+ZFw8NPXEmuI0mXJhsIy3iHe F2fp/3qCaFoLd0jA22dIWt2w1Fq+SKM/nIw4i27IcXL3Wqs4vvc35BqSgDWn5ZS1Qj2j ujiA== X-Gm-Message-State: AOAM5328hEybukEBk9usAPI71TFBjcJq+QWmgMRldikNpTryHPhhg4rl 51KtNnJEw2K8tidlid3RMCw= X-Google-Smtp-Source: ABdhPJyCo1Tsxnu9rig2t2KgMAcB3e7DRoJWJFvNaZoTvo5cXK5H0K/AscZbaDqkmYLKr0E6zpyEHg== X-Received: by 2002:a17:902:8497:b029:e6:f01d:9c9f with SMTP id c23-20020a1709028497b02900e6f01d9c9fmr462781plo.7.1616453597180; Mon, 22 Mar 2021 15:53:17 -0700 (PDT) Received: from laptop.hsd1.wa.comcast.net ([2601:600:8500:5f14:d627:c51e:516e:a105]) by smtp.gmail.com with ESMTPSA id j13sm8878211pfn.103.2021.03.22.15.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 15:53:16 -0700 (PDT) From: Andrei Vagin To: Will Deacon , Catalin Marinas Cc: Oleg Nesterov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrei Vagin , Dave Martin , Keno Fischer Subject: [PATCH 2/4] arm64/ptrace: introduce orig_x7 in the user_pt_regs structure Date: Mon, 22 Mar 2021 15:50:51 -0700 Message-Id: <20210322225053.428615-3-avagin@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210322225053.428615-1-avagin@gmail.com> References: <20210322225053.428615-1-avagin@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210322_225318_969943_801B6E11 X-CRM114-Status: GOOD ( 16.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We have some ABI weirdness in the way that we handle syscall exit stops because we indicate whether or not the stop has been signalled from syscall entry or syscall exit by clobbering a general purpose register x7 in the tracee and restoring its old value after the stop. This behavior was inherited from ARM and it isn't common for other architectures. Now, we have PTRACE_GET_SYSCALL_INFO that gives all required information about system calls, so the hack with clobbering registers isn't needed anymore. This change instroduces orig_x7 in the user_pt_regs structure that will contains an origin value of the x7 register if the tracee is stopped in a system call.. Signed-off-by: Andrei Vagin --- arch/arm64/include/asm/ptrace.h | 1 + arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/ptrace.c | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index d4cdf98ac003..1008f0fbc5ea 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -184,6 +184,7 @@ struct pt_regs { u64 pc; u64 pstate; u64 orig_x0; + u64 orig_x7; }; }; #ifdef __AARCH64EB__ diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h index 3c118c5b0893..be7583ff5f4d 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -91,6 +91,7 @@ struct user_pt_regs { __u64 pc; __u64 pstate; __u64 orig_x0; + __u64 orig_x7; }; struct user_fpsimd_state { diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 170f42fd6101..1ed5b4aa986b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1750,7 +1750,7 @@ static void tracehook_report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir) { int regno; - unsigned long saved_reg; + u64 _saved_reg, *saved_reg; /* * We have some ABI weirdness here in the way that we handle syscall @@ -1768,19 +1768,25 @@ static void tracehook_report_syscall(struct pt_regs *regs, * - Syscall stops behave differently to seccomp and pseudo-step traps * (the latter do not nobble any registers). */ - regno = (is_compat_task() ? 12 : 7); - saved_reg = regs->regs[regno]; + if (is_compat_task()) { + regno = 12; + saved_reg = &_saved_reg; + } else { + regno = 7; + saved_reg = ®s->orig_x7; + } + *saved_reg = regs->regs[regno]; regs->regs[regno] = dir; if (dir == PTRACE_SYSCALL_ENTER) { if (tracehook_report_syscall_entry(regs)) forget_syscall(regs); - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; } else if (!test_thread_flag(TIF_SINGLESTEP)) { tracehook_report_syscall_exit(regs, 0); - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; } else { - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; /* * Signal a pseudo-step exception since we are stepping but