Re: [PATCH 1/2] liveupdate: Return -ENOTTY for unknown ioctl numbers
From: Pratyush Yadav
Date: Wed Dec 02 2026 - 05:16:26 EST
On Tue, Dec 01 2026, Chris Down wrote:
> include/uapi/linux/liveupdate.h documents the errno contract for
> /dev/liveupdate and session fds: ENOTTY means "the IOCTL number itself
> is not supported at all", and EINVAL means "everything about the IOCTL
> was understood, but a field is not correct". luo_ioctl() and
> luo_session_ioctl() only keep that promise when the command number
> lands inside their ops table. If _IOC_NR(cmd) falls outside it, they
> return -EINVAL, but they return -ENOIOCTLCMD (which userspace sees as
> ENOTTY) when the number is in the table and the full command does not
> match.
>
> This matters most for feature detection. Say a program built against a
> newer uAPI calls an ioctl the running kernel does not have yet, such as
> LIVEUPDATE_SESSION_GET_NAME on a kernel that predates it. It gets
> EINVAL, which is exactly what a known ioctl with a bad argument
> returns, so it cannot tell "unsupported" from "I passed something
> wrong". A kernel that returns ENOTTY for the same number is
> unambiguous.
>
> It also shows up when something probes an fd it did not create, which
> session fds allow since they can be passed around (eg. via a service
> manager's fd store). Current glibc sends TCGETS2 from isatty() and
> tcgetattr(), and its number is outside both tables:
>
> isatty(luo_fd) -> EINVAL
> isatty(session_fd) -> EINVAL
> ioctl(session_fd, TCGETS, buf) -> EINVAL
> ioctl(session_fd, _IO('T', 0x40), buf) -> ENOTTY
>
> Documentation/driver-api/ioctl.rst also says an unknown command should
> get -ENOTTY or -ENOIOCTLCMD and that returning -EINVAL there is wrong.
>
> Let's return -ENOIOCTLCMD for out-of-range numbers too, as the in-range
> mismatch already does. This does change the errno for a released
> interface, but the selftests only expect EINVAL for known commands with
> bad arguments, and those still get EINVAL, E2BIG and so on from the
> later checks. systemd's fd_get_luo_session_name() already treats ENOTTY
> and EINVAL alike when it falls back for a missing GET_NAME, and its
> other LUO ioctls only issue commands the kernel knows.
>
> Fixes: 81cd25d263a1 ("liveupdate: luo_core: add user interface")
> Fixes: 16cec0d26521 ("liveupdate: luo_session: add ioctls for file preservation")
> Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
Reviewed-by: Pratyush Yadav <pratyush@xxxxxxxxxx>
[...]
--
Regards,
Pratyush Yadav