From patchwork Tue Jul 28 16:22:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 1337914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=INXzTO77; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGMR04F2Zz9s1x for ; Wed, 29 Jul 2020 02:22:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 618A73C2674 for ; Tue, 28 Jul 2020 18:22:44 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 5D5DD3C176D for ; Tue, 28 Jul 2020 18:22:42 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 831B91400F28 for ; Tue, 28 Jul 2020 18:22:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595953359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TCY+P0QHkO7+pfoxkD7WHwjRtX7kVZx7LZiZNZJbwhI=; b=INXzTO77VlAEztVyfELoTjsBmqDGFjUURnQdV9is3VITf1ziiVYDIGgQPw2ik9UvmATTtr qWFlKkmMgyM8IQMoxVi+vU5TKUDh+H7H9i7RfcxhyHR7NfuhiWe9Xqe2f+fYC6QDUlsZcD V3vSlt8kg1rzJqSDLl9DEq6xr0wpIdg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-Yqez3zVeO3GwW4NooX5Qjw-1; Tue, 28 Jul 2020 12:22:37 -0400 X-MC-Unique: Yqez3zVeO3GwW4NooX5Qjw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 584421902EA0 for ; Tue, 28 Jul 2020 16:22:36 +0000 (UTC) Received: from centennial.enunes.eu.com (unknown [10.40.194.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B135712E8; Tue, 28 Jul 2020 16:22:35 +0000 (UTC) From: Erico Nunes To: ltp@lists.linux.it Date: Tue, 28 Jul 2020 18:22:05 +0200 Message-Id: <20200728162207.332109-1-ernunes@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/3] lib: add function to check for kernel lockdown X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Some syscalls are not available if the kernel is booted using the 'lockdown' feature. That can cause some tests to report fail, showing a message like: Lockdown: iopl01: iopl is restricted; see man kernel_lockdown.7 This patch adds a function that can be used by tests to check for this case, so it can be handled accordingly. Signed-off-by: Erico Nunes Reviewed-by: Li Wang Reviewed-by: Cyril Hrubis --- v2: - just return the lockdown status so tests can handle as needed, instead of just always skipping the test. - handle fgets return value to avoid compiler warning (can't return any sensible value so I just ported what I have seen in other similar cases). --- include/tst_lockdown.h | 8 ++++++++ include/tst_test.h | 1 + lib/tst_lockdown.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 include/tst_lockdown.h create mode 100644 lib/tst_lockdown.c diff --git a/include/tst_lockdown.h b/include/tst_lockdown.h new file mode 100644 index 000000000..383026b1e --- /dev/null +++ b/include/tst_lockdown.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifndef TST_LOCKDOWN_H +#define TST_LOCKDOWN_H + +int tst_lockdown_enabled(void); + +#endif /* TST_LOCKDOWN_H */ diff --git a/include/tst_test.h b/include/tst_test.h index b84f7b9dd..b02de4597 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -40,6 +40,7 @@ #include "tst_hugepage.h" #include "tst_assert.h" #include "tst_cgroup.h" +#include "tst_lockdown.h" /* * Reports testcase result. diff --git a/lib/tst_lockdown.c b/lib/tst_lockdown.c new file mode 100644 index 000000000..024047aae --- /dev/null +++ b/lib/tst_lockdown.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#define TST_NO_DEFAULT_MAIN + +#include +#include +#include + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_safe_stdio.h" +#include "tst_lockdown.h" + +int tst_lockdown_enabled(void) +{ + char line[BUFSIZ]; + const char *lockdown_path = "/sys/kernel/security/lockdown"; + FILE *file; + + if (access("/sys/kernel/security/lockdown", F_OK) != 0) { + tst_res(TINFO, "Unable to determine system lockdown state\n"); + return 0; + } + + file = SAFE_FOPEN(lockdown_path, "r"); + if (!fgets(line, sizeof(line), file)) + tst_brk(TBROK | TERRNO, "fgets %s", lockdown_path); + SAFE_FCLOSE(file); + + return (strstr(line, "[none]") == NULL); +} From patchwork Tue Jul 28 16:22:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 1337915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZqxGrdXP; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGMR45K97z9s1x for ; Wed, 29 Jul 2020 02:22:56 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E6AEB3C26B4 for ; Tue, 28 Jul 2020 18:22:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 2EC3C3C5DAE for ; Tue, 28 Jul 2020 18:22:47 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 908FB200CE7 for ; Tue, 28 Jul 2020 18:22:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595953365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gh7esSoUwIX0iaQCAfVMV9hyKu+1gSYXukML+VO/0NA=; b=ZqxGrdXPe4MFRG/p9TxQMhN2Mn3/L5zgjTTBGYv/BmJCAywpq9t2PkxzKqTKiO5oWK5W4C wkugVzYd/7WNgp6nqsnyMKhsAGC7XxX0eHOufxJzS931iqYU17itid3Lex8ZiLxIOt1K/b 5Wl8soDQHHVFXfy89Xfs7KTf621U5As= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-192-eHfkS059Opi29WeWMI4K_w-1; Tue, 28 Jul 2020 12:22:43 -0400 X-MC-Unique: eHfkS059Opi29WeWMI4K_w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7A591005504 for ; Tue, 28 Jul 2020 16:22:42 +0000 (UTC) Received: from centennial.enunes.eu.com (unknown [10.40.194.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 062E2712F7; Tue, 28 Jul 2020 16:22:41 +0000 (UTC) From: Erico Nunes To: ltp@lists.linux.it Date: Tue, 28 Jul 2020 18:22:06 +0200 Message-Id: <20200728162207.332109-2-ernunes@redhat.com> In-Reply-To: <20200728162207.332109-1-ernunes@redhat.com> References: <20200728162207.332109-1-ernunes@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/3] ioperm01: skip test if kernel is locked down X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" ioperm is restricted under kernel lockdown. Signed-off-by: Erico Nunes --- v2: - update to skip the test here rather than relying on the helper function to skip. --- testcases/kernel/syscalls/ioperm/ioperm01.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testcases/kernel/syscalls/ioperm/ioperm01.c b/testcases/kernel/syscalls/ioperm/ioperm01.c index 4c5c0e6ea..c25baa678 100644 --- a/testcases/kernel/syscalls/ioperm/ioperm01.c +++ b/testcases/kernel/syscalls/ioperm/ioperm01.c @@ -42,6 +42,10 @@ static void verify_ioperm(void) static void setup(void) { + /* ioperm is restricted under kernel lockdown. */ + if (tst_lockdown_enabled()) + tst_brk(TCONF, "Kernel is locked down, skip this test"); + /* * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed * from kernel 2.6.8 to permit 16-bits ioperm From patchwork Tue Jul 28 16:22:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erico Nunes X-Patchwork-Id: 1337916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XAZn848n; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BGMRN554Tz9s1x for ; Wed, 29 Jul 2020 02:23:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 61A063C2680 for ; Tue, 28 Jul 2020 18:23:03 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 979AB3C5DB5 for ; Tue, 28 Jul 2020 18:22:59 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 19F3F1A01CE4 for ; Tue, 28 Jul 2020 18:22:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595953374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O7+Uh0d6cD3Viwn6qaWJS3q+OqUK2nKlSD38iVUwg5s=; b=XAZn848nXnO9N9BrdaPzXeLoMiKv1tAJlehzQ7dtoYbYlCUc5EnXINb1831l/T5o5CQs0d 830eYkA+ye7NQdbft1M/4KnmB0mWFJCqIVzQ7+5YMHZ8yYDjUOEk3o6najm8Zu+wVt5fM/ 6dh+T6bOkYiGHCt4x/dxXiSSuTAcLhY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-132-NDRUlmmpPPCd-m1Eg-BQGA-1; Tue, 28 Jul 2020 12:22:48 -0400 X-MC-Unique: NDRUlmmpPPCd-m1Eg-BQGA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 340021005504 for ; Tue, 28 Jul 2020 16:22:47 +0000 (UTC) Received: from centennial.enunes.eu.com (unknown [10.40.194.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B577712F2; Tue, 28 Jul 2020 16:22:46 +0000 (UTC) From: Erico Nunes To: ltp@lists.linux.it Date: Tue, 28 Jul 2020 18:22:07 +0200 Message-Id: <20200728162207.332109-3-ernunes@redhat.com> In-Reply-To: <20200728162207.332109-1-ernunes@redhat.com> References: <20200728162207.332109-1-ernunes@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/3] iopl01: skip test if kernel is locked down X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" iopl is restricted under kernel lockdown. Signed-off-by: Erico Nunes --- v2: - update to skip the test here rather than relying on the helper function to skip. --- testcases/kernel/syscalls/iopl/iopl01.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testcases/kernel/syscalls/iopl/iopl01.c b/testcases/kernel/syscalls/iopl/iopl01.c index edf586cd1..e5ec1147f 100644 --- a/testcases/kernel/syscalls/iopl/iopl01.c +++ b/testcases/kernel/syscalls/iopl/iopl01.c @@ -42,6 +42,14 @@ static void verify_iopl(void) } } +static void setup(void) +{ + /* iopl is restricted under kernel lockdown. */ + if (tst_lockdown_enabled()) + tst_brk(TCONF, "Kernel is locked down, skip this test"); + +} + static void cleanup(void) { /* @@ -54,6 +62,7 @@ static void cleanup(void) static struct tst_test test = { .test_all = verify_iopl, .needs_root = 1, + .setup = setup, .cleanup = cleanup, };