From 6cdbe06519ebc235c3d0fbb8e0092ffc8abf0ce6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Sat, 1 Nov 2025 14:58:34 +0100 Subject: [PATCH] fincore: do not fall back to mincore if cachestat fails with EPERM MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit cachestat() and mincore() both require that the tested file is (potentially) writable by the current user. If this permission check fails, cachestat() will return EPERM while mincore() will simply mark all pages as resident in core, as a proper EPERM would violate its API contract. But when cachestat() fails with EPERM we know that mincore() will not return real data, so instead show an error message. Reported-by: Christian Hesse Signed-off-by: Thomas Weißschuh --- misc-utils/fincore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c index c297c1045..7ccec2a82 100644 --- a/misc-utils/fincore.c +++ b/misc-utils/fincore.c @@ -370,7 +370,7 @@ static int fincore_fd (struct fincore_control *ctl, if (errno != ENOSYS || ctl->cachestat) warn(_("failed to do cachestat: %s"), st->name); - if (ctl->cachestat) + if (errno == EPERM || ctl->cachestat) return -errno; return mincore_fd(ctl, fd, st); -- 2.47.3