Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp120398lqm; Mon, 10 Jun 2024 15:03:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWntuMEttWEgFIgc4+MJ/loF2CbE0DUMTd1GBTHVjEoXH1zRPf/BN2Gx8a2us2Yfpx5IkttgdA3le3g1Lk1A36XD0ah0P747xK8pKHx/g== X-Google-Smtp-Source: AGHT+IGAgcn2mSAizm/4G66GGM5u8qeg+dNnQHoNtd23VwxuY4xHVWLiXpP+zV/jlIWSnTdOGhJw X-Received: by 2002:a05:6a00:868c:b0:704:209a:c59e with SMTP id d2e1a72fcca58-704209ae06dmr5551521b3a.9.1718057005019; Mon, 10 Jun 2024 15:03:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718057004; cv=pass; d=google.com; s=arc-20160816; b=OiQd3G3aK/VAswKa3amYApaN2u97AOPluahIE38np9N9iL3lKpcBO2S1804iN9Wc5E 8Gx3UznzTZ8FLopWv7eRmi19TtAXNe0YGoBdlThAXfTtK8+KyH+7CoW6vLaqOKjmMYaB P2QSM/a5Yg/E31w7iX8BO2YTrUPp7gxDC+QSi4j04V1le0qcudE5iX7XUy5W2Pmu7nvT gPnYFq2Woz82sMnTS96hqzL+RUMhFrbflig3Ysr6muPwH7YwY1hpmqM3JcNqoMAPYjP0 SnkZ5Jvwmmkdibc5C8ebVLZcNRVVUOyhPxHaPX3Q7RHgJ1zzUsgLafQxchfz3cjzTAZb lN4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=jkipqgfXTAB0h/pxtGVGPCvOzhO7bFTPvBD/3+fUXxc=; fh=2dAi7si8Z+XN5ZyLSTvXSAWP46xa+cehGwk27I2ZBig=; b=l8djOgsJ1Pr04/DbO+o6g+wZ6jGiBif951EPA+gVQRUcj/dmLKiqNueiWhffjH8kuh MvcdeXgHx+WhtBWeCvEQrVBwcrBYIJmJyo7qJorriZwMbGFqn22tjjdAIhzUi2cD3iR6 nNW4gjNs4IorRJIH3f2YXUfpCCvDgadYpP+w9rKPJJdPK/zobm1pYR5aA2qNVols3e+v 7kVBJIjLaw2qRN4oAVMDxOFJJK0zgtHRjRJTnozInTK1d02iOGJm3vFvOFCdJ6AiZsf2 DhiBTvpAMcgjKVaiM+tV91f3dxUx53jfoNEmgmtkg6mwWHLp/hMeM30RI0GB7EQXEyzw Ne3w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyE3dy4S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208976-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-70436a895c9si3229570b3a.377.2024.06.10.15.03.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208976-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QyE3dy4S; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-208976-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208976-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 70AE7284989 for ; Mon, 10 Jun 2024 22:02:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B27F814F9F2; Mon, 10 Jun 2024 22:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QyE3dy4S" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B87CC63D0; Mon, 10 Jun 2024 22:02:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718056939; cv=none; b=GbKF52FXBESLPWW3aeXctyIwnbMDqccDpdNj8OjfYnXv09RPuNOw5uc46PyWslnekv2dkjRrAFW0uhH3/mdNmqiVlKx0weeKuvZ2kjdf4WAKYSlHwsj1DhaZHQBdLaFukJd6esdTTEUl2UCjkVFC4txTNLIhJvm0NzEVFcyBzRE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718056939; c=relaxed/simple; bh=MqAQpkevHGNOOFgJUiEdfPRWQVNm7nE45c3VrxEicIA=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=jMG1bhL1oXOCpb4kPQ/u42iFcjtr+Pg2h3+HSQcNXBVjl3H7LhfSAJlayds/w4YQqthgPGuHlJtfuf1yOaAVi1y2oavJQBDq6C5ZBdgne2z9WPwK7PjDBEoRNBjBTKyAEiDpWq7VyR/gkj10jxU0QuOqWWzE4ARSAGPFABi8Ttg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QyE3dy4S; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3304FC2BBFC; Mon, 10 Jun 2024 22:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718056939; bh=MqAQpkevHGNOOFgJUiEdfPRWQVNm7nE45c3VrxEicIA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QyE3dy4SuC3VRsPWts6pHstZn3YX31KuhAybYrIPKs9yDsBuc8E2afjL4TWoup+Vx fJ8TduCIsN4pgTs5G8dvxj/2xR6381diQc1Lrhwj6cfKuM6IOYtlX78K+4kfgpqtHy Yzcdcz7SOyWhf/Yq0MmWmYGQorvieRfXhWUqQl2RpFTfRTceDYMTPWQWQASJqgI7Na eabkoLgghbQ34Zbvh7bX7vknHTJjq8ZP/2e2eBg12DcGfnxmo77P2gxPQD0Y9XM/Gb YzmSPHOIX8Wxe0rX3EhbLpRDku2W8ydGL+zRdEuE18kIUcKsrCnlxA0izqpKtrUyoc lnVy4rK4tl4RA== Date: Tue, 11 Jun 2024 07:02:12 +0900 From: Masami Hiramatsu (Google) To: Jiri Olsa Cc: Steven Rostedt , Oleg Nesterov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-man@vger.kernel.org, x86@kernel.org, bpf@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend , Peter Zijlstra , Thomas Gleixner , "Borislav Petkov (AMD)" , Ingo Molnar , Andy Lutomirski , "Edgecombe, Rick P" , Deepak Gupta Subject: Re: [PATCHv7 bpf-next 8/9] selftests/bpf: Add uretprobe shadow stack test Message-Id: <20240611070212.79cef453d0615e3af5af1fb0@kernel.org> In-Reply-To: <20240523121149.575616-9-jolsa@kernel.org> References: <20240523121149.575616-1-jolsa@kernel.org> <20240523121149.575616-9-jolsa@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 23 May 2024 14:11:48 +0200 Jiri Olsa wrote: > Adding uretprobe shadow stack test that runs all existing > uretprobe tests with shadow stack enabled if it's available. > According to the document and sample code, this looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thanks, > Signed-off-by: Jiri Olsa > --- > .../selftests/bpf/prog_tests/uprobe_syscall.c | 60 +++++++++++++++++++ > 1 file changed, 60 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c > index 3ef324c2db50..fda456401284 100644 > --- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c > +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c > @@ -9,6 +9,9 @@ > #include > #include > #include > +#include > +#include > +#include > #include "uprobe_syscall.skel.h" > #include "uprobe_syscall_executed.skel.h" > > @@ -297,6 +300,56 @@ static void test_uretprobe_syscall_call(void) > close(go[1]); > close(go[0]); > } > + > +/* > + * Borrowed from tools/testing/selftests/x86/test_shadow_stack.c. > + * > + * For use in inline enablement of shadow stack. > + * > + * The program can't return from the point where shadow stack gets enabled > + * because there will be no address on the shadow stack. So it can't use > + * syscall() for enablement, since it is a function. > + * > + * Based on code from nolibc.h. Keep a copy here because this can't pull > + * in all of nolibc.h. > + */ > +#define ARCH_PRCTL(arg1, arg2) \ > +({ \ > + long _ret; \ > + register long _num asm("eax") = __NR_arch_prctl; \ > + register long _arg1 asm("rdi") = (long)(arg1); \ > + register long _arg2 asm("rsi") = (long)(arg2); \ > + \ > + asm volatile ( \ > + "syscall\n" \ > + : "=a"(_ret) \ > + : "r"(_arg1), "r"(_arg2), \ > + "0"(_num) \ > + : "rcx", "r11", "memory", "cc" \ > + ); \ > + _ret; \ > +}) > + > +#ifndef ARCH_SHSTK_ENABLE > +#define ARCH_SHSTK_ENABLE 0x5001 > +#define ARCH_SHSTK_DISABLE 0x5002 > +#define ARCH_SHSTK_SHSTK (1ULL << 0) > +#endif > + > +static void test_uretprobe_shadow_stack(void) > +{ > + if (ARCH_PRCTL(ARCH_SHSTK_ENABLE, ARCH_SHSTK_SHSTK)) { > + test__skip(); > + return; > + } > + > + /* Run all of the uretprobe tests. */ > + test_uretprobe_regs_equal(); > + test_uretprobe_regs_change(); > + test_uretprobe_syscall_call(); > + > + ARCH_PRCTL(ARCH_SHSTK_DISABLE, ARCH_SHSTK_SHSTK); > +} > #else > static void test_uretprobe_regs_equal(void) > { > @@ -312,6 +365,11 @@ static void test_uretprobe_syscall_call(void) > { > test__skip(); > } > + > +static void test_uretprobe_shadow_stack(void) > +{ > + test__skip(); > +} > #endif > > void test_uprobe_syscall(void) > @@ -322,4 +380,6 @@ void test_uprobe_syscall(void) > test_uretprobe_regs_change(); > if (test__start_subtest("uretprobe_syscall_call")) > test_uretprobe_syscall_call(); > + if (test__start_subtest("uretprobe_shadow_stack")) > + test_uretprobe_shadow_stack(); > } > -- > 2.45.1 > -- Masami Hiramatsu (Google)