Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796194428; b=wp/eaaeSPRqeOOD+VKvvrCvLV87NTzN5ahPn9zZlKXQHeAHBo6vnoHjbiVHRDwcA/6KS ZvNvMsgPeBdFr0f/7VkdIzlupO/5r5blIHstKrzuGpZPgOMDgxEarQxmE+MX6fJef6B25 qUTkB3mUqIySeYfalSaL4oIojCtKUyt2XT+brLkvuyczwiUzDLLoeU4TwMtyncMKuDGZ9 XggdWiF9Y5ii0wwg/FC66JgDD/MNnESotqqqF5vlwboj9YROSnebIT2L9G8pUJxNBplME D4eBCFo3r52jWG2LJwYz6JgcL8llHHH9k02qJNTH63MklcCKCKm+dBTzJPp6pzsU8ZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796194428; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:In-Reply-To:References:From:Subject:To:Cc: MIME-Version:Content-Type:Content-Disposition:User-Agent; bh=cbnXcfODA0xeoHE0MNVfkwAIvfo9eq5LsFNtUi+aHVc=; b=yFuD+ZZkQbbKYhBLYMG7grHSVLieAbnHtO+OGBwel41zcgHWl9p5mkviJ41Ol5Oh11sY fTrMMEWR1giS7lsQUvarGIoMy+KD5W4H3WV83WUh7+7CJkHDmEtww63hkU9vXYUT8xP3J Mq52/CXCs/5kGTaX0WdI+rGhJnQmiZ2SMcfQCj8ClM4CeMY/A1KDtjL76ZmMz626Gca/g 63ITEX4T06xOSWios8ElK7gHFprmSO19ntocknnGMCLWzje61YATAX/gLPuDafzaT3UaU ishqzhZrGIRthZ/tLEM0dnzavvWIhF0CRfz4NSTNHlEXJzxJeuyn25xLmT3RqlXLOKA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=bYcC3PMC; arc=none smtp.remote-ip=74.125.224.42 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (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 6B696606A683 for ; Wed, 2 Dec 2026 06:53:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6B696606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=bYcC3PMC Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-67db23d8892so13656405d50.2 for ; Tue, 01 Dec 2026 22:53:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1796194427; x=1796799227; darn=vger.kernel.org; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=cbnXcfODA0xeoHE0MNVfkwAIvfo9eq5LsFNtUi+aHVc=; b=bYcC3PMCAJQfZV6pkllbOQBS2Lr4QYKQ3LJfuecEo7ilFezynG1C/YfI3KW21RcUbg GDWCuThM98Ar1qln9F67gfuhmGPRLLxRvZvx90i4OtysPZ118RdFytcqNKyeOGClJsr9 A2PTySQLZCA31BIlMBagklvlARiTtFuiX0pPU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796194427; x=1796799227; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:references:in-reply-to:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cbnXcfODA0xeoHE0MNVfkwAIvfo9eq5LsFNtUi+aHVc=; b=ygtf58OMVKUas/uDHeKxRuSPjOL+1GdLdyMSKCdTCtoxPjO5RKmHEg2qS3vbS2WbaR oP/9z+nXmzFMe1fZSkA+mp+2R10EwZbCwp9ir72xK4VU87BtbxpKSjz82Jfa4vxEf8/7 L+36wI4TYWhEu95NxQeyz6Btv4+W3h5HpHcx5ntPbNSXKBHtaCDNld+YfrMSccfqm70E dIzXcIhW5jGtbgVbaea0s/3RY72Z1rK969Oz3r7QL8pzJc5CDVk+es+wl4S4n9SAA/Gm wMXtr7VkMsx80PV5e5mNtVBoL/t1u8rx+/R3EgR4puXl3EYz5xDi861OBFqG4YOu8H46 1wjA== X-Forwarded-Encrypted: i=1; AL+hErH1XIemxP1+p/2PY8SjdPiV1g9pKZknv34YjjaIReqIrs4lPAEZmH8bTvyXsvHdBVSokEYKfKP7O/Y=@vger.kernel.org X-Gm-Message-State: APuU4Z/wB/MXI+W5vtNJyAVxcGkgABDAp/d7ocM85YGdC8uO2rAUwuOn jb/vd8I21NBfqmU+ysdS5a6xKlRu+uXX2wDGfbqXLJNNLhNs25vImbm4jf9yLW6tf3o= X-Gm-Gg: AZFdTZcv0TOTg5Cx0qiWScKeOTVvhy1oUf/l+fnch5BweM6xGuLy4duE3I1CMpnvyE2 Yl6qzgj4aYLqscLAhwKU6ADpZv3bt2HCZFmuHs++TXl+E8vQtreFqmk3IOM8h1WHgxE5EXsTd1m WTPWvr4SJvYJs+7r1uvVb1YKrhgZbcrRoPGDt2k3B5cHoyFDLhD+odb05dT7W5ZoCrNr310XfWx cH8R4b70mwnzU5EjW3OpSxC27Z9N0r9ZaulNMALKG4GcKSVc5/L45M4r0gWEEH1/7fp0Id9DczY 2QRsFxmPsVfvtujPRi//MxrzDvKGBb7rbY5dCDvUfIhqzzfSPrLUnbTfo3fugY2C3lqLxM/7PM7 UvNfox2s8w9YuPa/NZu+lKePwQq/Gjebf4cr0aH0BX+tY6thyLqpIVsRQjQPrg8qZA0VeeE2Slb 8mbfvAP73mczZT5IQWyN2H8t3PL7KPG6egqtyD8Pl6q2m2FtTBVfjkmFdaNp92rYzZVkEouyg4P gnd0C+20nKA97cVzD2vsV/6Fy1og6eXi7IzurZTQGELPbjtu9uDyCCVkzpicd/4mc6cq44xiVdL OIKkgJrA+t3fQiuRlJt+3QcwrJs4RO890o2LH52npCShr2P53h4Dg6dpss9EnUy+tDvR4PD+xf6 p5Uj6fORqXF41OxVt+ssvymZAJxpEk/tdb/K7HDnxNbuzHLP2pwwoqy/hFEol+PVsuHkR3Hsddw bR2iedM9HPdmleQTu5WPrvr0a0aAtNjX/m6qBOWKtWdm0I+0uP+KmxYEUG4Xnx62Qv1mLcarPEx tvx0gxx6ZbHHnA1019zvaeF X-Received: by 2002:a05:690e:4146:b0:67d:bda2:a4f6 with SMTP id 956f58d0204a3-67df44c4aabmr21244487d50.108.1796194427488; Tue, 01 Dec 2026 22:53:47 -0800 (PST) Received: from [172.20.0.3] (c-73-207-185-9.hsd1.ga.comcast.net. [73.207.185.9]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df33554b5sm17680518d50.13.2026.12.01.22.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 22:53:46 -0800 (PST) Date: Tue, 01 Dec 2026 22:53:44 -0800 Message-ID: <2b8066fe1f98c6063b94de5bf14e926ba13a58e6.1796194107.git.chris@chrisdown.name> In-Reply-To: References: From: Chris Down Subject: [PATCH 1/2] liveupdate: Return -ENOTTY for unknown ioctl numbers To: Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: Shuah Khan , Shuah Khan , linux-kselftest@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.4.3 (cc9e3943) (2026-10-09) 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 --- 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