From patchwork Fri Aug 30 18:02:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13785416 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 6BFE1CA1009 for ; Fri, 30 Aug 2024 18:02:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 320E96B01F5; Fri, 30 Aug 2024 14:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 234B46B01F6; Fri, 30 Aug 2024 14:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05F356B01F7; Fri, 30 Aug 2024 14:02:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C0D8C6B01F5 for ; Fri, 30 Aug 2024 14:02:47 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5FB0C120321 for ; Fri, 30 Aug 2024 18:02:47 +0000 (UTC) X-FDA: 82509682374.28.58FCBD5 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf05.hostedemail.com (Postfix) with ESMTP id 4AD9D10000D for ; Fri, 30 Aug 2024 18:02:45 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="gv/looj0"; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725040864; 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=O/lLriAP27R5nHPgsK9ypk/521J0I4x/lWwi5ADQ+zA=; b=FCvYxX4G4G8lwGJ0KRUZgFjORGHlDhuVZBABqLqBD59wpoVK0JEDdLOJprv+ib+TRHBemQ 3Je38BKRamQ24EDU9QlMoieAoLRWTT0l3jwLCoz+bBR4+7Re/FRCPws4iWvY5kfZrlLBqq U582QNvnH12QH9rhhahYUuGfqYmoZHs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725040864; a=rsa-sha256; cv=none; b=O3lLH5NqWuv//hxq2FEMzsT/rM66Sw6GQrhL1LPJ9Vir5PhHHLLYJN9qPtEuaw1MCi9fJW SAKFvesXqWIbVuTrNTKeel9z9htxzwzD6gFv/tc/DFnPVXCTeveIDPr+HKdZLcpZ9h09xA 1aiO3AktDrnx+W+hwuOoG0dYPxiKYjk= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="gv/looj0"; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf05.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=jeffxu@chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71420e66ecfso219156b3a.0 for ; Fri, 30 Aug 2024 11:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725040964; x=1725645764; 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=O/lLriAP27R5nHPgsK9ypk/521J0I4x/lWwi5ADQ+zA=; b=gv/looj0fKDVRO14i4xstrogh0gDy3WitwUxk/Lvvqw+hjqXpBp6Prw5ETrzZbw9j/ v9I799QImya/AWaLliyncRgnuQULkPZTjKXzddy8ifpTvAHQujEtcRReYPywHseO85sZ LnfhH860TOpxKuF91jPd40Wb2ftEoilDu2sYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725040964; x=1725645764; 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=O/lLriAP27R5nHPgsK9ypk/521J0I4x/lWwi5ADQ+zA=; b=sZNuvxSQV4mi6Qepd3SzdsqTDM4H0bcxxUyRvb212kLmuhb2DfiR0h6NbhNGC79697 BRpvpiuhfZ23BMOOYjbTTim79pASc54jX6/N0nArUH6SuLuGRkuCnYbie4mmPRpV77f+ II5zrZxcQomvuALBqsfeBJJQpPuOyCPcAdlo54xqM5Ne1F1wM+UnVYnWQhj0WGDpwGcp uEN8LjrCbiX+gA1Wesy/eD9hx4NJakC8C6JatPL7dzLOJOfTXrT99PiO5FrGzUcQJd/F GTsR6tOYk4yXfKzo3a19KD7UcIZ8c+nZUy/eqVQGHwXdvWUL4yF0gZp0pnOjhQmtx350 mzYg== X-Forwarded-Encrypted: i=1; AJvYcCXIXFj1R8qXO9pjcIYDBCq/QvHkhF3J4riwaY/dNdJ8Is7UhmTofZbUOvrbmXRCBcApgMZ0oBkaBg==@kvack.org X-Gm-Message-State: AOJu0YyM90SXq0MvyQLt+ggvqB1+vv9ev0yBb5vtvMq67dKFWdU/xOPJ 0RbYqHmzSmvHFlQzCgSjPbMDLoym8AZQFb5UFSpHlk3+05flYy2BuKAgHSGwPQ== X-Google-Smtp-Source: AGHT+IF7ss5vHuxDy95Wgb4WUGPyZvgp4tHfy8UO1MWvFABXKWvo/BydPzQQ6FPcavBSzZ5iLhUHAQ== X-Received: by 2002:a05:6a00:3e0a:b0:710:5243:4161 with SMTP id d2e1a72fcca58-7173078b724mr1724291b3a.5.1725040963782; Fri, 30 Aug 2024 11:02:43 -0700 (PDT) Received: from localhost (150.12.83.34.bc.googleusercontent.com. [34.83.12.150]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-715e575d087sm3037827b3a.207.2024.08.30.11.02.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Aug 2024 11:02:42 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org Cc: linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, pedro.falcato@gmail.com, willy@infradead.org, lorenzo.stoakes@oracle.com, broonie@kernel.org, vbabka@suse.cz, Liam.Howlett@oracle.com, rientjes@google.com, keescook@chromium.org, Jeff Xu Subject: [PATCH v3 2/5] selftests/mseal: add sealed madvise type Date: Fri, 30 Aug 2024 18:02:34 +0000 Message-ID: <20240830180237.1220027-3-jeffxu@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240830180237.1220027-1-jeffxu@chromium.org> References: <20240830180237.1220027-1-jeffxu@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4AD9D10000D X-Stat-Signature: hofh4omgm9xpw4c4xeruwoaed8kkun4n X-Rspam-User: X-HE-Tag: 1725040965-257858 X-HE-Meta: U2FsdGVkX1/3bUjG8Qp7cAPzIoI4WRB+/KJLDgJSzusBjYVpzlxLqZI4/vDv07DcFhFstb7Q99sFlrxERhDfQ4onnsdP3VIwwasPeSkwAsx4xLUp9hZ338n/nVDyf0Qdy8Sk0TErBSwVgNPNfcWedZ8XpSKYPKP7nmZtADvUB7fG0Iu4q27Y5kuRHiQryPL/OhVjbhd0SMOUo1MAxQcJbxyKNalQR+ySxgE2WIbJlmAdIa1IrwXz+zZg90KU62PFR1ILPTthiIFNp10eJFr2ZMk8dFWNFIuaEM1NxB3V9Q7j1TtfkWdsTk1KBoB5g1Yzhyjv8eRyd5DWPHvtr4juyetJfI3oBvxbddRS+PPS5wzurHDbM9YNxJNgb3mjuqZkgRsJDUNyAx1f3L4CIT4eOs0nTv/1FyI/qYERKa1cdhYq/W/UKOi28YIfbCHaNsjrPJ/HAfceno5lbzGroWKXApvAnjbp3+XeW1edwuyVaafhbOYBoG/t6NXrM6/fSZmWGCf7bSE1hoMRBDaHh1GMTUXB3LnQfjNDoA6u/hISKpPVJexNPWeA/dhy7gbUgv8eSj/ACy67NCGeC/Ru7rfv9fmsyFqx9cpOwTyVS5qRFogrdBJ8GInyW2ZIgFM1709ZYMb6DPZn7D3l1RhjaoCSJtWdV3PrZAdMabcWhPca18dq5imkmT2qUrutIpUG/SFtPgwVhoLRlL/akzfcAOBZiXQ4PPJqpu62rSlzJwkbbO4grFP5vGSdq48Edx6zVtmp3OUGPWxEl4/OxflLXpeggOxHAfO3ZixlQ7TvnU0FgCLFmrjOnLkX3xS2t/zfUljYED+AInH5KsAKNkKolnXBlH1xXcWTuIbBYcrsZmI7Vx00wjYBwi3VCgO99DRBMZlBE0MnXxpnpZOZ0WRb287wvCLn9nmgSh3hBZiBQDGUwAzJ+QfjoIp7K6peH93JFj0jzB/lNZlQAneSoDIpFBL jP74F0Nu Z87Y5pA2fJkgMKG7xspO6khq8iaTBOtkLeTYeYbJZBZcBlHaEYyQNv1RYUYr9Y7bPVh6sbziX5rhUm8Z5MdAldYkjLC20bnsGC/lwlZL9AOPD1lEMoKrOthkPOhFWn6rCzYdqbjLKWmAyLygKvk9m+D+WMkrpqTXBUKic+Skx4g3Ye/tuoyxti5PMsFAk/SU/579+orubkWvDhNsJI1pEbP8mMBmJ6igBMP8byy9Gg+Zm16zktmpCBScHVoxeoT69pThn+unwsARsJAK27LLbyYetOhDGQKwUoTt0j/KzT2iBTcxIHrDPJR5D6OAkncnsBmCwit8RXP58guJIFzX96KPPaQ== 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 Add a testcase to cover all sealed madvise type. Signed-off-by: Jeff Xu --- tools/testing/selftests/mm/mseal_test.c | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 7198f2314f9b..6d77dc9b5442 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -2121,6 +2121,32 @@ static void test_seal_madvise_nodiscard(bool seal) REPORT_TEST_PASS(); } +static void test_seal_discard_madvise_advice(void) +{ + void *ptr; + unsigned long page_size = getpagesize(); + unsigned long size = 4 * page_size; + int ret; + int sealed_advice[] = {MADV_FREE, MADV_DONTNEED, + MADV_DONTNEED_LOCKED, MADV_REMOVE, + MADV_DONTFORK, MADV_WIPEONFORK}; + int size_sealed_advice = sizeof(sealed_advice) / sizeof(int); + + setup_single_address(size, &ptr); + FAIL_TEST_IF_FALSE(ptr != (void *)-1); + + ret = seal_single_address(ptr, size); + FAIL_TEST_IF_FALSE(!ret); + + for (int i = 0; i < size_sealed_advice; i++) { + ret = sys_madvise(ptr, size, sealed_advice[i]); + FAIL_TEST_IF_FALSE(ret < 0); + FAIL_TEST_IF_FALSE(errno == EPERM); + } + + REPORT_TEST_PASS(); +} + int main(int argc, char **argv) { bool test_seal = seal_support(); @@ -2142,7 +2168,7 @@ int main(int argc, char **argv) if (!get_vma_size_supported()) ksft_exit_skip("get_vma_size not supported\n"); - ksft_set_plan(88); + ksft_set_plan(89); test_seal_addseal(); test_seal_unmapped_start(); @@ -2251,5 +2277,7 @@ int main(int argc, char **argv) test_seal_discard_ro_anon_on_pkey(false); test_seal_discard_ro_anon_on_pkey(true); + test_seal_discard_madvise_advice(); + ksft_finished(); }