From patchwork Fri Aug 16 04:17:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 1973050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=I3oSnzbd; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WlTHF0XfSz1yfB for ; Fri, 16 Aug 2024 14:17:42 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7FED73D21B6 for ; Fri, 16 Aug 2024 06:17:29 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E54173CDE64 for ; Fri, 16 Aug 2024 06:17:25 +0200 (CEST) Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 1931A10006D8 for ; Fri, 16 Aug 2024 06:17:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=7RAGt pbn4Nfp13H7BOhMmYrZzzRoo/fKACnFXztqViI=; b=I3oSnzbddeTCpu0qaJ7G0 iQMKdqXtFQGGtfDM7iJqQtQBagCCqyDazx/h24MjHr8y51ZtAiK91X40uY7sBOt1 3TDQ8fQpRHDZgj75VbOZy6yHgvtFgcdtF8YmJl24bVJLrEImVei8I03imSRDHNH1 l2hWkEsYkER7btKdtT5pBg= Received: from fedora-40.. (unknown [106.146.87.91]) by gzga-smtp-mta-g3-0 (Coremail) with SMTP id _____wAnD_3J0r5mHgIUCQ--.48845S2; Fri, 16 Aug 2024 12:17:15 +0800 (CST) From: Xiao Yang To: ltp@lists.linux.it Date: Fri, 16 Aug 2024 13:17:11 +0900 Message-ID: <20240816041711.153530-1-ice_yangxiao@163.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-CM-TRANSID: _____wAnD_3J0r5mHgIUCQ--.48845S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw13GFyrWw1UCr4kZry3XFb_yoW5Kr43pF y7JFW7Aw4fJa4xXr43Xr1jkFW7Cw1rJF17GrWjywn09r93ZFy7tF4qqFy3G348JrZ7CayD CanYvrs3Ka1DZFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUga9xUUUUU= X-Originating-IP: [106.146.87.91] X-CM-SenderInfo: 5lfhs5xdqj5xldr6il2tof0z/xtbB0ho9XmWXzvVL7gACsF X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] syscalls/mseal02.c: Add new testcase 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" New testcase is added to check various errnos for mseal(2). Signed-off-by: Xiao Yang --- runtest/syscalls | 1 + testcases/kernel/syscalls/mseal/.gitignore | 1 + testcases/kernel/syscalls/mseal/mseal02.c | 75 ++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 testcases/kernel/syscalls/mseal/mseal02.c diff --git a/runtest/syscalls b/runtest/syscalls index fea0c9828..1591158de 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -886,6 +886,7 @@ mremap05 mremap05 mremap06 mremap06 mseal01 mseal01 +mseal02 mseal02 msgctl01 msgctl01 msgctl02 msgctl02 diff --git a/testcases/kernel/syscalls/mseal/.gitignore b/testcases/kernel/syscalls/mseal/.gitignore index e13090994..2348efe30 100644 --- a/testcases/kernel/syscalls/mseal/.gitignore +++ b/testcases/kernel/syscalls/mseal/.gitignore @@ -1 +1,2 @@ mseal01 +mseal02 diff --git a/testcases/kernel/syscalls/mseal/mseal02.c b/testcases/kernel/syscalls/mseal/mseal02.c new file mode 100644 index 000000000..62eeb25b2 --- /dev/null +++ b/testcases/kernel/syscalls/mseal/mseal02.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Author: Xiao Yang + */ + +/*\ + * [Description] + * + * Check various errnos for mseal(2). + * + * - mseal() fails with EINVAL if flags is invalid. + * - mseal() fails with EINVAL if the start address is not page aligned. + * - mseal() fails with EINVAL if address range overflows. + * - mseal() fails with ENOMEM if the start address is not allocated. + * - mseal() fails with ENOMEM if the end address is not allocated. + * - mseal() fails with ENOMEM if there is a gap (unallocated memory) between start and end address. + * + * TODO: support both raw syscall and libc wrapper via .test_variants. + */ + +#define _GNU_SOURCE + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static void *start_addr, *unaligned_start_addr, *unallocated_start_addr, *unallocated_end_addr; +static size_t page_size, twopages_size, fourpages_size, overflow_size; + +static struct tcase { + void **addr; + size_t *len; + unsigned long flags; + int exp_err; +} tcases[] = { + {&start_addr, &page_size, ULONG_MAX, EINVAL}, + {&unaligned_start_addr, &page_size, 0, EINVAL}, + {&start_addr, &overflow_size, 0, EINVAL}, + {&unallocated_start_addr, &twopages_size, 0, ENOMEM}, + {&unallocated_end_addr, &twopages_size, 0, ENOMEM}, + {&start_addr, &fourpages_size, 0, ENOMEM}, +}; + +static void run(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + TST_EXP_FAIL(tst_syscall(__NR_mseal, *tc->addr, *tc->len, tc->flags), tc->exp_err, + "mseal(%p, %lu, %lu)", *tc->addr, *tc->len, tc->flags); +} + +static void setup(void) +{ + page_size = getpagesize(); + twopages_size = page_size * 2; + fourpages_size = page_size * 4; + overflow_size = ULONG_MAX - page_size + 2; + start_addr = SAFE_MMAP(NULL, fourpages_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + unaligned_start_addr = start_addr + 1; + SAFE_MUNMAP(start_addr + twopages_size, page_size); + unallocated_start_addr = start_addr + twopages_size; + unallocated_end_addr = start_addr + page_size; +} + +static void cleanup(void) +{ + SAFE_MUNMAP(start_addr, fourpages_size); +} + +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, +};