From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795924832; b=f0RhwOG5DhU55+aOEvRZlF+9Sc1ZBfSSmscaPCp4WY7l1Rr20duBGpPai/Kq4cC0tb+R Yb4ouugX75HvkkIBsSH51xux0h6u02fslhve/nWLiM0wZcOYuDzNCQgAEqe6ByJ17yE0S 9ozEfuxn2CjnBGeU5/m8XE1j1N/VKoWOHFnLxicLm66qKNx24pxjeshuxChI6mtk7R5nO itAW2f1B+JbH0PhJJM8b38A09RnF6KQ9b5NJO86r/4+XtFEHfQpDMUmThuiarpceOx4kQ LlFvEy7E9rwI8Uxw+zsXWyBQ4uzz7RzAToEBO4s44m6hHj20XukEXTSayLXupj69D9g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795924832; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=HmKcTXehvRa4e80u3vi22Qbhbikchs3hgoCg4yFj+3o=; b=5OtHzKAteQnL1oxFcRajHvTzMxYCLkR1hGBkqCs/eSBHwfqHSoqjY5qCsz60uZfgBEk8 m+qczrKKZ1n9RAsO8abWO34QDA4c45QQJjs0OAM1nrpAsOmkFPW8/2hWuVmSR1RJxE620 ZJEk+Ha56/oY6laNu0xOJaP4mCfONYBZ9zlk1pF+FD1p3UgoXTHDJVw0TMoRnpPrCjHj1 41L8mY009JE2LA8oRW24JbBafiNjLDPi5HCLzx0rNWwsxT/8ndlxnWKe5d54wxQedwSDP 5y4EIiFCMnjiAN4Y8zu/78nJzw1VOqeYdZqaRyBJzVf9WFt7sCzkDkQQhOCQv4iZTmA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=i023jjI1; arc=none smtp.remote-ip=209.85.160.176 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB744606A32C for ; Sun, 29 Nov 2026 04:00:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB744606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=i023jjI1 Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-536717a4d83so78405841cf.2 for ; Sat, 28 Nov 2026 20:00:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795924831; x=1796529631; darn=vger.kernel.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=HmKcTXehvRa4e80u3vi22Qbhbikchs3hgoCg4yFj+3o=; b=i023jjI1ilP3PUIaMDY7PxGlQwhoMjbO+ofGrnx0T3VpxYWyE35tAfXtJWUGKi/Yv/ njwfrXYqMoTD04CGoif3zMOVvrJrxSquTqdClxMA7PpSbyast25n3EfI99Its2SdwejU 2grgA8dDW+VXEhguE6MgL3aWosw1zpUQaM00lUmEVTM/ipneMdqAFd6cw0Utqk8j7T3I xEtXEKbDnOq/tvPmmc6oIdyI1RZuTjLO4CjwhW878ymlydB/C3VJhBH8pTns8KlNL6OJ xcLRv20xoUeN36heN/WeJaSSYi7IUyPVensmmA398y4fv5yMHVSiFz1Uv0VFFvgzwayL hbZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795924831; x=1796529631; 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=HmKcTXehvRa4e80u3vi22Qbhbikchs3hgoCg4yFj+3o=; b=JISqtkcpM6omacqt7nj2YR2SQGXFs8SQXxsXaH3s/zM3RpL3jsF7gyKrdV6tjWj4TF ZxqX+/gD8KEToRwUy98ipQKdd3K1A4GV+9QltD+b8aqlmCikpcNn0UI6QK6+MlnuTBmv uEjvJSBxvLXVhsqHg+MXo1AZfg+0mNvB1Otxlh7DHR8kT/60MnZOlMiuZPYLMLht+6aC u+WXvhZ7DYCuO4xpMy3OMuf0m9X2as0BYvNWbhQo4cMBE8OGX/ooSdHVeKvgN2TSFxZ2 VFekQH/Ro5JVw7iCxKrfHGg983ZFBx4wzQeTuZWbEsLS0ONP3JdPRONMI9cl6OaWCrEj nX8A== X-Forwarded-Encrypted: i=1; AL+hErEeTmtVtdiaTHI3gj2PCei+6VIAiFbwi2zPeJtFtGEp7ltTqh8/X25OXTu9ZTDIcHsLwTr2lbC574+ioXDrjVc=@vger.kernel.org X-Gm-Message-State: APuU4Z+IAiWmTONBDR2twV+Dl5IojhAw4/gQKqR7JE5cdQe9nEb1S8lu dbxgftWqu/YRKlc1Ff61J6ubk7DCHGSOb1ggWFWsW+iEtgdFXZDWeC/j X-Gm-Gg: AZFdTZevR4S1IYZLz0A7k9M2n8zCPZ45CTaSvVNQql2eOE6dTnBdxq3QGztSwv7SHfp 3SsKAiPEhGhbkRlk4997SgxDGqlbu6YiQER3LYhaRWhfYxovq78GJLMMbYlr5Sz+fumiN7N6i6T fLqTFtWX/3cwBLYuR0cVUirpNiKItdG4BGw8UYnBGH6mEtiqlt9rMql3OQXYU3FMqlfA71M44WZ kqqAEyNJVFUJ1NZ0pucsfaQ9/9CLTMFrnXcNFvqTXOd1oJSD69iKby9lSXt1e4jeihUuff2Tfaa kWbbPqAeQCPTP9mX23Ci6PVZSdHX+9DFlm8qQ8nf0PKWvVzD/ZoGktQ7EZ13xgD6bLai9lJGO6x kLQqzCbO/1sG9NBOI3FtFvaKGJpkpuPfxc3kpdCnntkRVbG4GkZtfBWAF6CGUlCtl1476F1+MAT L7yNHre6oktnaK+KCSnjM6ENysIofVBvLSQgQvgCfR8zXqPwW7trhYsm7fdvn65uQQ0ip3iJ0sM RiE/XBvkIJI+4udK+Zdb5pJpbknrFt5Tn98II64smkzcfC5wADJYUB5HQrk5/FroD5H6LX5NkRR q18EnUSChsBp7LO2a+APo0KJnVUILrINoeCUMpCqhT5tJucvkKh6Y1hGsf/VM27Wzp8pxN0JRAw ybdZLdg== X-Received: by 2002:a05:622a:428a:b0:535:f92d:5c00 with SMTP id d75a77b69052e-55d76af8921mr549310601cf.76.1795924830347; Sat, 28 Nov 2026 20:00:30 -0800 (PST) Received: from localhost ([138.197.109.108]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d7c654585sm241489991cf.5.2026.11.28.20.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 20:00:30 -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 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Date: Sun, 29 Nov 2026 07:00:23 +0300 Message-ID: <20261129040025.37113-2-ndokutovich@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261129040025.37113-1-ndokutovich@gmail.com> References: <20261129040025.37113-1-ndokutovich@gmail.com> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. A refused forced write transfers zero bytes and mem_rw() reports it as -EIO; any other zero-byte remote access reports the same. The helper therefore treats -EIO as a refusal, but keeps every other outcome separate, so a caller skips only on that error and a real fault in the test below still fails. Signed-off-by: Nikolai Dokutovich --- tools/testing/selftests/mm/vm_util.c | 42 ++++++++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 16 +++++++++++ 2 files changed, 58 insertions(+) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 515031b8283d..f80188f500a2 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -1119,3 +1119,45 @@ void shm_limits_prepare(unsigned long length) shmall = val; } } + +enum proc_mem_force_write proc_mem_force_write_probe(int prot) +{ + const size_t pagesize = getpagesize(); + ssize_t ret; + char data = 1; + char *mem; + int fd; + + mem = mmap(NULL, pagesize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (mem == MAP_FAILED) + return PROC_MEM_FORCE_WRITE_UNKNOWN; + + fd = open("/proc/self/mem", O_RDWR); + if (fd < 0) { + munmap(mem, pagesize); + return PROC_MEM_FORCE_WRITE_UNKNOWN; + } + + if (lseek(fd, (off_t)(uintptr_t)mem, SEEK_SET) == (off_t)-1) { + close(fd); + munmap(mem, pagesize); + return PROC_MEM_FORCE_WRITE_UNKNOWN; + } + + ret = write(fd, &data, 1); + if (ret < 0) + ret = -errno; + close(fd); + munmap(mem, pagesize); + + if (ret == 1) + return PROC_MEM_FORCE_WRITE_ALLOWED; + /* + * A denied forced write transfers zero bytes and mem_rw() reports + * that as -EIO. So does any other zero-byte remote access, hence + * the refusal is only recognized, not proven. + */ + if (ret == -EIO) + return PROC_MEM_FORCE_WRITE_DENIED; + return PROC_MEM_FORCE_WRITE_UNKNOWN; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index b5d59729d432..5b05763945da 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -68,6 +68,22 @@ static inline void force_read_pages(char *addr, unsigned int nr_pages, bool detect_huge_zeropage(void); +/* + * Result of probing a write through /proc/self/mem into a mapping that is + * not writable, which the kernel performs as a forced (FOLL_FORCE) write. + * + * proc_mem_force_write_probe() takes the protection of the mapping to try; + * it must not include PROT_WRITE, or the write succeeds without going + * through the forced path. + */ +enum proc_mem_force_write { + PROC_MEM_FORCE_WRITE_ALLOWED, + PROC_MEM_FORCE_WRITE_DENIED, + PROC_MEM_FORCE_WRITE_UNKNOWN, +}; + +enum proc_mem_force_write proc_mem_force_write_probe(int prot); + /* * Plan 9 FS has bugs (at least on QEMU) where certain operations fail with * ENOENT on unlinked files. See -- 2.43.0