From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795924848; b=d7CyS1lvvmoViApamzNtuws540xAj4fj4iZme9/pr53zKYH57NnPh3QNDhnT3pScftey p2JFjkd3On5wFXBZ1fKpjwi5VrEVxQHEYwbHajp3ongskDxKG59Xo7EmQxeU4az6InvAV nN6foivZVcp0VE6QVNGxV6P8fZwhusUXgJoD+l9DPEaONNeiEf/Nth15VG4xxyd+oKV2X 23TmNot4EBOHGh1TRiiVl2Xi3+VvUlDWJy62DzSvU0TzvZZktxNK2j5Y/0T5cX0wjrFd4 Yi8lXtHnQhhN7DpOPtBrnzdNH44gjEatiYnBYU4nQR4mSzMZpSB7O19EFd0mtICAczA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795924848; 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=PCZ2u+GN0+GXsBDrULquieQ0RUNzTMFHiyc9MHLvl6vg4s17ILphP6idEFlPExdj28s9 0U2B7H3ICe0X3sjxvIAa2xSX6H4mi+Awb+fdynEKwPSMlIiRI1vj7hEKZprWYQbvkcbeA GuOKgA1p2KBgqq6d3IDg0zSN0WGPSUyIad2TCyh4SHwI4T4BDsk1llpvZDuLvS+DujbRp A053YxcdgMnJQQ0buskheyrCbO4o5WiS+nlWm3LNQCH63qmoFgsau4DuGXgWO9kw+ggzu q1EKFl9iyJxU68mRrz7TujN33Qfc24Tl9EVEK7iGTvLdXiv07kzU3GFV9x7Ri1xAbww== 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=joZ1BBkL; arc=none smtp.remote-ip=209.85.160.170 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (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 BFC81606A32F for ; Sun, 29 Nov 2026 04:00:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BFC81606A32F 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=joZ1BBkL Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-536c8f958d7so71175831cf.1 for ; Sat, 28 Nov 2026 20:00:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795924847; x=1796529647; 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=joZ1BBkLIxRAm4V6jCIuhKXd8FSu9M38fLYQS4F2Msoe/JW5/TeUEqS6h4WgErJZRu lPuHDfOuedy+0KubQUKkM1rgRdzeyH5SVQ/kS25YJeSNefYr6zx7dF1Bwmw72Zf2TbtI 4ngeXBxOIRIpNRtuL1l/UME6Vw8w8C/ppbOoSrsGRYRJiKajAY/tZKUHS0PVoQkWrzi8 tgMLyLE4B+42+S87iNdHxKu2Qn5q4cZ5FNI3taA7jmR1lHf+SUeNxl5hNN2GV9gaGH3a yC9o96+gWLpHxTAUIrPGszPcJlhITXewVnSg1A89hnTRHcaJJYa09zFc+l4vohBi8Jc0 U6jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795924847; x=1796529647; 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=16hnsJLzHRvyJqA48ErzWIzNTYo7epn7SAygDyUBt/KBou3ygDqRwkKNfdoMLrwhgi WGaylnQwEWBruqkE4Dk4yv6dWj6LfkS0LFdeq/wsaymRsyaX76CFKz11ARJOAxj5EP4+ 87OwJLsyRYQSL5JaYe+EsZjc6zrHfN4FFhlb7ZOAK6oqFM9xOKErs6fw8szRvAmMIYPe P/HJQQpl0XhoigppkMRWDRv1/xGl2uXlNVXytl4BgAa8wBcfpyAxx/3LvNtTU3m0ylcn ogeDA6d36WsKTN1CEKXtD/H8yAUffXuTjccwkGiH1F4BmF5WAxpSH6zS138XM05+8wMR X9Sw== X-Forwarded-Encrypted: i=1; AL+hErFEXKTCp+mC6WHGBH64bHf15EVdFW4ZaHCdDTXkBHlmcUArEC7YE3C2cviVDXxYoWbtgf3EIXVnwwZXQI8SxeM=@vger.kernel.org X-Gm-Message-State: APuU4Z+y3s6m2QLJRB4cMMPa79xMbOnf/JcNwwSCk1Q1vIF31uzb3dyF 3w0GjJdPJDde5ueXdaIBmeji/wbEKZkBsI4EWBl+hn7+0ZqIkGnTwxYH X-Gm-Gg: AZFdTZfXOBpkfRsgP9Q7fPf8VS0JlTA/dQ3ALXtm7PRs/M9tGqmWS4dchuQ+B/WN/Qb tgeqUmXpXFynRQ4vCbnh/m07z+USVkZ/qt5cTS8sT8gWMP/TtkEm0R7DqRA5EFbRCiCEHyS1jYe uKayc+Q/XO6olXec0OG7kfA4dFujE3KgGeWKAl3z8yOv51Ei4cce3B98HWaoXB0YM8ZxaJbZwKW zkoHAO4sFBYCiu/icnJd9x/YSUF+8oOAsBjqzEUbskHtf7ue07M2PR34iCQ2rMmuT7RFLHm+sxu L5clLdWq59fDIuIgXFnXXOb+O5x28bR6YA1BNRZpKTMvmK2JodI8iGJVjdgigvMgtKfIeyeuHOm d/SnIxC9n2d+jew3Aqe2lKAW0Q/UhKSdKeMa6AlXqjFgrlkUxKghvlMtn1nRBacxUVbgeDHn/Ro tCaTVjzcv8C1tTMyFpi97NJf2Z1RRuCpNiZXILltdFpc24SL4q+4KP/kLPlW2sTQJ6Wu9dZ4liA JOmbZEP7lDqv1wYoii58jPa2MNlSJu8G5vmg0UxN9LvI09XCz3YM6ZyMCJ57JDnTn2Go1mPiiU4 DOF1GCUhdwY6Y9X1ALXedClP5g+eFRCpTOI3MMyNxZgKall90jN4iinxVRCUaQ9xI51bsnwSy6E A0ai7/eV/2/sNUzGRIFzX8sXGBw== X-Received: by 2002:a05:622a:8ca:b0:55c:303f:622b with SMTP id d75a77b69052e-55d76740464mr559125311cf.0.1795924846612; Sat, 28 Nov 2026 20:00:46 -0800 (PST) Received: from localhost ([138.197.109.108]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921349f8c34sm259537606d6.32.2026.11.28.20.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 20:00:46 -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:39 +0300 Message-ID: <20261129040041.37139-2-ndokutovich@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261129040041.37139-1-ndokutovich@gmail.com> References: <20261129040041.37139-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