From patchwork Sat Jan 19 00:12:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tycho Andersen X-Patchwork-Id: 10771853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5372013BF for ; Sat, 19 Jan 2019 00:13:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 436DF30764 for ; Sat, 19 Jan 2019 00:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 358CC307A4; Sat, 19 Jan 2019 00:13:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD66930764 for ; Sat, 19 Jan 2019 00:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730248AbfASANQ (ORCPT ); Fri, 18 Jan 2019 19:13:16 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:36129 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730241AbfASAMy (ORCPT ); Fri, 18 Jan 2019 19:12:54 -0500 Received: by mail-qt1-f194.google.com with SMTP id t13so17225502qtn.3 for ; Fri, 18 Jan 2019 16:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho-ws.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4xYyUhHddUIYM/qVhIDdz28Cxrw9f+oJSbudf679vJA=; b=Tj4U5JIdYV5Zdhy33wHxsxGsLIp7ac1oDRlYsBWgr4RBgbAEwto+lVomOViEK+6+/d VwOzM7/ufX17prkUwcsJyXPf/SXLRIhufHIGk4MP+uqFW3AJjz1cAmsemVtOtW1RWouE Wy87UK0jk0dxmaYgbkKg66UCnkO4YF7gb5cHVYMCJpkh4p771WEqYkGJNp26Y8CJPABo F1SXiqwHZOeoAbQmubP+9TPCFnwYWbPpcJ7wBJCvNf1OwekYx1MBOEGHDe4Qzm61kYqH HIJWShQUaX5fbCE6ISy8WOvpE8ZrnWMcOWPjFoLiBTXHONdZWwbyHkXmDxPjEv1yZhvE 39tg== 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=4xYyUhHddUIYM/qVhIDdz28Cxrw9f+oJSbudf679vJA=; b=Ws4DQVcJNuskSwmzFcZDyCbSqB2x/F6fQQn8idNF+ZT9IwDS5wWUNeMIa0qaHGkAEF FGyVSBMy2ScEoi/E9dTavMKcYaj9m1CdgJ4HlSKLEFuVnjSLHekgbJy7hjduANBmvV2b 30Ioh2j+4agXqnQuTYAcOS6QvTUyF6Ey9qn7Zu+4QX7QjIpHpFpEhn70WmKFBQUd7QBt X7m2rJSgJh2GeOkTl8EnqgIOJfdMFn7qmNeaDAeBjg167kxWRIP8fTfoXditQRwYuPsp VbD3Pu3sxG5Z8CX0rPQKjRwxiOG0UIJTDkCK81RcU3xeSZ10jtXCVrXcMRf+U61fJ2wY 6Enw== X-Gm-Message-State: AJcUukfPQdX3EbDmPFNQC6AhYokLg4f/XJP7XIwqRZHS7exJUdCcjPDi 6q+GKW0XliKrzYERsI5L/T4MIg== X-Google-Smtp-Source: ALg8bN79Iu3vj7HxoY6RJSVdIIaOABF51ItMX6RQiNJ+s5Ho4VEm7NAcTzM3xLtYdtQ/vT3p7fwxZA== X-Received: by 2002:aed:2044:: with SMTP id 62mr18135646qta.11.1547856773475; Fri, 18 Jan 2019 16:12:53 -0800 (PST) Received: from localhost.localdomain ([64.125.109.186]) by smtp.gmail.com with ESMTPSA id m14sm41140501qka.21.2019.01.18.16.12.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 16:12:52 -0800 (PST) From: Tycho Andersen To: Shuah Khan , Kees Cook Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Tycho Andersen Subject: [PATCH 5/6] selftests: set NO_NEW_PRIVS bit in seccomp user tests Date: Fri, 18 Jan 2019 17:12:16 -0700 Message-Id: <20190119001217.12660-6-tycho@tycho.ws> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190119001217.12660-1-tycho@tycho.ws> References: <20190119001217.12660-1-tycho@tycho.ws> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP seccomp() doesn't allow users who aren't root in their userns to attach filters unless they have the nnp bit set, so let's set it so that these tests can pass when run as an unprivileged user. This idea stolen from the other seccomp tests, which use this trick :) Signed-off-by: Tycho Andersen --- tools/testing/selftests/seccomp/seccomp_bpf.c | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index ab6b6620f522..a4a7dce1a91b 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -3026,6 +3026,11 @@ TEST(user_notification_basic) .filter = filter, }; + 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!"); + } + pid = fork(); ASSERT_GE(pid, 0); @@ -3107,6 +3112,11 @@ TEST(user_notification_kill_in_middle) struct seccomp_notif req = {}; struct seccomp_notif_resp resp = {}; + 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!"); + } + listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); ASSERT_GE(listener, 0); @@ -3154,6 +3164,11 @@ TEST(user_notification_signal) 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); listener = user_trap_syscall(__NR_gettid, @@ -3219,6 +3234,11 @@ TEST(user_notification_closed_listener) long ret; int status, listener; + 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!"); + } + listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); ASSERT_GE(listener, 0); @@ -3350,6 +3370,10 @@ TEST(user_notification_fault_recv) struct seccomp_notif req = {}; struct seccomp_notif_resp resp = {}; + ASSERT_EQ(prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0), 0) { + TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!"); + } + listener = user_trap_syscall(__NR_getpid, SECCOMP_FILTER_FLAG_NEW_LISTENER); ASSERT_GE(listener, 0);