Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2998596lqo; Tue, 21 May 2024 04:01:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzvceSh1ak8HKZyZkW7euwiUynZ0T4DVHZvFRzuLICg8lpl+wV/4srKK/88ExIdwkyMYyjpA6/UKOm7Q2dj6OvFHdIobhV7LtEkn6qWA== X-Google-Smtp-Source: AGHT+IE0hWZ8lVao3J5voDZGXqz1CPRBL4eGClQDYK8JNSAxXz5SqW5a51O7v1CEXo+wp3+eaCHX X-Received: by 2002:a05:6a21:3a46:b0:1b1:d7a2:76fc with SMTP id adf61e73a8af0-1b1d7a278c4mr6966828637.37.1716289288242; Tue, 21 May 2024 04:01:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716289288; cv=pass; d=google.com; s=arc-20160816; b=bBgXqwJ4/Fao4hwC94tC5hOCdQD/EbgWNDoZCmXqNXmMK9KCN2nJxa8DXS4YLeioiK BZlo7DPb/dMTBMknlUDxAzdNJZvSPhYNNu+AnN0XXhXiw4gwDKQIEqnhcMYU20573Pp1 2K5PxBVYeFUm6A/TaciW0IuesZvR63ltIIEYqxd17ws3CV1O9MuuomvmSiU/yagFZJIm Jv3/h3QQNwwy43o1thMAsdM6yKkSS/vvyjMEwIMCOMkxQ1wvJjmZbFy5zJdcKLL4u3JV pNsSVIZPpRHHzjvveSYg9itNr9dsYfp44iofp1JvvKhWEUSj2msizN4FwgkJh3MZH1cU 4xYw== 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 :date:subject:cc:to:from:dkim-signature; bh=qt6fLfYa7dcxgPGZDRQC9C/ZSz92A6bOWKIAcUT2BuQ=; fh=nmDo0evxWwTAvBlxNELHY/fYZbxD4K9pluaUjPt1MrQ=; b=diKEkRpJEtnbGofAhcpCCZPTZKFDsFa6diQE+mnNhX1R3gBBFVvF3IbyMCs+VQCsG2 /bfvY3auso3SRGrVXlbPsNFFRd6hCconNPmI8aO5m2o40LdBMuxU822RgVGhNPVidgVM FWvtDsRcCE9bD90okExEadWyxai3VbajPHwmChDWtaRcRL+OvdJIrCoKvc7algWpygQT keeMlW1TQbecm5bhuff1eWNB4sptz4Uvp1Bgf0aFMnL5+NRgUtYnTrbvpimp+UWzz6xt oQM+UyCimZQvoLpBgGNejBRoXCUI4hIBV6n0lvAExGYY1U0dQd1q71sepQF7ufkVogRW ECqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BidipBjr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184828-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184828-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-6f4d2a97179si24515104b3a.128.2024.05.21.04.01.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 04:01:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184828-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=BidipBjr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184828-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184828-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 B975E283448 for ; Tue, 21 May 2024 10:51:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D64FB7603A; Tue, 21 May 2024 10:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BidipBjr" 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 EFFE46D1BC; Tue, 21 May 2024 10:50:11 +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=1716288612; cv=none; b=Bl8TpK1+yvt4AMVxG+5++m3kN89jBF3gJAB56vhxDUVRFApGTamBsCyTEl3f55F4IZQ07tSk1DEX3ZbfF4ONfAQpjdY9Ohq7LwYXEkdzof1FyAfe8OtUh3Z0DQTiKOu4BEn44asloQ667Pbj7fodeHlvj8GyYc4uRrmgqMoe82g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716288612; c=relaxed/simple; bh=n/oAy5vJBvR1F5+qZWIuxrNBXKK0jB6rNDZbMLCp8L8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o6UPiAWtiPF8cFjgpbpn9YJskw9QIUbtlcyNjf7MBoGzWorSRK3IOm9Mnn6+ln9yHCr+HT5JVAgajTpX+KnCOGvSF5tNNPU0yxBs4RUZ1FRmgTKL1WF/ObdXXbMWSWkldGdXYsCKJA9I4du8bkBQ1VA4cd2Tf7NMQwiLm5kAbEI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BidipBjr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8B7BC2BD11; Tue, 21 May 2024 10:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716288611; bh=n/oAy5vJBvR1F5+qZWIuxrNBXKK0jB6rNDZbMLCp8L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BidipBjrGuOkSoCJXdzboXiMvk2URky/b33HNpaGWJeUHyhqmKZS0OY9NUF9hcHb7 6ie3tZdttprh1P9doOvDqnaQq4dtM++Pwem1Iqw5jwBxjU1nc2ctH8vDeucDTmSxqH DmH7Dpe5eAn1gBD5e5TERM9HuHJp+TDqomJ4uz92gwssuxkmZJ4JV6raoZw1PjLn5K wK7Qw139BYrqlgSyF4fOYjCfWZDJsVKbsTMvxC+WrLfSl92f8fRbzEMbXYeDkMW2NC 3H5cwzIVjiyC4CTb578+XkLarmsYLvVYirxPHdws2MuGC+cdG0pxza3/c019sMX+WF 7nRFnK+VteRIw== From: Jiri Olsa To: Steven Rostedt , Masami Hiramatsu , Oleg Nesterov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: 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: [PATCHv6 bpf-next 8/9] selftests/bpf: Add uretprobe shadow stack test Date: Tue, 21 May 2024 12:48:24 +0200 Message-ID: <20240521104825.1060966-9-jolsa@kernel.org> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240521104825.1060966-1-jolsa@kernel.org> References: <20240521104825.1060966-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Adding uretprobe shadow stack test that runs all existing uretprobe tests with shadow stack enabled if it's available. 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.0