Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1169867pxb; Thu, 4 Mar 2021 05:16:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRgGzieLArw5cVj85V6xGfb44c6wnf9mM22CfvmcJoaROWHGWy5zpVmYhIpIXcffKtMu3E X-Received: by 2002:a17:906:4a50:: with SMTP id a16mr4249799ejv.256.1614863807717; Thu, 04 Mar 2021 05:16:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614863807; cv=none; d=google.com; s=arc-20160816; b=ZBUZyxWoUCCPfOxi8KGyyLfECb2o6ifwdiB1IjfqLJlzw+nTfkXa8dIW3tWws9eTRP qKNkLoPMC/iuGP1W7GuVz0vUcYjfpcavUMcZAvD6kdtL+VEPun83qV0PD/zqLaEevTv0 S9j7nqpmsshYbrVhxsFFsszr/+5eIG+wUuccmgsj0fB269hG6IwBKKUjFsUP/Wumzinv MbD+lzKWyUgQwYfDSZA2XCog5jgUBvTmN/SxpShT/9PI3gDq8fCTNWg09hnHWfKsKv8A 9+kFD9RUrWzKNwIRCLFVKOeg26HsOxe/IbXD5jDeB+uo9ZYa6XW0aAk3t51CteS/yPxw cE5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=PSAzL91TbxHcUATvC5tUj2/89vsy0mCOaRDjirPS0rI=; b=zUpy3qyCWFJrO26C707y2eIBReCO3XUq/B1KlJEdShx/bL7SHkDTZOutY21D6uroqx iDMEAp89tFBKsplyj0B69AhS5ULq/EBkesJoOf+GUPd/MUMtlAQzkkLkyp3Zlb/udT2j KXy4WRAFY5QkHFaCMY8EcwrstMgithi0qCGQ+CmXfUFrYlTmuOTMXqqXM/TSttZl+Ikf J1V42B7xR58f9rtGaM0AzZm6JI8Y+Ya8w/Zw3vOs4PLReBLi6T0MJHAZldciCiOnFPxl OuvdxHRXj9XtM1TBNJjXS7jimYtjRThwPCutu/jctYrqQjozQwOy36iNpYrmQhtZWyHE FMxg== 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 g21si14990009ejf.645.2021.03.04.05.16.23; Thu, 04 Mar 2021 05:16:47 -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 S236945AbhCDAIG (ORCPT + 99 others); Wed, 3 Mar 2021 19:08:06 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:50980 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390139AbhCCWCC (ORCPT ); Wed, 3 Mar 2021 17:02:02 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 59C4F72C8B8; Thu, 4 Mar 2021 00:51:07 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 47F467CC8A2; Thu, 4 Mar 2021 00:51:07 +0300 (MSK) Date: Thu, 4 Mar 2021 00:51:07 +0300 From: "Dmitry V. Levin" To: Andrew Morton Cc: Sergei Trofimovich , linux-kernel@vger.kernel.org, Oleg Nesterov , linux-ia64@vger.kernel.org Subject: Re: [PATCH] ia64: fix ia64_syscall_get_set_arguments() for break-based syscalls Message-ID: <20210303215107.GC19445@altlinux.org> References: <20210221002554.333076-1-slyfox@gentoo.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210221002554.333076-1-slyfox@gentoo.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 21, 2021 at 12:25:53AM +0000, Sergei Trofimovich wrote: > In https://bugs.gentoo.org/769614 Dmitry noticed that > `ptrace(PTRACE_GET_SYSCALL_INFO)` does not work for syscalls called > via glibc's syscall() wrapper. > > ia64 has two ways to call syscalls from userspace: via `break` and via > `eps` instructions. > > The difference is in stack layout: > > 1. `eps` creates simple stack frame: no locals, in{0..7} == out{0..8} > 2. `break` uses userspace stack frame: may be locals (glibc provides > one), in{0..7} == out{0..8}. > > Both work fine in syscall handling cde itself. > > But `ptrace(PTRACE_GET_SYSCALL_INFO)` uses unwind mechanism to > re-extract syscall arguments but it does not account for locals. > > The change always skips locals registers. It should not change `eps` > path as kernel's handler already enforces locals=0 and fixes `break`. > > Tested on v5.10 on rx3600 machine (ia64 9040 CPU). > > CC: Oleg Nesterov > CC: linux-ia64@vger.kernel.org > CC: linux-kernel@vger.kernel.org > CC: Andrew Morton > Reported-by: Dmitry V. Levin > Bug: https://bugs.gentoo.org/769614 > Signed-off-by: Sergei Trofimovich > --- > arch/ia64/kernel/ptrace.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c > index c3490ee2daa5..e14f5653393a 100644 > --- a/arch/ia64/kernel/ptrace.c > +++ b/arch/ia64/kernel/ptrace.c > @@ -2013,27 +2013,39 @@ static void syscall_get_set_args_cb(struct unw_frame_info *info, void *data) > { > struct syscall_get_set_args *args = data; > struct pt_regs *pt = args->regs; > - unsigned long *krbs, cfm, ndirty; > + unsigned long *krbs, cfm, ndirty, nlocals, nouts; > int i, count; > > if (unw_unwind_to_user(info) < 0) > return; > > + /* > + * We get here via a few paths: > + * - break instruction: cfm is shared with caller. > + * syscall args are in out= regs, locals are non-empty. > + * - epsinstruction: cfm is set by br.call > + * locals don't exist. typo: epsinstruction > + * > + * For both cases argguments are reachable in cfm.sof - cfm.sol. typo: argguments > + * CFM: [ ... | sor: 17..14 | sol : 13..7 | sof : 6..0 ] > + */ > cfm = pt->cr_ifs; > + nlocals = (cfm >> 7) & 0x7f; /* aka sol */ > + nouts = (cfm & 0x7f) - nlocals; /* aka sof - sol */ > krbs = (unsigned long *)info->task + IA64_RBS_OFFSET/8; > ndirty = ia64_rse_num_regs(krbs, krbs + (pt->loadrs >> 19)); > > count = 0; > if (in_syscall(pt)) > - count = min_t(int, args->n, cfm & 0x7f); > + count = min_t(int, args->n, nouts); > > + /* Iterate over outs. */ > for (i = 0; i < count; i++) { > + int j = ndirty + nlocals + i + args->i; > if (args->rw) > - *ia64_rse_skip_regs(krbs, ndirty + i + args->i) = > - args->args[i]; > + *ia64_rse_skip_regs(krbs, j) = args->args[i]; > else > - args->args[i] = *ia64_rse_skip_regs(krbs, > - ndirty + i + args->i); > + args->args[i] = *ia64_rse_skip_regs(krbs, j); > } > > if (!args->rw) { This stuff is too ia64 specific, so I cannot properly review this patch, but it definitely fixes ia64 PTRACE_GET_SYSCALL_INFO on entering syscall. -- ldv