mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: Pasha Tatashin <pasha.tatashin@soleen.com>,
	Mike Rapoport <rppt@kernel.org>,
	Pratyush Yadav <pratyush@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	linux-kselftest@vger.kernel.org, kexec@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-api@vger.kernel.org
Subject: [PATCH 1/2] liveupdate: Return -ENOTTY for unknown ioctl numbers
Date: Tue, 01 Dec 2026 22:53:44 -0800	[thread overview]
Message-ID: <2b8066fe1f98c6063b94de5bf14e926ba13a58e6.1796194107.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1796194107.git.chris@chrisdown.name>

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@chrisdown.name>
---
 kernel/liveupdate/luo_core.c    | 2 +-
 kernel/liveupdate/luo_session.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c
index a9215eca9e7e..34422b81beaf 100644
--- a/kernel/liveupdate/luo_core.c
+++ b/kernel/liveupdate/luo_core.c
@@ -394,7 +394,7 @@ static long luo_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 
 	nr = _IOC_NR(cmd);
 	if (nr - LIVEUPDATE_CMD_BASE >= ARRAY_SIZE(luo_ioctl_ops))
-		return -EINVAL;
+		return -ENOIOCTLCMD;
 
 	ucmd.ubuffer = (void __user *)arg;
 	err = get_user(ucmd.user_size, (u32 __user *)ucmd.ubuffer);
diff --git a/kernel/liveupdate/luo_session.c b/kernel/liveupdate/luo_session.c
index 1ed914db513d..6ea2d3d36f70 100644
--- a/kernel/liveupdate/luo_session.c
+++ b/kernel/liveupdate/luo_session.c
@@ -414,7 +414,7 @@ static long luo_session_ioctl(struct file *filep, unsigned int cmd,
 
 	nr = _IOC_NR(cmd);
 	if ((nr - LIVEUPDATE_CMD_SESSION_BASE) >= ARRAY_SIZE(luo_session_ioctl_ops))
-		return -EINVAL;
+		return -ENOIOCTLCMD;
 
 	ucmd.ubuffer = (void __user *)arg;
 	ret = get_user(ucmd.user_size, (u32 __user *)ucmd.ubuffer);
-- 
2.56.1


  reply	other threads:[~2026-12-02  6:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:53 [PATCH 0/2] " Chris Down
2026-12-02  6:53 ` Chris Down [this message]
2026-12-02  6:53 ` [PATCH 2/2] selftests/liveupdate: Test ENOTTY " Chris Down

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b8066fe1f98c6063b94de5bf14e926ba13a58e6.1796194107.git.chris@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=kexec@lists.infradead.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®