From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 41603606A334 for ; Mon, 30 Nov 2026 17:40:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=I45beBYs Received: by kanga.kvack.org (Postfix) id 922516B05CB; Mon, 30 Nov 2026 12:40:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D24E6B05D7; Mon, 30 Nov 2026 12:40:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E84E6B05D9; Mon, 30 Nov 2026 12:40:03 -0500 (EST) 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 55B7E6B05CB for ; Mon, 30 Nov 2026 12:40:03 -0500 (EST) Received: from smtpin25.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AC257A896C for ; Mon, 30 Nov 2026 17:39:59 +0000 (UTC) X-FDA: 85492498518.25.9537674 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf31.hostedemail.com (Postfix) with ESMTP id CE8282000A for ; Mon, 30 Nov 2026 17:39:57 +0000 (UTC) Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=I45beBYs; spf=pass (imf31.hostedemail.com: domain of ndokutovich@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=ndokutovich@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796060397; b=ANwb2DwdE/qbRKsIivUuN2J0RslZTFWQAMg7anilRuTFeAQ+qY6ueNLbaxEF1r2w0JbLAr Y6JPTGCoZkueE8hyPwoi7E8daTFjQANCnHZJ2lQy3gycLN1Eynjul7MblFU3XbE85K+vCQ 2dy8xFmQkcZ+lP5YTnm1yEsBMQXUeXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796060397; 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=WQ7gSuFsJ5BGEV9QS1KAUDxDZhXWbdjDhzVwsnwRLAw=; b=yJtCBwBSB8L6YRaZbySh8z3iRpP1LSPrFrfqwtbf71ksAFWLnOcajAmHedBvQOfyAebfXT gFCCRO0k6TbF/+2OhEYMAtZMbDNA2riZPriQLvaDvXwSeUnFhKBehrdi7LQC7fHvgsZlHH 9e2OhItGkzFdprNBwQUW/yHm4Sel7+w= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=I45beBYs; spf=pass (imf31.hostedemail.com: domain of ndokutovich@gmail.com designates 209.85.222.177 as permitted sender) smtp.mailfrom=ndokutovich@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-9496473b511so1276722785a.0 for ; Mon, 30 Nov 2026 09:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796060397; x=1796665197; 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:content-type; bh=WQ7gSuFsJ5BGEV9QS1KAUDxDZhXWbdjDhzVwsnwRLAw=; b=I45beBYskyuk62oYyWBQgNDgNobOmzEumQQm++xEXxMOBZ2i/5YTfGNsVLWCs9Xh+2 dmIi26xQ3ve0LcKT6JRhfFZfqvdZOmI2tpQChbARnbck6+H5zFYPxuw4wANJIav1jLnx tYZzG5LUGu5QfEURXAyFJXQ3D6xghVeh9n17Mnp8k0Uq+j7uCHtG1NQFhErQH6ofmNKW AuecGulCqkXAGvAKR0H4IRUAMynvbhpdPk4VwM0qDChOlSqeqYW6rycHa+m3pKBbMTlx Q5YJtBzYqLZAgGMyepAI+adDeBfuHyFC+9MdtQYXs7t0OYtADnl458zfaswtxzQfiwGy e3SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796060397; x=1796665197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=WQ7gSuFsJ5BGEV9QS1KAUDxDZhXWbdjDhzVwsnwRLAw=; b=FWyi8R11O0aA7eqh5Ru7ZTT/4KqkqXFmFgmqDswSKaBfNEd6awakfmP7qc5tn5Sugd 5rrPAHJzFy0OgWu2d6/jerPrQGp9r4jpW3PuZBxjpUPFLNIVt8DW4BADRWJRoVusy7BN LhjAnw2mzv3Ef7ikfsgnIChPSU70ixipOkaWPOhSDrHejV00VyK8O7DRsdnOlAHcAd/m GQfuLiVLR51Q07MI2qCrcMJBiG52k4l0I1nUXKqCtLFREmy6PGb7xFtyexMUJdpXpTVp Y5NCgSermQ5SkpA8QTwdpFimF1iQ2pePg2STCMp3cvEmiJd1sNZQU7Fb3AXC1k4MKZXV 5xtA== X-Forwarded-Encrypted: i=1; AL+hErFX1+Nm1WT2Tlppp8RQnwiSwT4mZOnTwaf6Jn01a+yCQl3q1vl7okshANTJsXCjLMMbmECe25sKbw==@kvack.org X-Gm-Message-State: APuU4Z+U8Q7hUq1uQCOBSx3Wj2XBeywpH8dsa1AYr3dwNb4Bv9jMd7Zp hxKe5fq/d5Ejh1qMACBB9YS8Aqgn8Dk70lm3AOAnmXXubK4uUGo5o9vJ X-Gm-Gg: AZFdTZcWGueRPcC1BVbEbFUckBlb2A7+V6HF5uVkKkRtPhL3BbarY0OOI1alv9bpYci cNoSV1LtBDD2XQA3PhB94+7SwmdxRnfbyuo/IGawec8onUOXCgodV9/d4djxK2x0xQgZ6YimuvE lhl530uLBPbNW43YlWWAj8TiIeVPYFz/zV4IONSXmab2F+YGlqU8K4xk2fxQYl4v6Eft4EcEUWD mwpRJYYad+oklcwvSBqzfu4Sky3KxIT+D2qp7pop+y8Oc0CvWpkUcPOZmDaT5rkhhsUuS9/dGKi tuQ+9w4Judm8EuiyC1rThVL23GspFdMiN2yJIRdstXyyvs9pZYZV0NSXZCEyOrFJQrksUaACDOh MqoXGaDTa3wYZz4w/r9kcPJevPQS2FMJaLEbxhMaTyT/MXdlyh6ZcaRjN2A3YCnY40fiARm1roH duoHD780YW3/4NC8ECAxnhbF91AyXQN1UnDL3sn7dDw+n/Ydg9QpkGKR1Ytjh4U2q4lyMFf9cIc +K6rzhFuHllo5PRXHvt8aK5vZldQliV9SI1fYrGsTewBWyIfBBGJP8qs1uSi4+rGUo7rwYLUT6H NY1hblmeZkC6pyyJPm3erWzIA604lwWGtff/cIMMwwpbFoU5P7gQpk/B9Ode9hzpHLF5QliOiA8 q0cFS X-Received: by 2002:a05:620a:4142:b0:93e:c173:f690 with SMTP id af79cd13be357-949bab12903mr5616294585a.36.1796060396896; Mon, 30 Nov 2026 09:39:56 -0800 (PST) Received: from localhost ([138.197.109.108]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb3f2de5sm2581341885a.29.2026.11.30.09.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:39:56 -0800 (PST) From: Nikolai Dokutovich To: David Hildenbrand , Andrew Morton Cc: Shuah Khan , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Nikolai Dokutovich Subject: [PATCH v3 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Date: Mon, 30 Nov 2026 20:39:48 +0300 Message-ID: <20261130173950.41003-2-ndokutovich@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130173950.41003-1-ndokutovich@gmail.com> References: <20261130173950.41003-1-ndokutovich@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CE8282000A X-Stat-Signature: aehu4tshwz3subhz5fkqmarfj81kp459 X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796060397-165092 X-HE-Meta: U2FsdGVkX1858fySUYQIVbr6CuWmTmeuEjD2B74xyivBMgcKt9Ea+tkTQeX484SqbSFpes6xvkjTwi+BhLs6U+0utlmcY/F0bHr0w5giLUc7AWZ44Zxv2yTJyWnKPtt4fqP2lU36T0UBqlom8SvGauOd4GLTnM2SYxXU/1u9WtQ2dtqxJUYbTD67fQTaxjFS/KlkduUCyItrHkZ6kJaiVO1SlbuD9BDP7Z+bSxTbsRE2W+z5Ph0LmLYBHVe4aIjvpDSOi3Y1cSn5F0QMcHdplUNmsZ89EXzKt0sPcWBAvVJ7aV2BhNi59O02IKTIw5QXNQZrPrVfp89zpqt5nYzwHGgVWpXgXkZ47suVV4Q58RpI2h0J8j3bL/T+4IVVSjgYe4Viukf40Tst1u2DVvQuH5mBavhyaMz9PfwffkupcKKuRMHWY0wdRdPXTB5+AzZQM3REEta8tsqHv5iWIJFV/gqG8U8XbXfuoZxgLrWm4pIwiSGvFpIY0l/VaPWnotPXmBnqq1aY70fpMmyafAzWAe2aqq9HHAY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shLcE+0nl3jdJxNT/pNgkYlS5hPBZB4wHuwx3zC52PUsaT7Y54158rN9bCd6Bk82JBnVhmwYBVgVVyaAFO9RuMcibr+xms09RGtmeULxWjOa8Q Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 A write through /proc/self/mem into a mapping that is not writable is performed by the kernel as a forced write. Since commit 41e8149c8892 ("proc: add config & param to block forcing mem writes") such a write is refused with -EIO unless the writing task is tracing the target task, the kernel was built with CONFIG_PROC_MEM_ALWAYS_FORCE, or it was booted with proc_mem.force_override=always. Commit 599bbba5a36f ("proc: make PROC_MEM_FORCE_PTRACE the Kconfig default") made the refusal the default, so it is the common case on distribution kernels. Commit a3907a3169d0 ("selftests/mm: specify requirement for PROC_MEM_ALWAYS_FORCE=y") set CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config for dedicated selftest builds. That fragment is merged into the kernel configuration only when it is requested, so it does not cover a test binary run against a distribution kernel. Add a helper that reports whether such a write is permitted. The permission is a property of the kernel and the calling task, not of the mapping, so the helper probes a read-only mapping, caches a decisive answer and takes no protection argument. A refused forced write transfers zero bytes and mem_rw() reports it as -EIO; any other zero-byte remote access reports the same, so -EIO can indicate a refusal but does not prove one. Only the two decisive results are cached; an inconclusive probe returns true and is not cached, leaving a real fault to fail the test. Signed-off-by: Nikolai Dokutovich --- tools/testing/selftests/mm/vm_util.c | 47 ++++++++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 17 ++++++++++ 2 files changed, 64 insertions(+) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 515031b8283d..5ccf1e2e7ec9 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -1119,3 +1119,50 @@ void shm_limits_prepare(unsigned long length) shmall = val; } } + +bool proc_mem_force_write_allowed(void) +{ + static int allowed = -1; + const size_t pagesize = getpagesize(); + ssize_t ret; + char data = 1; + char *mem; + int fd; + + if (allowed >= 0) + return allowed; + + mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) + return true; + + fd = open("/proc/self/mem", O_RDWR); + if (fd < 0) { + munmap(mem, pagesize); + return true; + } + + if (lseek(fd, (off_t)(uintptr_t)mem, SEEK_SET) == (off_t)-1) { + close(fd); + munmap(mem, pagesize); + return true; + } + + ret = write(fd, &data, 1); + if (ret < 0) + ret = -errno; + close(fd); + munmap(mem, pagesize); + + /* + * A refused forced write transfers zero bytes and mem_rw() reports + * that as -EIO, but any other zero-byte remote access reports the + * same. Cache only the two decisive results and leave anything else + * to the test. + */ + if (ret != 1 && ret != -EIO) + return true; + + allowed = (ret == 1); + return allowed; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index b5d59729d432..0a1af711e0f3 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -68,6 +68,23 @@ static inline void force_read_pages(char *addr, unsigned int nr_pages, bool detect_huge_zeropage(void); +/* + * Whether a write through /proc/self/mem into a mapping that is not + * writable is permitted. The kernel performs such a write as a forced + * (FOLL_FORCE) write. The answer depends on the kernel configuration, + * the boot parameters and whether the writing task traces the target, + * not on the mapping, so a decisive result is cached after one probe. + * This holds for the self probe only: another target or a policy that + * could change during the run would not be safe to cache. + * + * A successful write returns true; -EIO returns false, although -EIO can + * also mean another zero-byte remote access and so indicates a refusal + * without proving one. Any other result is inconclusive: the probe + * returns true and caches nothing, so the test runs and reports its own + * failure instead of skipping. + */ +bool proc_mem_force_write_allowed(void); + /* * Plan 9 FS has bugs (at least on QEMU) where certain operations fail with * ENOENT on unlinked files. See -- 2.43.0