Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1863529lqt; Sun, 21 Apr 2024 12:43:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUI9q+uscqoutOk8VBTjiAAJrcbXJ38hpEjVn6Y3IjxqtPZg0ITufAIl2/Ay8fxCn48NMFS0KAdoO5cV4U8Dt1klS86Y57A5GdwxLtcjQ== X-Google-Smtp-Source: AGHT+IFV9lRzynuzDbB/Rl8F2adKfCsvYVpMP1QC1XVmQAYKNwVp8TCe0kbyAiZNaXpLRtdSHR/u X-Received: by 2002:aca:180e:0:b0:3c5:e901:e3ec with SMTP id h14-20020aca180e000000b003c5e901e3ecmr8689240oih.16.1713728633191; Sun, 21 Apr 2024 12:43:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713728633; cv=pass; d=google.com; s=arc-20160816; b=szf32DOwUCaIHAkk4FiJDbOGbyw4nqKiKclsjdJWqxAZfuc/yHARGrQUlCkogVW5r9 ZO/7ZvXUcd1GmvGpDUieL6eSBxhOSJdzPKw6DeGNoHp083gCKnpP4Zcq7Y3Of0jLrQGo OfWFNfYp8m8EQ9GouShw4zSqLnl9SAhf32owJjlUhxnQQq1vvWDlUIK16WvdqXPAUiKo l/Xn1QE5zQwM/Uw/luM4S8iEwAOyc77q4mxfATWtjN6XFs+2FYQMmOa8jQEIW1yOEnpO 9OHKQTvLFKs0ccGRIgudh1TvhjFDZiBTC8trqHQab0RRpleyFEEFcKTP7jpTuAWHS/aW 071g== 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=ZDtClU3IU7T/TouF6O3aXIbVfl4vYoN6HcRHPlwMrsc=; fh=BGjS9EmzIs1KVwcaqROnfMbpy2e6oo3cY1daNsDmauE=; b=Qvaapl1tv0MLQWjTUJDT39tUgc4i+5E6frMCHQ4UmBWV9oIsb3grKlMNlYbYey3Ce/ 21VSv7jR/o5GqG96qejTA9HzCd3iP/0GI8Qnfo1haTsmtzHF5zHf4MCYYEhtPk/Mj0tK f3G9Y3H1XP6MaxFE7197nV1m4Yxtsuv3AbYH9vPOT+uLv/sQnW1WRuWN2aL296OEXacE /H6dvp++wqhWHUf9uNAnExJ2EvsJ3wmg7x+qSJH3GM3BjK/dUW4aaBGrOL4ltQQFD0WB 0EZLg/uyn0bkuGu+NlMH42BJmAVG5bilEMHNzKHhh2HxZ96En40+xcILxAQGCqFfzuG+ 2cBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jn7soWvs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f31-20020a631f1f000000b005ce030a6460si6445346pgf.71.2024.04.21.12.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 12:43:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jn7soWvs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152601-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152601-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1C521B20D03 for ; Sun, 21 Apr 2024 19:43:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B6F444361; Sun, 21 Apr 2024 19:43:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jn7soWvs" 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 A31F53FB14; Sun, 21 Apr 2024 19:43:16 +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=1713728596; cv=none; b=DO4s5P3T4TVYKFwYxr1kvq3Q7f+CFpb7wR+n2WR5MMw6H1+4Uv1GUOpo1jyz/xj20HsRRoYUpdHIPYWVhheH9XkM7lj/RqZB+ah9bgq9V8vBL2Pgh3FDdSMcM62YlaOttNqoxOp7mWD7D3rU307sle7NyeV90uAjdIk4AlBVNnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713728596; c=relaxed/simple; bh=zXsQFP+lBWcQOzhNUiIZY9EDEZ2vOGD8pKD7bKL08jE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XidYYX0vf+hWCAlyaEKMv2ynEQC6Rcyyt6809PuPAcGCWGSqDk5vqpfSQAqvbRfGiyPa4BUsiQIM40Fcl2DuCuGDE8+XrKGWWAXa79EaIlmJp0JsruO7oZO7icTCrvHUC8bWcu1HS2fQc0clHrINL2U5omYk8DolW4oJuizBoIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jn7soWvs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B21F9C113CE; Sun, 21 Apr 2024 19:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713728596; bh=zXsQFP+lBWcQOzhNUiIZY9EDEZ2vOGD8pKD7bKL08jE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jn7soWvs0sLr9hsTFqTnjXPH+4DzuW3o3L0MDPilqGczRK9fX7SmEV5p9Q+3PA8Gc /tHNoVHpEtrnDhSQ+5+FDP1KT83QyT9vyVk12ySLSS2pBl+rViPWm/65YekugUoCG2 vNo+Woa8nRi0iVTJxsnZMLwz3xT+oxNySIhAAhuXJ05FBQR7WcHS7G9+0R8DTf+GMx UygmSGPv5AaWIgi7DFjz+5qpl17T7j+oR6UeramK0hdiWxQBGlqpzveX5XksKttmos ABHkegTKGpBGDKmxyXqXoXz+wiXk3NUDZ96dpY7E6OmmYwbci2KutYpCq7dlunpJNn Smru/o4B/1Mlg== 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, x86@kernel.org, bpf@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend , Peter Zijlstra , Thomas Gleixner , "Borislav Petkov (AMD)" , Ingo Molnar , Andy Lutomirski Subject: [PATCHv3 bpf-next 5/7] selftests/bpf: Add uretprobe syscall call from user space test Date: Sun, 21 Apr 2024 21:42:04 +0200 Message-ID: <20240421194206.1010934-6-jolsa@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240421194206.1010934-1-jolsa@kernel.org> References: <20240421194206.1010934-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 test to verify that when called from outside of the trampoline provided by kernel, the uretprobe syscall will cause calling process to receive SIGILL signal and the attached bpf program is no executed. Signed-off-by: Jiri Olsa --- .../selftests/bpf/prog_tests/uprobe_syscall.c | 92 +++++++++++++++++++ .../selftests/bpf/progs/uprobe_syscall_call.c | 15 +++ 2 files changed, 107 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_call.c diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c index 1a50cd35205d..9233210a4c33 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c @@ -7,7 +7,10 @@ #include #include #include +#include +#include #include "uprobe_syscall.skel.h" +#include "uprobe_syscall_call.skel.h" __naked unsigned long uretprobe_regs_trigger(void) { @@ -209,6 +212,85 @@ static void test_uretprobe_regs_change(void) } } +#ifndef __NR_uretprobe +#define __NR_uretprobe 462 +#endif + +__naked unsigned long uretprobe_syscall_call_1(void) +{ + /* + * Pretend we are uretprobe trampoline to trigger the return + * probe invocation in order to verify we get SIGILL. + */ + asm volatile ( + "pushq %rax\n" + "pushq %rcx\n" + "pushq %r11\n" + "movq $" __stringify(__NR_uretprobe) ", %rax\n" + "syscall\n" + "popq %r11\n" + "popq %rcx\n" + "retq\n" + ); +} + +__naked unsigned long uretprobe_syscall_call(void) +{ + asm volatile ( + "call uretprobe_syscall_call_1\n" + "retq\n" + ); +} + +static void __test_uretprobe_syscall_call(void) +{ + struct uprobe_syscall_call *skel = NULL; + int err; + + skel = uprobe_syscall_call__open_and_load(); + if (!ASSERT_OK_PTR(skel, "uprobe_syscall_call__open_and_load")) + goto cleanup; + + err = uprobe_syscall_call__attach(skel); + if (!ASSERT_OK(err, "uprobe_syscall_call__attach")) + goto cleanup; + + uretprobe_syscall_call(); + +cleanup: + uprobe_syscall_call__destroy(skel); +} + +static void trace_pipe_cb(const char *str, void *data) +{ + if (strstr(str, "uretprobe called") != NULL) + (*(int *)data)++; +} + +static void test_uretprobe_syscall_call(void) +{ + int pid, status, found = 0; + + pid = fork(); + if (!ASSERT_GE(pid, 0, "fork")) + return; + + if (pid == 0) { + __test_uretprobe_syscall_call(); + _exit(0); + } + + waitpid(pid, &status, 0); + + /* verify the child got killed with SIGILL */ + ASSERT_EQ(WIFSIGNALED(status), 1, "WIFSIGNALED"); + ASSERT_EQ(WTERMSIG(status), SIGILL, "WTERMSIG"); + + /* verify the uretprobe program wasn't called */ + ASSERT_OK(read_trace_pipe_iter(trace_pipe_cb, &found, 1000), + "read_trace_pipe_iter"); + ASSERT_EQ(found, 0, "found"); +} #else static void test_uretprobe_regs_equal(void) { @@ -219,6 +301,11 @@ static void test_uretprobe_regs_change(void) { test__skip(); } + +static void test_uretprobe_syscall_call(void) +{ + test__skip(); +} #endif void test_uprobe_syscall(void) @@ -228,3 +315,8 @@ void test_uprobe_syscall(void) if (test__start_subtest("uretprobe_regs_change")) test_uretprobe_regs_change(); } + +void serial_test_uprobe_syscall_call(void) +{ + test_uretprobe_syscall_call(); +} diff --git a/tools/testing/selftests/bpf/progs/uprobe_syscall_call.c b/tools/testing/selftests/bpf/progs/uprobe_syscall_call.c new file mode 100644 index 000000000000..5ea03bb47198 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/uprobe_syscall_call.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "vmlinux.h" +#include +#include + +struct pt_regs regs; + +char _license[] SEC("license") = "GPL"; + +SEC("uretprobe//proc/self/exe:uretprobe_syscall_call") +int uretprobe(struct pt_regs *regs) +{ + bpf_printk("uretprobe called"); + return 0; +} -- 2.44.0