Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 850B4C433B4 for ; Mon, 26 Apr 2021 18:06:25 +0000 (UTC) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0DADD61009 for ; Mon, 26 Apr 2021 18:06:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DADD61009 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sargun.me Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=containers-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id B3BD34044A; Mon, 26 Apr 2021 18:06:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8avse6iDubrq; Mon, 26 Apr 2021 18:06:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTP id 68F7C40421; Mon, 26 Apr 2021 18:06:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4AA26C000E; Mon, 26 Apr 2021 18:06:23 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id BA2F6C000B for ; Mon, 26 Apr 2021 18:06:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id A8F3E60905 for ; Mon, 26 Apr 2021 18:06:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=sargun.me Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YtcAdcoinKY3 for ; Mon, 26 Apr 2021 18:06:21 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by smtp3.osuosl.org (Postfix) with ESMTPS id E903E608E7 for ; Mon, 26 Apr 2021 18:06:21 +0000 (UTC) Received: by mail-pj1-x102c.google.com with SMTP id gc22-20020a17090b3116b02901558435aec1so2038795pjb.4 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=fKntD769TPFR2xrl2oaCp3q4QPfLv1qQNwnBqofzEb0XXv+I3FJM0zmQg8Va5jg8ZG kgSnFX9TD5T7EFWkn4VPEvmUi7vBoAt49G3hTDGEJfzOcO/ijPXzQJoeDwQePl6itmro 79T57Y8y4zSLExByKCLACmrKLDasKDpyG7WCVRqWIMpPrt214fgxfWEOAU7t256Xw/U8 mT0Ux+Z+OzTE7inP7iN+oEps6AYqQeESBRSvRGMu6GSoO2Piefq/KhwCnMD9lnEiK8Mo sQzXmzaYkoL5bkLUqGnfP+vW3F1V79prSi8rN1ViEmeqWZB1NiIWN2gQRJnm/6q3mf5g StkQ== X-Gm-Message-State: AOAM530QETYVo51XWKOCCjwd1SEj7MIhobRitvxCYZUTFOE2GxVHK1ip bSDnDH/ZqmSotr5Vnh9Ypnc/jQ== X-Google-Smtp-Source: ABdhPJxac+qneaPoiDM++eOdU6qvTBl1VlpL4cLhCGu1W4aN2kj+jIllJrl+2QYEkF3ULEPQPY0arg== 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 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 Cc: Giuseppe Scrivano , Will Drewry , Andy Lutomirski , Alban Crequy X-BeenThere: containers@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux Containers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: containers-bounces@lists.linux-foundation.org Sender: "Containers" 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 _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/containers