From patchwork Sat Nov 16 00:50:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13877419 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 54731D68BDA for ; Sat, 16 Nov 2024 00:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97CF99C001C; Fri, 15 Nov 2024 19:51:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 928F79C0018; Fri, 15 Nov 2024 19:51:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A2439C001C; Fri, 15 Nov 2024 19:51:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 52B2B9C0018 for ; Fri, 15 Nov 2024 19:51:05 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E6B1E140B76 for ; Sat, 16 Nov 2024 00:51:04 +0000 (UTC) X-FDA: 82790126538.03.9A616FA Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf25.hostedemail.com (Postfix) with ESMTP id C6EA9A0005 for ; Sat, 16 Nov 2024 00:50:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gsxf3c9Z; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf25.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=jeffxu@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731718083; a=rsa-sha256; cv=none; b=eTcKHnVa6EKaedT4ho4a0KvOCTxnito9XdR1Ckd1hVJGWY3n5uL/9YNPHOu2mpPzWcRaOJ liPCAE1CHSS7Yt5xzwe9rSxoNBOvKBrKyzTfSqp4WZcLmf5ps5yK5pTHE1OKgiIy3tXsC7 Kc4IMfhSpL97MyOVSEIPnLZ7AYMyH+g= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gsxf3c9Z; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf25.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=1731718083; 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:references:dkim-signature; bh=8OTklPY0QALxtPYDVAKnfGC6P1pEseSuX9K+uwN76nU=; b=dV9gBJ5mdSh9qeRap4x4jEJfbHNs6KjW/ognESU7QtdOy0Dk8Y4+zDpwoOKswQaq92WceD nMUVEunPcH4Gunsfpz3G43fIGn8UUAJHatO+XDNtNV7ggqWzdCUgejk8nHOFYppZrVI7/I ebyHAhOCtd6l/TzNq88TNdQLXyAcgrA= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-72467bd1502so185136b3a.3 for ; Fri, 15 Nov 2024 16:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731718262; x=1732323062; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8OTklPY0QALxtPYDVAKnfGC6P1pEseSuX9K+uwN76nU=; b=Gsxf3c9ZW9uAavbN1Kb4Es0dIzRSf7hav3Em+7hMpQKBQeOlpGVdU+l0fg8izXcULa sbE4eV27n/YGrfir4g3VLmMs/WVm/COKt7EzNObF0XBIc8P8a67atVqLoSl+iEaCxy5C jxO1073eraCVt9/Bw18OFhXMBfmByr/SqyI2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731718262; x=1732323062; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8OTklPY0QALxtPYDVAKnfGC6P1pEseSuX9K+uwN76nU=; b=pBPxcugpt5c+ZOSAPa6x2os/JQ2dWilgpjIrLvbzylmx/oBL4yYhMekeynkKPSlKuh Lzd8egBLle4KoQxvoiIUzhOHfYrXKhShMIl3EpkgsCMWKKtvHEkyz5C9WBno3gaG6ESc OuI8CFnDdLaVqMK8SHi5sx46NYJMoEwZ86FnCdJnBGLUalIAY4ItFA05OpiXSAxmtOw4 ivGlg9bfxbfGOJe4HBeL4NKjAjIyLsNZzNu1JnfUvTt1lfJe2NzKBzF53s4FkDSWNfUm OTPpjDvO6VO1Wx3e4Al9RFHPMSuNby/g4UTkVkHsFD49Llz6VpBqOAWTstSfEWbjD8Ju FcaQ== X-Forwarded-Encrypted: i=1; AJvYcCX4cjQK/9HxvSfrc8V4MSnksqTNMWXcBk6kJqDGdnZr3xzeslJqLdE6c/LiqvqOHwe68OZ8YNB9kw==@kvack.org X-Gm-Message-State: AOJu0Yy6YvEaGdmKHO/QUzMmEmOkI4+udTvpVxZ7bxSx2DhFfk5/RW6i H7SPTynu10iHPpqAzVuq9vD3Hkxz5ZHU27wdDaPTBWY5l6SqsNoDnQN+9pItww== X-Google-Smtp-Source: AGHT+IHCFGFxXTdc5NmJ9A5WfB9TAKESidMsf663Up34gRIwCYJ4a4J9fqZkmA9zxB6fNDrOQFC97w== X-Received: by 2002:a05:6a00:21d4:b0:71e:4bda:71ec with SMTP id d2e1a72fcca58-72476d42f3dmr2444731b3a.4.1731718261613; Fri, 15 Nov 2024 16:51:01 -0800 (PST) Received: from localhost (238.76.127.34.bc.googleusercontent.com. [34.127.76.238]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-724771c0d29sm2063055b3a.122.2024.11.15.16.51.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Nov 2024 16:51:01 -0800 (PST) From: jeffxu@chromium.org To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Jeff Xu Subject: [PATCH v1] selftest/mm: remove seal_elf Date: Sat, 16 Nov 2024 00:50:58 +0000 Message-ID: <20241116005058.69091-1-jeffxu@chromium.org> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog MIME-Version: 1.0 X-Stat-Signature: bf5h5eytkow8rzdm3ybaxciigh9t4ojs X-Rspamd-Queue-Id: C6EA9A0005 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1731718229-745443 X-HE-Meta: U2FsdGVkX1/pMju3g19I4FdUfyufxwG+MnOvmr7kxMPa+o6YN1fLm59IhjPbYhffb87xnYVCdh/AyBq0avyWlY0q/oEDfbwu24kqItdaSqeSqif/A5nujg0rx0CapUpKiv3c6iaRZ8cXNcJoZfbMAPihCE0/JcyXx76txC33N6beUDaQZ+i2xcUn2p98exT7OtzczrlPcytDgzySJEiu9ruIWM7Z9I3KVLFFStJbVPFaIO9dyHS7ASiFSP1bleVm6TS2Ad6KG4fXvzdrP1Rdp56+dLiedhy+zT1VxmLhNKNl2gCM/ATpSQ3T6oWFmV07lQaeSIPfV/GpxcKDW1I4n7NexW8pGPRvf9Op6ybLbmb1UruZHMLg1eBg6DjYOsTpp3buAZa6zE6xhVGlgj5io7IIoWNMXyYScpYMpt3uUuQc9utI4OY0KrRV/uLsdrdtM0NLPY2y+v3RNWkoMc/+InmMk9dhoKsndHJLiDLzN4R+sufBS/GlVOm8hbwwWBMXqARBBGkxMltg9Mw0rRINUzz4ud01wJW+j8UGjq7UCRYU/aqt34GU7FAN7+wZnNzhtJLQOKbhBVgnjbxT2mBKipY4IEkwuX/0QExEGhcIxPjbHEPkTnKEgEVGEtx1j36Fa6p1iTj5IdjXZmpKo2bm13v+MEfJkq+mHi0MK1pDh2UbVFL+gWJbUnSwwarW2s+JNPik7FisbrD0WQXcaKE9g/UzANeXCKNdtbh/58Qh1ERMAQFNn1CFYOjMMAKC6TqaOqQqiDyur7CFLHr7ggQpqgJlyJ3yZDg23YXrr46EZ1H8nN20xPJv+k9YLD5lxIWeqS63NkChZkIQeQwCCKkSYPs7ohVyNUtNo+GNSvEqY4uEzh4ALwrE4d5x+2A/HosRW97Bkk1q6Hv8oQRmsU3hvbZtFnv7NRa87uSBHzWeg1S72J0RAL5EGbZz6s5/7YXZiRMZRlGQfKQZCHG1Mvd 7BQHvAhe 9NKJKOqWNq2QgzJIXMpomcofW2ipeACYEet4L5QVmz5GNxiNbgVSnR7mPSwW4lMK/eksXFdGsDCeDfOb2YoOtBA8tC6myAvPMpbV0ReOXAMASokR3PXiKcQ6uF8gViHQYuDp82Wi/L8ZVX2yTXFiUaOvJVYCc7d6xGTZc30iwAFpFC6eWEqhTn8mut1oNVG+PX2V6UkoGjX8duA1PTB4tFttvA9lOGk+n0mLEcpIXROmVIp3AXY+F/IUhekURBbFTjRgmCEVhOkEHbiIKejFGuuU28JvD82tiQZjaxr9E23A6Ga0= 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 seal_elf, which is a demo of mseal, we no longer need this. Signed-off-by: Jeff Xu --- tools/testing/selftests/mm/.gitignore | 1 - tools/testing/selftests/mm/Makefile | 1 - tools/testing/selftests/mm/seal_elf.c | 137 -------------------------- 3 files changed, 139 deletions(-) delete mode 100644 tools/testing/selftests/mm/seal_elf.c diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index 8f01f4da1c0d..6a273bdbc70b 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -49,7 +49,6 @@ va_high_addr_switch hugetlb_fault_after_madv hugetlb_madv_vs_map mseal_test -seal_elf droppable hugetlb_dio pkey_sighandler_tests_32 diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 72ec4403032d..869b6a40f290 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -64,7 +64,6 @@ TEST_GEN_FILES += mrelease_test TEST_GEN_FILES += mremap_dontunmap TEST_GEN_FILES += mremap_test TEST_GEN_FILES += mseal_test -TEST_GEN_FILES += seal_elf TEST_GEN_FILES += on-fault-limit TEST_GEN_FILES += pagemap_ioctl TEST_GEN_FILES += thuge-gen diff --git a/tools/testing/selftests/mm/seal_elf.c b/tools/testing/selftests/mm/seal_elf.c deleted file mode 100644 index d9f8ba8d5050..000000000000 --- a/tools/testing/selftests/mm/seal_elf.c +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include "../kselftest.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "mseal_helpers.h" - -/* - * define sys_xyx to call syscall directly. - */ -static int sys_mseal(void *start, size_t len) -{ - int sret; - - errno = 0; - sret = syscall(__NR_mseal, start, len, 0); - return sret; -} - -static inline int sys_mprotect(void *ptr, size_t size, unsigned long prot) -{ - int sret; - - errno = 0; - sret = syscall(__NR_mprotect, ptr, size, prot); - return sret; -} - -static bool seal_support(void) -{ - int ret; - void *ptr; - unsigned long page_size = getpagesize(); - - ptr = mmap(NULL, page_size, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (ptr == (void *) -1) - return false; - - ret = sys_mseal(ptr, page_size); - if (ret < 0) - return false; - - return true; -} - -const char somestr[4096] = {"READONLY"}; - -static void test_seal_elf(void) -{ - int ret; - FILE *maps; - char line[512]; - uintptr_t addr_start, addr_end; - char prot[5]; - char filename[256]; - unsigned long page_size = getpagesize(); - unsigned long long ptr = (unsigned long long) somestr; - char *somestr2 = (char *)somestr; - - /* - * Modify the protection of readonly somestr - */ - if (((unsigned long long)ptr % page_size) != 0) - ptr = (unsigned long long)ptr & ~(page_size - 1); - - ksft_print_msg("somestr = %s\n", somestr); - ksft_print_msg("change protection to rw\n"); - ret = sys_mprotect((void *)ptr, page_size, PROT_READ|PROT_WRITE); - FAIL_TEST_IF_FALSE(!ret); - *somestr2 = 'A'; - ksft_print_msg("somestr is modified to: %s\n", somestr); - ret = sys_mprotect((void *)ptr, page_size, PROT_READ); - FAIL_TEST_IF_FALSE(!ret); - - maps = fopen("/proc/self/maps", "r"); - FAIL_TEST_IF_FALSE(maps); - - /* - * apply sealing to elf binary - */ - while (fgets(line, sizeof(line), maps)) { - if (sscanf(line, "%lx-%lx %4s %*x %*x:%*x %*u %255[^\n]", - &addr_start, &addr_end, prot, filename) == 4) { - if (strlen(filename)) { - /* - * seal the mapping if read only. - */ - if (strstr(prot, "r-")) { - ret = sys_mseal((void *)addr_start, addr_end - addr_start); - FAIL_TEST_IF_FALSE(!ret); - ksft_print_msg("sealed: %lx-%lx %s %s\n", - addr_start, addr_end, prot, filename); - if ((uintptr_t) somestr >= addr_start && - (uintptr_t) somestr <= addr_end) - ksft_print_msg("mapping for somestr found\n"); - } - } - } - } - fclose(maps); - - ret = sys_mprotect((void *)ptr, page_size, PROT_READ | PROT_WRITE); - FAIL_TEST_IF_FALSE(ret < 0); - ksft_print_msg("somestr is sealed, mprotect is rejected\n"); - - REPORT_TEST_PASS(); -} - -int main(int argc, char **argv) -{ - bool test_seal = seal_support(); - - ksft_print_header(); - ksft_print_msg("pid=%d\n", getpid()); - - if (!test_seal) - ksft_exit_skip("sealing not supported, check CONFIG_64BIT\n"); - - ksft_set_plan(1); - - test_seal_elf(); - - ksft_finished(); -}