Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3847837pxy; Mon, 26 Apr 2021 11:09:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZjI46WjmL6PTEvTjoV+HLSc/eHERu6e+3Ohu5HMs1PLfJYKjAwxVwcyiCc/42mzmFxrIM X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr22941225edu.268.1619460555538; Mon, 26 Apr 2021 11:09:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460555; cv=none; d=google.com; s=arc-20160816; b=sFk4A/l2IM02Xj7/Fkk3n989keWMdKpcxhlnDqex1/mhbV44l+LoSU9TLJHF+JhSLP 4Mc+CPbjGWe4qrbxAEntxO2F5wDTC7YoK5NUdpy0WsmpWrFdivJY/GIa8+WreTIBWrLU NfHiJ2YvCd3ymv5sIytibnmBdYlWTh4JsMf6YtTYyBk51sPLh8e3bD3tkD3D+HrtMwGz NGWMbem2txonTD2Wmh2wSiDYpdFqjYmFNX6csrGTGIP51Py1ontMP1wG1l/5oREkFuPD RN1wLrQ7cs6VjB3O3VIx+ag0YjyF1xgY0axDw0WPqwnhtKdfggdhdgYC7v7/bYqAmMpf Zfrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X6rX98hDfmwMvXNLYGLENiBjXrMNx3f1cVY9RbI6yg0=; b=h27znj72ON+nQhSmhedamX0cvwLJGMnc+LQsMAncKx4ytXxPGj6IISVL12V6HHOsEd kufhralexfaTUZqk+tzkUzyIO8GvJlQaXR/zGVX8r1hCamfFUsXGfDdzkGN5qA8liPmv 3Zy0KcoZoK2OHwN3zg+ZNPK0FuvqbBSpTUoTDLJCofgmncOhDmi6X8xtkoqeEpIQyAT6 Lr1S2c9vGaaf3ADjfgd7C1Uaux7XVL6VUqDXIM2F7ogHOuAwJilSIkIjp5yoAa9bN2Ki Ebd2OSLzj5IzYOfKJJQQ9F1uxIdwCCkscW5Gaw90HA0b8a6QJ5RTYs4tDMiajaecTgUX PTHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=O7G+JeIX; 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 zh8si16261035ejb.639.2021.04.26.11.08.51; Mon, 26 Apr 2021 11:09:15 -0700 (PDT) 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; dkim=pass header.i=@sargun.me header.s=google header.b=O7G+JeIX; 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 S234305AbhDZSHN (ORCPT + 99 others); Mon, 26 Apr 2021 14:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234294AbhDZSHG (ORCPT ); Mon, 26 Apr 2021 14:07:06 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCA5EC06175F for ; Mon, 26 Apr 2021 11:06:21 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id f6-20020a17090a6546b029015088cf4a1eso5764344pjs.2 for ; Mon, 26 Apr 2021 11:06:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X6rX98hDfmwMvXNLYGLENiBjXrMNx3f1cVY9RbI6yg0=; b=O7G+JeIXayDNkXmfUzuLpkBvyA0+i+YAiu+ONggStuJ90PCRVFHBB7ssGmkC7PLhqF cx7xn5iiunf4FK4prQDhpUchjkMSnI3UvnO/fpLzIbU02VKtj55Vv7nCshDlIM68noVU hd6Jh2LXxpFcZ/3dI0AxOV8kdGVf8fAR08+zI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X6rX98hDfmwMvXNLYGLENiBjXrMNx3f1cVY9RbI6yg0=; b=CXf6QsnBAXzSccPJU55kET7PBJPiPKL6YK6Mk+82Ei+rUKRGZEBhkkeFHXtJcGiYgK j9+vFtFl+Wg9AEFWIvdE5EhxOtCCeNGd0prH6hfOZA2mlDVAxwjhzQaZPaI+TT9j1hD8 +5G1V5bYcvfQR4OGAJXXDBkKC75+hFyGDpRQ5U9REWNgqhivfsFEb3BNguJ1U/RZ9cpD NKshgMi4neKuFdRRRgIsfzAkjPl7QPnIN7IP8GNEn3nvDkIauY4sOgv8WVzJ+gftfN5R bWMCA8XyaG+vM7BTLdoaeacSnSlT9XSFGXize0RVT9bI/p/bdZjZ+A9AEO96fMTCzrgd kELw== X-Gm-Message-State: AOAM5338AP8SqEji7RiZQnI32mVj1YC1q/p3Lxyha/KVvdmVZV49nm5d BNZjvCy8z1WRD2s+wPb/LDv+yA== X-Received: by 2002:a17:90b:30c3:: with SMTP id hi3mr9150037pjb.235.1619460381235; Mon, 26 Apr 2021 11:06:21 -0700 (PDT) Received: from ubuntu.netflix.com (136-25-20-203.cab.webpass.net. [136.25.20.203]) by smtp.gmail.com with ESMTPSA id j7sm326835pfd.129.2021.04.26.11.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 11:06:20 -0700 (PDT) From: Sargun Dhillon To: Kees Cook , LKML , Linux Containers , Rodrigo Campos , Christian Brauner Cc: Sargun Dhillon , =?UTF-8?q?Mauricio=20V=C3=A1squez=20Bernal?= , Tycho Andersen , Giuseppe Scrivano , Andy Lutomirski , Will Drewry , Alban Crequy Subject: [PATCH RESEND 3/5] selftests/seccomp: Add test for wait killable notifier Date: Mon, 26 Apr 2021 11:06:08 -0700 Message-Id: <20210426180610.2363-4-sargun@sargun.me> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210426180610.2363-1-sargun@sargun.me> References: <20210426180610.2363-1-sargun@sargun.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds a test for the positive case of the wait killable notifier, in testing that when the feature is activated the process acts as expected -- in not terminating on a non-fatal signal, and instead queueing it up. There is already a test case for normal handlers and preemption. Signed-off-by: Sargun Dhillon --- tools/testing/selftests/seccomp/seccomp_bpf.c | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 98c3b647f54d..34140ce2ab21 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -235,6 +235,10 @@ struct seccomp_notif_addfd { }; #endif +#ifndef SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE +#define SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE (1UL << 0) /* Prevent task from being interrupted */ +#endif + struct seccomp_notif_addfd_small { __u64 id; char weird[4]; @@ -4135,6 +4139,66 @@ TEST(user_notification_addfd_rlimit) close(memfd); } +TEST(user_notification_signal_wait_killable) +{ + pid_t pid; + long ret; + int status, listener, sk_pair[2]; + struct seccomp_notif req = { + .flags = SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE, + }; + struct seccomp_notif_resp resp = {}; + char c; + + ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + ASSERT_EQ(0, ret) { + TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); + } + + ASSERT_EQ(socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sk_pair), 0); + ASSERT_EQ(fcntl(sk_pair[0], F_SETFL, O_NONBLOCK), 0); + + listener = user_notif_syscall(__NR_gettid, + SECCOMP_FILTER_FLAG_NEW_LISTENER); + ASSERT_GE(listener, 0); + + pid = fork(); + ASSERT_GE(pid, 0); + + if (pid == 0) { + close(sk_pair[0]); + handled = sk_pair[1]; + if (signal(SIGUSR1, signal_handler) == SIG_ERR) { + perror("signal"); + exit(1); + } + + ret = syscall(__NR_gettid); + exit(!(ret == 42)); + } + close(sk_pair[1]); + + EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0); + EXPECT_EQ(kill(pid, SIGUSR1), 0); + /* Make sure we didn't get a signal */ + EXPECT_EQ(read(sk_pair[0], &c, 1), -1); + /* Make sure the notification is still alive */ + EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_ID_VALID, &req.id), 0); + + resp.id = req.id; + resp.error = 0; + resp.val = 42; + + EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_SEND, &resp), 0); + + EXPECT_EQ(waitpid(pid, &status, 0), pid); + EXPECT_EQ(true, WIFEXITED(status)); + EXPECT_EQ(0, WEXITSTATUS(status)); + /* Check we eventually received the signal */ + EXPECT_EQ(read(sk_pair[0], &c, 1), 1); +} + + /* * TODO: * - expand NNP testing -- 2.25.1