From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796194429; b=qYjQ6ECDxXVXqcX7jCrEcRYBebwxy0N6bRiO78Y+vEMsIB6d4168ou9DG0Gnj5KiIQBs cbir8+HQSiihxZGCN1ABboPtWAuZ1ABzvXkQ10bzwaBg7nQvjknR6n6XKaaQOBk1uDbnB vWKefT5HyM47S19KHlvqQmkqaE67v6GXrVKT0Zf4Ht0TfYV8qSAPxXZH1kpAPDoCoqVxB fEnlAoiIgs38SS9d7dSpjBX+4/TzCcrAGX4Bk1lcnZhpaEJEgjOL5GOs1GSjrkWZpFBKA 6HgmlSFNxYy1YCJMo7ifSU18395w9kKZFMr1nwi4C+bqT0cWrMyYq/khyEoe4nIgOgg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796194429; 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=q4MRErTr85wZeQb7I2DqhASjR5j3EKMXVDJFlPSyQXeuqBGYRBO+/G0Xk4VANaiG96rm JZEUH8meNzmDj1gM2vHN4AI1lU5q4PZ/zApr4N6wtt7/efeWZT5jbKfVd44LoJf8dumOf Qb2B+/Nfyt1Y75z2XQMjH97Kj54iWUt/MDNe9szgtz9L/tidtrvHQSLIUMMPmCUM+tKZ/ bxF8asV3oJYsuzMvjgVtCpA2f473XxmunJs7ImjSn95T/MiWykPz5JwuqGLcxTtrhpi2O VsIpP8IoaYfbfn8jAQO0wrlywhhRUiL7B5iaZcGIcOQJlmrDNzbwTYj8Hex6e3MxcaQ== 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.48 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (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 6706E606A33F for ; Wed, 2 Dec 2026 06:53:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6706E606A33F 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-f48.google.com with SMTP id 956f58d0204a3-67990a45e02so13159143d50.3 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=HHe04Q4h8I6nbJ++dJ40oPJNZvwASJxmTE9jsDlSqhctamwLijn82bSnhPRjk2UGAU rNu/ASSEzLWcds2ve4OhyjgcOCGJi/z5CJryEibnDa2fFpAdeY/hRKdrRznwV3L4e0P1 NqgNSKNpvyp8aaOgNO8uh/SgwkQMauQutMwc8QSLIuCxLThFk+n0NQ4i4YRo89IoSw7M RLr2P9aj7tD7XehSd7FspJMcYDu8c07ZFl12bBtRQzdVmCOHTfSWvZPscs4OVk4A9JHS nmblyekr6OZiAzbSvXladxcxeUqUWsXKI88+COPUpd1gc3NT90kFtDrRJF6jjtQY2tbt I5xw== X-Forwarded-Encrypted: i=1; AL+hErHwyMbtzL4GStZIvKbxbpvKdffqVORGFqBg1D/3hGnFH+7/ndFt+qAjl9OM03MiNBYE3MU1cOALx3ajGMM=@vger.kernel.org X-Gm-Message-State: APuU4Z+FZe4snJATkGEUXxhTWd/v+YumKIjGA3LA6DjqgKM/9oF0n8U/ 3jprYEIQu6+l+OnuLZyuQk/mE+x+ASm3DqJN5VlFBwILpZnZ04Xqqlh4O3inir53ZPRTUPt3hp/ 8CS0oZh886aHloCQ= X-Gm-Gg: AZFdTZdmHj8CgE69QEARxPiG1TM/ZB/U00kQuaAfIaNZeWFnH2duwAhotFDlHDY8nZV PQ/ZkODm0386gBwTeG1mnRS+Cqep7PNP7DeJ8G7t3koFE50Fb2L5jy4Iuwxg/FZytNIkblfKPw3 PR5pTV1+nmoQG09WYdI/CU8odvNj4gxojjbHbBHQ6YR7WILAwZI+po2r0yYPJwSObc3KX2QA1PQ gSe+QfoCg1W1tzoLL/POEhqN6ozgZSH4bFqkxGiA1n1ncjvyIvAkprddshiHLYZ6rQJXHlxLh7h WT+iBPWhFmRcsnC/3v9sIAlruVmSQbfMfbiWNdjS5ntaQ/fykZl5rykxzfkFYmq1U8tOHwP/nP9 j4MS2WOmsRcZYbBdgTJLvZ7gwWj5UKGz+hpLZNJmz7STsFI2FUCQnhcUGwV+YA7tkmDjiRVSUhq YX/+4x8dlYHJvBQiF/F8YCb2QL7xkv5Vh2o0YWfVBJPGwa/NYH9DPzJ/j57UP5iSj4Vk93yO0u7 P5TL1lvMFydtVlybc7DVgTCkjz+4xslOrfXNiB40fTvuNJ+U9bVbviKrexwAmjCUIOr4fs6Oq8G HAvNGkwg6sR6MuiE8vCPhtSTI09DXLHNnRviO+qXbMhpFDueyDIMcDuDvde8PZBMvp6LtA/cEj9 uhmrZ7TjMg3RNoSVMdFFxdlxIQOF+LcV6L5PPElqrp45rJTxK73wPqku/fBCY4eR1GTlNP6qZN1 yubUcZy/bffetiBym1xDJ/UmAOS9pSMUDYraJsg0aVeX4rE4XU0w0QjQwqwLkkIoWP5Oc97gfan CLvQZMdh02ahQ6/yqhDdjik 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-kernel@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