From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D2B42F3E for ; Fri, 10 Jan 2025 03:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736480070; cv=none; b=LDgpm7yl/AymxDt2dkjILosUpLRJWwfFLOMy0V0ZPo9dIXVPSTNzjWWMQF/K7zTqc3Oz+RIPkPFYqhVgfCwWNZZ/yUQYMddxvdrsSWuU/BazVbvwdoigvdECvS/Uz1fhL8UsAgW28TChTyzvXGnRNlbjxcl09K+MdFxq95gRmHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736480070; c=relaxed/simple; bh=A9fX/VY2dYRWoEe0eb7yQncWibBrwOENzsi82qWwsEI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d/WF9Ij4wWjTLH81exNMCYapBEEQGiWKoWKOYYCXsxbreYOc3m07G3D6HrXtVBT69q4rtNTxNxeX0bEDHM3lmkLD80nRTRnSnx5tdl8sjiKg3q8Awmq2HIBdRxlS62phSu0JMM/ywvJAzRjKvohLgtKRiog96pIkSqeqXy23Mk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=eBUZwVGD; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="eBUZwVGD" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2166651f752so33354755ad.3 for ; Thu, 09 Jan 2025 19:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736480068; x=1737084868; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Viayt1DprygJVfkBr8f2Q096yWM1X8ypOSSUQGDK3YM=; b=eBUZwVGDam67JwyMqc1Txd0LJvomzfvh4onYKPKcAEO03AuG+VZPPBiTkkS2l7rOYZ P6AtRpJl5w5GPdFvK3DyTiaKO/so5ARIyv0QLvhzi8R6X2SlVS4sksgjO8SYO8tWJmeS GsCpE8yK8p+f1RVtl0pgUPDPD+NJWZlXTvjDH+xcBE5joPQ97l4VPSTgY7Zm9MdTIrbz OjZVehjgZ5kaD3lDLIn76uRg71bht9HB+cdQcSCKRZUewQq+1t25aurZ2/yw5cc1H/U8 EH+F80pKiYegpmxZgmijWCPpkjQp7H0MIo5fJpHrcJtgdiAAZS7Rd69Iwa0mlNNYDYdb Xo6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736480068; x=1737084868; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Viayt1DprygJVfkBr8f2Q096yWM1X8ypOSSUQGDK3YM=; b=RXPngVrlJkDnRLKGA7PSkQ2CiTjzeNT73qTktHs6hG4QVxTC9jzt9tgFAUvFbpNi1G 1EUTxokxNuMe9M0Oy/DgekbJ/fLPAanAKB/H3+GyGGr9z+MIdvRvwPe7SrWX59aXWJNZ okKqjm1cCR5JOXWFNzNQ19kckmDtR+7ZWWGcBEjSE+9btlZwiyKWBWaDNVJRLO2EKEnj aq64h/OGDieD+Qf5aGXclAwmMvJGrI0AgM2fTYAZvAGaQtDqApwSzNqh827501K4mfT+ Dl9vk8XJSnVQtoK5Md1s8eIu/GPLcuTbkfo9Z8Mclv00bnkbg8xdEpnEaOeDjt7nSVP5 uOWw== X-Forwarded-Encrypted: i=1; AJvYcCWyjUw0Sp/DNaprJ0WwUpKIwEDeSQh765y8Jd/uL5/gr6aBfxhgX9LqFaItaNL+IdPDYeHpeQDn8qh99EU=@vger.kernel.org X-Gm-Message-State: AOJu0YxMSIP3ukFwWBnjmHk7EKGYjGLdTnFTqy+dUfOgbmmDVmjpdzaz 7rvsCJ8PcgDGavz3qItnPr2WSif5A8m4r7nid6mA4EY6iWfvxbPy5IR6FdJkMX0= X-Gm-Gg: ASbGncuAOHrxjw8JcPYWbuJDxF9WaRkx5fv0P13iVS/pSTHgi6TmNrUm1uaG6CIUXSh H787sKwsBPrk9Od6kgzaBianWzZNze4y/XDDg1Darlu5wqt4oNu9659Y+dJ27whGOg6/jVTJX0B e45M1y3GZL3dg2ghkGz7jHX1zrD2VLpQZA1Tjd988408o/GC8oTTxvIcsEzMDuGbYor/wOWMV3N KY2HytYZBKTg9/5OW2ogNTvrnp2pjEUH/eOga/HbVo429foQvHl X-Google-Smtp-Source: AGHT+IG3bbMYbkS4jJPSzQ9p7FyUYg9x1B/aqRiSj2rt9ftAdecMCL/6FTOfSLcR8vnjUeA3BTKFRA== X-Received: by 2002:a05:6a00:1c92:b0:725:e499:5b86 with SMTP id d2e1a72fcca58-72d21fdfc66mr14107164b3a.20.1736480067688; Thu, 09 Jan 2025 19:34:27 -0800 (PST) Received: from ghost ([2601:647:6700:64d0:691c:638a:ff10:3765]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72d406a4dddsm569643b3a.155.2025.01.09.19.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jan 2025 19:34:27 -0800 (PST) Date: Thu, 9 Jan 2025 19:34:24 -0800 From: Charlie Jenkins To: Celeste Liu Cc: "Dmitry V. Levin" , Oleg Nesterov , Paul Walmsley , Palmer Dabbelt , Eric Biederman , Kees Cook , Shuah Khan , Albert Ou , Alexandre Ghiti , Andrea Bolognani , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , Thomas Gleixner , Ron Economos , Andrew Jones , Quan Zhou , Felix Yan , Ruizhe Pan , Guo Ren , Yao Zi , Eugene Syromyatnikov , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= Subject: Re: [PATCH v4 2/2] riscv: selftests: Add a ptrace test to verify syscall parameter modification Message-ID: References: <20241226-riscv-new-regset-v4-0-4496a29d0436@coelacanthus.name> <20241226-riscv-new-regset-v4-2-4496a29d0436@coelacanthus.name> <20241226133459.GA30481@strace.io> <2e09aedc-44ba-40e3-ae93-1d6dc21b5eb1@coelacanthus.name> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2e09aedc-44ba-40e3-ae93-1d6dc21b5eb1@coelacanthus.name> On Thu, Dec 26, 2024 at 11:21:59PM +0800, Celeste Liu wrote: > > On 2024-12-26 21:35, Dmitry V. Levin wrote: > > On Thu, Dec 26, 2024 at 06:52:52PM +0800, Celeste Liu wrote: > >> This test checks that orig_a0 allows a syscall argument to be modified, > >> and that changing a0 does not change the syscall argument. > >> > >> Co-developed-by: Quan Zhou > >> Signed-off-by: Quan Zhou > >> Co-developed-by: Charlie Jenkins > >> Signed-off-by: Charlie Jenkins > >> Reviewed-by: Björn Töpel > >> Signed-off-by: Celeste Liu > > [...] > >> diff --git a/tools/testing/selftests/riscv/abi/ptrace.c b/tools/testing/selftests/riscv/abi/ptrace.c > >> new file mode 100644 > >> index 0000000000000000000000000000000000000000..023695352215bb5de3f91c1a6f5ea3b4f9373ff9 > >> --- /dev/null > >> +++ b/tools/testing/selftests/riscv/abi/ptrace.c > > [...] > >> + if (ptrace(PTRACE_GET_SYSCALL_INFO, pid, PTRACE_SYSCALL_INFO_ENTRY, &syscall_info_entry)) > >> + perr_and_exit("failed to get syscall info of entry\n"); > >> + result->orig_a0 = syscall_info_entry->entry.args[0]; > >> + if (ptrace(PTRACE_GET_SYSCALL_INFO, pid, PTRACE_SYSCALL_INFO_EXIT, &syscall_info_exit)) > >> + perr_and_exit("failed to get syscall info of exit\n"); > >> + result->a0 = syscall_info_exit->exit.rval; > > > > I'm sorry but this is not how PTRACE_GET_SYSCALL_INFO should be used. > > > > PTRACE_GET_SYSCALL_INFO operation takes a pointer and a size, > > and in this example instead of size you pass constants 1 and 2, which > > essentially means that both syscall_info_entry->entry.args[0] and > > syscall_info_exit->exit.rval are not going to be assigned > > and would just contain some garbage from the stack. > > > > Also, PTRACE_GET_SYSCALL_INFO operation returns the number of bytes > > available to be written by the kernel, which is always nonzero on any > > PTRACE_GET_SYSCALL_INFO-capable kernel. In other words, this example > > will always end up with perr_and_exit() call. > > > > I wonder how this test was tested before the submission. > > Oops... It seems I forget sync the code to test board so it runs with the old code... > The code is completely not tested... > I'm so sorry for my mistake. > > I will correct it and test it carefully later... It would be great to get this into 6.14. Let me know if you would like any help! - Charlie > > > > > >