From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796251485; b=dcccJDuirl7EDqLt/1ErvcubGnRFocCTQZcjVpTSVUV4XSCLsH8nl0x/9XmeIlAM2h2Q PqpW37TpcaLIuTNSl46KBPsB+3676UKIfDk5Sln0Xx74ZOSYLX5Y+f60DWr0BLyzaI+qo OMHsJXsl9XvNei16t7HC623co91F9o7H600qjyCyFMd2E0mI/c3uSE2j82aoE4zWOYl7Z 0YdDND7JIl5PpxbuiGZAr7r8vXaQ55RK5/R7RbN3qyTwyh55CihqUHVQzDF4bKc0sDyJ4 ykUQX5hMkYaJ10YIoP3BQou3h7eofGrZCe/WyRYh8l1jfM+ZxyimUYpSDdOg7JGRTvQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796251485; 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=nzG0CPlwBpHedLYUs20v8fXRMUKwvMXzFXLxHjLqKOw=; b=ch2s6D5LwQ6YolNpLXw3S+T43wrzdY9jBqQGqds32fuASzMvC/4jRz4bKV/9vbpI525A CYE4CoPp7LysjWNsUL40BfRsBi0nlCxdCuN4lOnIxr6JL7+DvkjfTqmCBA73XX4peqB36 wmXUAf7nwgwwlip0Pnm8atpG4+xZE7h8muq94teBGGbR6fSV84t6iLttBqKx81QkI4keK Ngf4PydthB9R3/qEQJHhDhgTEJbRT0My+FRbiBu1ZVnUFQlKMDKvgLj+j7uyxK8Llsvxw klDkalOf8g8q99LI/fYU+zDF+PmDj6WIBU9lBJQSSts+ruYidSxxWngJA56/qK/JGGA== 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=V+hbV8Lg; arc=none smtp.remote-ip=74.125.224.44 Received: from mail-yx1-f44.google.com (mail-yx1-f44.google.com [74.125.224.44]) (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 C35E3606A336 for ; Wed, 2 Dec 2026 22:44:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C35E3606A336 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=V+hbV8Lg Received: by mail-yx1-f44.google.com with SMTP id 956f58d0204a3-67dc7eb1442so14584647d50.0 for ; Wed, 02 Dec 2026 14:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1796251484; x=1796856284; 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=nzG0CPlwBpHedLYUs20v8fXRMUKwvMXzFXLxHjLqKOw=; b=V+hbV8LgF39FA86RkJjdS6SYZe6j4y8lxaeNvcwLFEB1BFZxKQhnMlnC0fSoyyzPhS tmMujhKF7e+M+rulazW/SZ8HC/hHbJR/wnx0HYogQLfDTS1n8bA1oUyC5YPjJ95o5WB5 XUVgaC+lbTv0egMYCAtA4Aa129njvYD3I2GQA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796251484; x=1796856284; 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=nzG0CPlwBpHedLYUs20v8fXRMUKwvMXzFXLxHjLqKOw=; b=RQKee0FK8qiW+TVlUuVRYHnvTLrp0AKueWnG+5OAqCNe4Hjdirks+FkIw4h9sMxAKl v8sGiRsQhhvJKQfJYDwL71l7rDEeG22FfkGaPJ7N210soJx5J/ih1UqFidcc6yHIcazQ XirkY79m7qlhGowXa0vfV2hLIdIJODx0DVwRKiNBxG9B2Lz4KVRLA/Z+Bo1M1w7zjpiU +pkP9q4YbX48N3rSNynIQnVeUY4pMaCZ+ddG6VQJ/fUosZgkSJZS0mh6O8QSkqnNsiB5 jrpKzrGhAhusLF7W43rA7N52VOS7UNFf0tC/Yv7UtVYgLWOaKvJUEGtllseWRnhs3TRM oZGw== X-Forwarded-Encrypted: i=1; AL+hErHQaYEx09RSXc+zLKcrUiU/G6zZrB6SqFGnlbSG+hUP5Np6FOmGa120Lbe7cGqG3q+0bBCRKG592fX3a+A=@vger.kernel.org X-Gm-Message-State: APuU4Z+S6zJ8/Lq8nt7meP2IvRAzZoUCHALp8DgcekPFa1kqYQ2iA+y3 n3B4MrH+f4s/QsUJB4iGloAdnPq1OVYt0AW9ZHe8pOT3e4uvRPcQqhDuZG/MzyzuKZI= X-Gm-Gg: AZFdTZd7f7yMQ5ftWriuRcin3dmuLzDU13opdjJg36u512iq6WfRprZkaiJrN6HHwCg 2iNfpLfpRBvrcuDd900TnXs4h829WzQk8ErPSg7IzZziwo+2vmOPGZzSdgvXATIab5hM8w25ZQe S7+edbpx+toNZgDqLwCoUH3A6XxgXN0DLmdHIou4XYCRUE5BRY68nRDV2m00E3HHsLHO/N6EoRw L0tOPOMIkzrRLwvgQTiseO58tqGCuq2KjnLDQ+oAMlLiMPTNu+U5FBh1ezRYKLTgclE0uvjpFEl xhXiAWyFPREfnVzgFDKnMvPyPomAkxyeMfexcL3G4NhEhvXT1eq1IY6DuEMZbkK+tUPLBU+hUwW FrUXSd+vMjjZ4f00t7QJkwRSTR0imgf0AzkLpN+PZscRBLG14AKqqPaqwTy/QJVGW16mOLqkFda Q1wOA9mBTKF8oe9gxLIsuN54o2h3K/MuG+yghU8qky97GDCMp5wcFdp5jRvr63qqVZ2iKmy9yXD dMiXyZuVGwz8Y0sDeud9n7DMH7wOVnVbuBe2LbFRIhK7mL7Bs1D3qWLAi+0eQ5c6lhntfo8cCFh 4pbnuI599KDCRohhoMh11I3bCOSUrV5wbPM3LVn6wDf9693n7wuUeTauLe1m5wEtVIN/ithxx5E xaLqNLAOYf8QKb1D37TDXsTv9gzUY8pjGpYRf+w9JaVPUxgMcE+6FePV6FrCC5GbIXoJdn39H7r M1DzVmXGpN6QYJycc75+aFFdomezD0ZpRALK9cddMFSdGcOAQC1p85GSw43UGKc4TQEKJuGytqp YlZmNaaHgf14bXj2gJ6Jcg= X-Received: by 2002:a05:690e:bc6:b0:67b:e31d:6eec with SMTP id 956f58d0204a3-67df43f2fe8mr21330084d50.29.1796251483871; Wed, 02 Dec 2026 14:44:43 -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-67df3394796sm18831967d50.17.2026.12.02.14.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 14:44:43 -0800 (PST) Date: Wed, 02 Dec 2026 14:44:40 -0800 Message-ID: In-Reply-To: References: From: Chris Down Subject: [PATCH v2 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, sashiko-bot@kernel.org, kernel-team@meta.com 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") Reviewed-by: Pratyush Yadav 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