From patchwork Tue Apr 16 22:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13632657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8A17C4345F for ; Tue, 16 Apr 2024 22:10:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B3866B009D; Tue, 16 Apr 2024 18:10:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63BE56B009E; Tue, 16 Apr 2024 18:10:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48E876B00A0; Tue, 16 Apr 2024 18:10:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 24AD26B009D for ; Tue, 16 Apr 2024 18:10:16 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9A6FB80742 for ; Tue, 16 Apr 2024 22:10:15 +0000 (UTC) X-FDA: 82016789190.04.9726A28 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf13.hostedemail.com (Postfix) with ESMTP id C2F202001F for ; Tue, 16 Apr 2024 22:10:12 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="DvTjV+/d"; spf=pass (imf13.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.214.181 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713305412; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wxVHDOvUhVBVzAOb5wpvBaQ8ZT8i2HrkTBsI4fhOGcg=; b=yr1nweHV60NswUYUQHb/FfKO5NsKHpwjkHEBFsVtfyXjOy5VxN5bZZw0iHLODFESk+FiQg 0CeupMbexIBWhLs+hMFsH1QuhZE5tlydbMu2ZCZbACUo2vUFT91c9/wFiQ2bFVIW+rqb/D AhPHqJUY4st7SFYzQLnmiIH4CfF7qYU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="DvTjV+/d"; spf=pass (imf13.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.214.181 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713305412; a=rsa-sha256; cv=none; b=hPMRkxq6hdvRdgEw5FBJVLZRgPAWlcH1F4G3F8ZfpvMuoSHO9/rcY+Uv2pN1VsaY2HVObb La8wLLx//16W5/cPfyBOS7/yhnPBJ6kwNEAidqLpuG7Ypbl7Alj78ooSarpQwzWZrWf1BP EESmh9FWKDK8yu7vyhtLnUbBs1zuAgo= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1e65a1370b7so27961875ad.3 for ; Tue, 16 Apr 2024 15:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713305411; x=1713910211; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wxVHDOvUhVBVzAOb5wpvBaQ8ZT8i2HrkTBsI4fhOGcg=; b=DvTjV+/dFN+Ye2+t44Y4Dp2gxFJopy3naLNPJ32u2Frr7QmD2bvrUT44Lla+ID61WC wRSh/Wn7bVIdCvHbUzJcm7Nv/0cTeCZa1HqRMVpBC5+O4eDmhe4Ny43TUskzlPQMZAsm wmwNzwzkOhJywV9GojLAd27uirpDru9q4T0Cg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713305411; x=1713910211; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wxVHDOvUhVBVzAOb5wpvBaQ8ZT8i2HrkTBsI4fhOGcg=; b=g24Kms6X0wRBDrDtKD18j3nKRHiGPQRhIfTriJTaZs6PEYDbrxmOrzBvattfqbSKNk XzeBqR0unRgvemCYumkPDlAsSxiG2i2IozR8gUoB8yHGCVCGKErzkNAXVqHAFuYXSWZF DSAiikIXXsQD+Ko7FbJTCNNiWvvLhnQVZxDx1Mq8E5+KE2Y7g1S0iA0MV8ur6bCJmS1Y gXdRI5LTRTktGwlyl+gC90IlydeAb7zQpc4x16GlcGf59gg8QS3Lz5AIzaJcJdovp3yA 7rd6At9QcrPQgt+vKe2+NsxCLql3+uJqWIj0/phN8JbSsariWhDWPLAAU3MswwputaBl /dLQ== X-Forwarded-Encrypted: i=1; AJvYcCXl2qyXI2bE5PPNaM3hGWSxtGWf7r9Cc1/w9ZwvyN+wlsUb0ng9Neh5YANcZ8oTrQZTwuit/ipr4TcGSyL3rQ1qsR4= X-Gm-Message-State: AOJu0Ywwp2Q/T0zubRO8z0Y3d3i6oScggiOBmTMxJVdvaQCshxfSDeNy 9rubqsWrZikLmMTtfqqc7FlqCXzRwACUiVIdQhfzcC2y9xwOQSJ4fYH3as/4bA== X-Google-Smtp-Source: AGHT+IFOSdcgQyk6biwC2aPuWcLWnlux4DGUDewTmrRbyQvQfiiI+29eaaKEia9vvpDMeLIYZhwYKQ== X-Received: by 2002:a17:903:1245:b0:1e7:8686:c37b with SMTP id u5-20020a170903124500b001e78686c37bmr7826165plh.22.1713305411466; Tue, 16 Apr 2024 15:10:11 -0700 (PDT) Received: from localhost (15.4.198.104.bc.googleusercontent.com. [104.198.4.15]) by smtp.gmail.com with UTF8SMTPSA id d10-20020a170902ceca00b001e41e968a61sm10246065plg.223.2024.04.16.15.10.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Apr 2024 15:10:11 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org, keescook@chromium.org, usama.anjum@collabora.com Cc: jeffxu@google.com, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, sroettger@google.com, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org, willy@infradead.org, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, deraadt@openbsd.org, corbet@lwn.net, Liam.Howlett@oracle.com, surenb@google.com, merimus@google.com, rdunlap@infradead.org, Jeff Xu Subject: [PATCH 1/1] selftest mm/mseal: style change Date: Tue, 16 Apr 2024 22:09:44 +0000 Message-ID: <20240416220944.2481203-2-jeffxu@chromium.org> X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog In-Reply-To: <20240416220944.2481203-1-jeffxu@chromium.org> References: <20240416220944.2481203-1-jeffxu@chromium.org> MIME-Version: 1.0 X-Stat-Signature: a85953qiyrch614nsy78ay3amdbnsn1o X-Rspamd-Queue-Id: C2F202001F X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1713305412-708173 X-HE-Meta: U2FsdGVkX1+J+YRW3PeCF/T2wYGQTujs2OzkuvWSJ1gsdlPXOH1FgHnbYA6SxxHbrS3lq5mXIVxSx26kYVbL7RAZsL74bZAWWN/aL5E4cg5L9YMGIOIpUXs2yAJ4FO8sO94BJtGKHCZ66ksHFZ9aYCYVP2NJNmr6/6GghrYdcs/Xbm4V9cSiMdSanhfJ9s+A1lKJ6NB9FwzxNtyZb8iI0bPgtAdgUMiUQ16LgTXghh5j9h3a51wUtY7s/x7RePC05v6gU6DIEBsiMchIK/XfZRpWKIUFmYiZhw97bx2DbL3fAsZkLUdnBFD1cJI4XkxAfb0TkBAXBDxexSzEPqsg42Pr0/8FUi6aNg0WSuQFBgR8iA0YHODu0dMkesxZg1SSJfalO+YcT6Bzgb3AmLm/xSh+0gEnxfOJ8bKcIj4lVHs0yJPSUF0yWm0S8V4ymBnm19RDbyr3DEwKe7iQL5pSLpwQ8u22KbwA4KmwrETu+UHD2Q/lk/FwiC9zYvnGl9FTvRwi59AyfbjoKa/6HhbjhYLdpC0VAgxmrRWFfcsAWWiPI/gVNOzC5Gv4ly8m1j57vW8QFNkt7Gq4YZCN35qXmbqrhUx7hQ8LzHhXVoTggeNbTXWtn7Ya7ZKcQH3OWnwjmTxV1yyoTnnUkWpvGAlEkv9Wz5Jp+33VaCWiJitkXPgwiywGGUvcpMka4v+7H+eGNn21if1/N5o8WrJXvLJglNTsE4RlfRYZcrc6C2NzkEoT8rtRk5WlKWSN9ozDEBzRYTlDo5lumiAR2v/Uw4h5faHxfJ3Le8ynDa7WhyK8Jw3H9PvdgrdZWzpwMa2DJ4TU+ho4uyEWnNEVGWZTf3nVHKnk1vf/1t2Pl4RTZn5Xw+3ObarsVAYNeJTFWsrXmBAyaBZcPvF0WzQLp/sEXQ78Eks1OUC3/5OWXtvdWk0K8AX9NHx62m1mmsXR46Am/LmaASNAWLCny47GkgIAVBP wrqFeGCk ez9O6J7THG8cH9gtc3eYq3pcqeQBgZnfqjbaDRN5HoZUhBQ37pnsp3lRRrCu5KeqS66x0OxSG0y4m7VWRTRhzWr0cYZ/v3aTPpeUKj+TacEYseYgcqr5jZIFCK3KoZpKd8xT+zIjOC2NA/uKbh/zgaB/JOkyBnm67IXSKxtSC9V6ZjW+2uSNNp7kpWaRabqfhyknQ29RjU+gsHzIuePEC8Sht8FKxSBOzYC+9KTLKssA5pKcE+zU/4nLzWB/gunzvuaH8b6YycAW3BytXfSIwwVgLdHiHjQMYTK9DXGEMBvYYehU1p6Stc2GlukrPZJjVMuk1wQ9QsiIi15CfFmW2bFgGQmta8Ks8uY1OSR/ufLcK0OkvsIhCZmn1+t7gyhle4ouoJeL3RM+1HUthiJbVmxktgxcJXazpWH6+gTBAKb0dp5hpHmx1iAsKWTxlFInPUcTSMMYGoSmguXFT9sqn92i297gECp3MRPk6L9TH3s27j+uaUaluYWlH4A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Jeff Xu remove "assert" from testcase. remove "return 0" Signed-off-by: Jeff Xu Suggested-by: Muhammad Usama Anjum Reviewed-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/mseal_test.c | 124 +++++++++++++++++------- tools/testing/selftests/mm/seal_elf.c | 3 - 2 files changed, 91 insertions(+), 36 deletions(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 06c780d1d8e5..4a326334726d 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -12,9 +12,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -189,7 +187,6 @@ static void __write_pkey_reg(u64 pkey_reg) asm volatile(".byte 0x0f,0x01,0xef\n\t" : : "a" (eax), "c" (ecx), "d" (edx)); - assert(pkey_reg == __read_pkey_reg()); #endif } @@ -214,7 +211,6 @@ static void set_pkey(int pkey, unsigned long pkey_value) unsigned long mask = (PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE); u64 new_pkey_reg; - assert(!(pkey_value & ~mask)); new_pkey_reg = set_pkey_bits(__read_pkey_reg(), pkey, pkey_value); __write_pkey_reg(new_pkey_reg); } @@ -224,7 +220,6 @@ static void setup_single_address(int size, void **ptrOut) void *ptr; ptr = sys_mmap(NULL, size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - assert(ptr != (void *)-1); *ptrOut = ptr; } @@ -234,24 +229,21 @@ static void setup_single_address_rw(int size, void **ptrOut) unsigned long mapflags = MAP_ANONYMOUS | MAP_PRIVATE; ptr = sys_mmap(NULL, size, PROT_READ | PROT_WRITE, mapflags, -1, 0); - assert(ptr != (void *)-1); *ptrOut = ptr; } -static void clean_single_address(void *ptr, int size) +static int clean_single_address(void *ptr, int size) { int ret; - ret = munmap(ptr, size); - assert(!ret); + return ret; } -static void seal_single_address(void *ptr, int size) +static int seal_single_address(void *ptr, int size) { int ret; - ret = sys_mseal(ptr, size); - assert(!ret); + return ret; } bool seal_support(void) @@ -290,6 +282,7 @@ static void test_seal_addseal(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); ret = sys_mseal(ptr, size); FAIL_TEST_IF_FALSE(!ret); @@ -305,6 +298,7 @@ static void test_seal_unmapped_start(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* munmap 2 pages from ptr. */ ret = sys_munmap(ptr, 2 * page_size); @@ -332,6 +326,7 @@ static void test_seal_unmapped_middle(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* munmap 2 pages from ptr + page. */ ret = sys_munmap(ptr + page_size, 2 * page_size); @@ -363,6 +358,7 @@ static void test_seal_unmapped_end(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* unmap last 2 pages. */ ret = sys_munmap(ptr + 2 * page_size, 2 * page_size); @@ -391,6 +387,7 @@ static void test_seal_multiple_vmas(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split the vma into 3. */ ret = sys_mprotect(ptr + page_size, 2 * page_size, @@ -421,6 +418,7 @@ static void test_seal_split_start(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split at middle */ ret = sys_mprotect(ptr, 2 * page_size, PROT_READ | PROT_WRITE); @@ -445,6 +443,7 @@ static void test_seal_split_end(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split at middle */ ret = sys_mprotect(ptr, 2 * page_size, PROT_READ | PROT_WRITE); @@ -469,7 +468,9 @@ static void test_seal_invalid_input(void) int ret; setup_single_address(8 * page_size, &ptr); - clean_single_address(ptr + 4 * page_size, 4 * page_size); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + ret = clean_single_address(ptr + 4 * page_size, 4 * page_size); + FAIL_TEST_IF_FALSE(!ret); /* invalid flag */ ret = syscall(__NR_mseal, ptr, size, 0x20); @@ -502,6 +503,7 @@ static void test_seal_zero_length(void) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); ret = sys_mprotect(ptr, 0, PROT_READ | PROT_WRITE); FAIL_TEST_IF_FALSE(!ret); @@ -551,6 +553,7 @@ static void test_seal_twice(void) unsigned long size = 4 * page_size; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); ret = sys_mseal(ptr, size); FAIL_TEST_IF_FALSE(!ret); @@ -570,9 +573,12 @@ static void test_seal_mprotect(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); - if (seal) - seal_single_address(ptr, size); + if (seal) { + ret = seal_single_address(ptr, size); + FAIL_TEST_IF_FALSE(!ret); + } ret = sys_mprotect(ptr, size, PROT_READ | PROT_WRITE); if (seal) @@ -591,9 +597,12 @@ static void test_seal_start_mprotect(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); - if (seal) - seal_single_address(ptr, page_size); + if (seal) { + ret = seal_single_address(ptr, page_size); + FAIL_TEST_IF_FALSE(!ret); + } /* the first page is sealed. */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -618,9 +627,12 @@ static void test_seal_end_mprotect(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); - if (seal) - seal_single_address(ptr + page_size, 3 * page_size); + if (seal) { + ret = seal_single_address(ptr + page_size, 3 * page_size); + FAIL_TEST_IF_FALSE(!ret); + } /* first page is not sealed */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -645,9 +657,12 @@ static void test_seal_mprotect_unalign_len(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); - if (seal) - seal_single_address(ptr, page_size * 2 - 1); + if (seal) { + ret = seal_single_address(ptr, page_size * 2 - 1); + FAIL_TEST_IF_FALSE(!ret); + } /* 2 pages are sealed. */ ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE); @@ -671,8 +686,11 @@ static void test_seal_mprotect_unalign_len_variant_2(bool seal) int ret; setup_single_address(size, &ptr); - if (seal) - seal_single_address(ptr, page_size * 2 + 1); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + if (seal) { + ret = seal_single_address(ptr, page_size * 2 + 1); + FAIL_TEST_IF_FALSE(!ret); + } /* 3 pages are sealed. */ ret = sys_mprotect(ptr, page_size * 3, PROT_READ | PROT_WRITE); @@ -696,13 +714,16 @@ static void test_seal_mprotect_two_vma(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split */ ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE); FAIL_TEST_IF_FALSE(!ret); - if (seal) - seal_single_address(ptr, page_size * 4); + if (seal) { + ret = seal_single_address(ptr, page_size * 4); + FAIL_TEST_IF_FALSE(!ret); + } ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE); if (seal) @@ -728,14 +749,17 @@ static void test_seal_mprotect_two_vma_with_split(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split as two vma. */ ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE); FAIL_TEST_IF_FALSE(!ret); /* mseal can apply across 2 vma, also split them. */ - if (seal) - seal_single_address(ptr + page_size, page_size * 2); + if (seal) { + ret = seal_single_address(ptr + page_size, page_size * 2); + FAIL_TEST_IF_FALSE(!ret); + } /* the first page is not sealed. */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -772,10 +796,13 @@ static void test_seal_mprotect_partial_mprotect(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* seal one page. */ - if (seal) - seal_single_address(ptr, page_size); + if (seal) { + ret = seal_single_address(ptr, page_size); + FAIL_TEST_IF_FALSE(!ret); + } /* mprotect first 2 page will fail, since the first page are sealed. */ ret = sys_mprotect(ptr, 2 * page_size, PROT_READ | PROT_WRITE); @@ -795,6 +822,7 @@ static void test_seal_mprotect_two_vma_with_gap(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split. */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -837,6 +865,7 @@ static void test_seal_mprotect_split(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split. */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -873,6 +902,7 @@ static void test_seal_mprotect_merge(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split one page. */ ret = sys_mprotect(ptr, page_size, PROT_READ | PROT_WRITE); @@ -906,6 +936,7 @@ static void test_seal_munmap(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -936,6 +967,7 @@ static void test_seal_munmap_two_vma(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect to split */ ret = sys_mprotect(ptr, page_size * 2, PROT_READ | PROT_WRITE); @@ -976,6 +1008,7 @@ static void test_seal_munmap_vma_with_gap(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); ret = sys_munmap(ptr + page_size, page_size * 2); FAIL_TEST_IF_FALSE(!ret); @@ -1007,6 +1040,7 @@ static void test_munmap_start_freed(bool seal) int prot; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* unmap the first page. */ ret = sys_munmap(ptr, page_size); @@ -1045,6 +1079,8 @@ static void test_munmap_end_freed(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + /* unmap last page. */ ret = sys_munmap(ptr + page_size * 3, page_size); FAIL_TEST_IF_FALSE(!ret); @@ -1074,6 +1110,8 @@ static void test_munmap_middle_freed(bool seal) int prot; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + /* unmap 2 pages in the middle. */ ret = sys_munmap(ptr + page_size, page_size * 2); FAIL_TEST_IF_FALSE(!ret); @@ -1116,6 +1154,7 @@ static void test_seal_mremap_shrink(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1144,6 +1183,7 @@ static void test_seal_mremap_expand(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* ummap last 2 pages. */ ret = sys_munmap(ptr + 2 * page_size, 2 * page_size); FAIL_TEST_IF_FALSE(!ret); @@ -1175,8 +1215,11 @@ static void test_seal_mremap_move(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); setup_single_address(size, &newPtr); - clean_single_address(newPtr, size); + FAIL_TEST_IF_FALSE(newPtr != (void *)-1); + ret = clean_single_address(newPtr, size); + FAIL_TEST_IF_FALSE(!ret); if (seal) { ret = sys_mseal(ptr, size); @@ -1205,6 +1248,7 @@ static void test_seal_mmap_overwrite_prot(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1232,6 +1276,7 @@ static void test_seal_mmap_expand(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* ummap last 4 pages. */ ret = sys_munmap(ptr + 8 * page_size, 4 * page_size); FAIL_TEST_IF_FALSE(!ret); @@ -1262,6 +1307,7 @@ static void test_seal_mmap_shrink(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1290,7 +1336,9 @@ static void test_seal_mremap_shrink_fixed(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); setup_single_address(size, &newAddr); + FAIL_TEST_IF_FALSE(newAddr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1319,7 +1367,9 @@ static void test_seal_mremap_expand_fixed(bool seal) void *ret2; setup_single_address(page_size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); setup_single_address(size, &newAddr); + FAIL_TEST_IF_FALSE(newAddr != (void *)-1); if (seal) { ret = sys_mseal(newAddr, size); @@ -1348,7 +1398,9 @@ static void test_seal_mremap_move_fixed(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); setup_single_address(size, &newAddr); + FAIL_TEST_IF_FALSE(newAddr != (void *)-1); if (seal) { ret = sys_mseal(newAddr, size); @@ -1375,6 +1427,7 @@ static void test_seal_mremap_move_fixed_zero(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1406,6 +1459,7 @@ static void test_seal_mremap_move_dontunmap(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1434,6 +1488,7 @@ static void test_seal_mremap_move_dontunmap_anyaddr(bool seal) void *ret2; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); if (seal) { ret = sys_mseal(ptr, size); @@ -1469,6 +1524,7 @@ static void test_seal_merge_and_split(void) /* (24 RO) */ setup_single_address(24 * page_size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); /* use mprotect(NONE) to set out boundary */ /* (1 NONE) (22 RO) (1 NONE) */ @@ -1700,9 +1756,12 @@ static void test_seal_discard_ro_anon(bool seal) int ret; setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); - if (seal) - seal_single_address(ptr, size); + if (seal) { + ret = seal_single_address(ptr, size); + FAIL_TEST_IF_FALSE(!ret); + } ret = sys_madvise(ptr, size, MADV_DONTNEED); if (seal) @@ -1832,5 +1891,4 @@ int main(int argc, char **argv) test_seal_discard_ro_anon_on_pkey(true); ksft_finished(); - return 0; } diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c index 61a2f1c94e02..7143dc4f1b10 100644 --- a/tools/testing/selftests/mm/seal_elf.c +++ b/tools/testing/selftests/mm/seal_elf.c @@ -12,9 +12,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -179,5 +177,4 @@ int main(int argc, char **argv) test_seal_elf(); ksft_finished(); - return 0; }