Re: [PATCH] fs/proc/task_mmu: return -ENOTTY for unknown pagemap ioctls

From: Pedro Falcato

Date: Mon Oct 26 2026 - 09:23:42 EST


On Fri, Oct 23, 2026 at 02:13:00PM -0400, Hengyu Liang wrote:
> Commit 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and
> optionally clear info about PTEs") made do_pagemap_cmd() the ioctl
> handler of /proc/<pid>/pagemap.
>
> However, do_pagemap_cmd() returns -EINVAL for every command other than
> PAGEMAP_SCAN. Before that commit, pagemap had no ioctl handler, and
> the VFS returned -ENOTTY for these commands. As of now, they fail with
> EINVAL, so tcgetattr() and isatty() on pagemap report EINVAL instead
> of ENOTTY.
>
> The issue can be reproduced with a simple C program:
>
> #include <fcntl.h>
> #include <stdio.h>
> #include <termios.h>
>
> int main(void)
> {
> struct termios t;
> int fd = open("/proc/self/pagemap", O_RDONLY);
>
> if (tcgetattr(fd, &t) < 0)
> perror("tcgetattr");
> return 0;
> }
>
> Before that commit, the result is:
>
> tcgetattr: Inappropriate ioctl for device
>
> After that commit, the result is:
>
> tcgetattr: Invalid argument
>
> This patch will return -ENOIOCTLCMD for unknown commands, as
> procfs_procmap_ioctl() in the same file does, so that the VFS turns it
> into -ENOTTY.
>
> Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Hengyu Liang <hengyul@xxxxxxxxxx>

Reviewed-by: Pedro Falcato <pfalcato@xxxxxxx>

I would generally be scared of applying this change, but since this is a
niche API, and there are no other ioctls for it, this should be fine.

--
Pedro