From nobody Sun Jun 28 23:59:12 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gpRG85c41z6jSHC for ; Sun, 28 Jun 2026 23:59:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gpRG83RCqz3Th1 for ; Sun, 28 Jun 2026 23:59:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782691152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7HlFSCM1S1kvBEI6PUcv0HP6wPBZLhANjGfeEfdRlpw=; b=qjINP8xXmyA0Vg3BMUMU0wzY7azRFElJd9j9nU+mjmVy5UcsR9Z7nfbHxc1nZD2hqnZlIB ECnoZwj/TamBCkY1LWRM8uitDtXQacF5yempCO00AIqvs9v2TIBkk2TPkHThy0pyXp7iLM ZNUG/Uh2N7/Orf/Jr+IKsBqT5n6k+BGMk21igqO31P7+QhdJCQ9TqfBlZc+eL6k0cyVBWQ HalFi4fBRxyqjIgXOYVLwBEOLygjixVUxG5lxRN7dbUlwIT7+BUeLgyibVga7NwS+eie9p i3v4pdLqXYhE1odRaf97aidA4J//S53+4SDF6GYDbO26PvAdm7M8cCmZ3GHEmA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782691152; a=rsa-sha256; cv=none; b=mUYJvr9bB6isI4qnQnR5srxHj8dZh+vplAEV9GpsDJ8/ZahV+C73kEpO85uF6bsYGwPvCQ BoJ3st8Sk0ZNvGlldYI7IZ77ym8gCrxSKcauM/T2IA40mdsjxGfV2YnOiQ/e2TBa5jiOYf B7O3/F/aOkdcimeeBYJFCBwIOnx2gErb0TQf/QmfqmYWUIwW791caLwtbjG7wiFej6M59H vw0dJcndiuJp+MiteNRWHgkSBOOiA6d6iVPEmYu5lQaFlFU0EhxoEPHIXZ1qzUKjpIKVMn D+Y+66fp17tRgW5cgkALpA/eZr9DTcWusVZw+6Kmt8CP3TKGBjIjaiA2nUSaPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782691152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7HlFSCM1S1kvBEI6PUcv0HP6wPBZLhANjGfeEfdRlpw=; b=yH94XHIEUi538EJaTH1v511ZFduUZSKIPs7xdGVVhk9jPp6q4C+HS4GGo1jaKohSV+D4Pk 7ckV4+bGNEwMpBjX4H7+BuWq7p2M6FsAhgMC3Hl7AX4TnJvKf2HPNgUFQCmDScs7yYYQQ8 avt9PjBitWp/qdQ87G01AoIr09Hu7MVTs6q7NzS+OvNMrayvpjWxC1GWDYB67UERsXk4UM geWaHL3KqSGy99KdAMY3dN1ByNAOL04As5YcDrHqMKEuE8m51PSi0+x5rmIjWcmvzVueVy LxSO39+AeJYBg3jkMq8eKvt/N2zBqvnr5G3znbAEoAotxf/KXtWbYBhjIo7nQw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gpRG81WM4zYtk for ; Sun, 28 Jun 2026 23:59:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 43b47 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 28 Jun 2026 23:59:12 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 30fff269ad1c - stable/15 - linuxkpi ioctl handler: restore the user data pointer List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 30fff269ad1c046d38469ad66f211334d2034982 Auto-Submitted: auto-generated Date: Sun, 28 Jun 2026 23:59:12 +0000 Message-Id: <6a41b550.43b47.52ab1bb4@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=30fff269ad1c046d38469ad66f211334d2034982 commit 30fff269ad1c046d38469ad66f211334d2034982 Author: Konstantin Belousov AuthorDate: 2026-06-16 22:12:01 +0000 Commit: Konstantin Belousov CommitDate: 2026-06-28 21:43:27 +0000 linuxkpi ioctl handler: restore the user data pointer (cherry picked from commit 91413e8e6311b4d4891dc2299d144feb31e04628) --- sys/compat/linuxkpi/common/src/linux_compat.c | 48 ++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 2fd502990eb3..e93963428195 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -926,19 +927,39 @@ linux_file_ioctl_sub(struct file *fp, struct linux_file *filp, struct task_struct *task = current; unsigned size; int error; + bool direct; size = IOCPARM_LEN(cmd); /* refer to logic in sys_ioctl() */ + direct = false; if (size > 0) { /* * Setup hint for linux_copyin() and linux_copyout(). * - * Background: Linux code expects a user-space address - * while FreeBSD supplies a kernel-space address. + * Background: Linux kernel code expects to operate on + * userspace addresses, but FreeBSD's kern_ioctl() + * will generally provide a kernel address. For the + * native process ABI, where we know how to find the + * original address, we reach directly into the system + * call args to get it. Then, if the Linux driver + * copied out to that address, we copy the whole block + * back into the kernel buffer allocated by + * kern_ioctl() so that kern_ioctl() itself doesn't + * clobber the driver's data. + * + * Otherwise, fall back to the LINUX_IOCTL_MIN_PTR + * hack. */ task->bsd_ioctl_data = data; task->bsd_ioctl_len = size; - data = (void *)LINUX_IOCTL_MIN_PTR; + if ((td->td_pflags & TDP_KTHREAD) == 0 && + SV_PROC_ABI(td->td_proc) == SV_ABI_FREEBSD && + td->td_sa.code == SYS_ioctl) { + direct = true; + data = (void *)(uintptr_t)td->td_sa.args[2]; + } else { + data = (void *)LINUX_IOCTL_MIN_PTR; + } } else { /* fetch user-space pointer */ data = *(void **)data; @@ -968,11 +989,30 @@ linux_file_ioctl_sub(struct file *fp, struct linux_file *filp, error = ENOTTY; } } + if (error == 0 && size > 0 && (cmd & IOC_OUT) != 0 && direct) { + void *xdata; + int error1; + + /* + * Ensure that the copyout in sys_generic.c copies + * over the data which is possibly modified by the + * driver. A possible error from the copyin() is + * ignored since it is formally possible for the memory + * to become unaccessible in the meantime. Do the copying + * through the intermediate buffer instead of copying + * directly to bsd_ioctl_data, to ensure atomicity of + * the change with respect to the error. + */ + xdata = malloc(size, M_TEMP, M_WAITOK); + error1 = copyin(data, xdata, size); + if (error1 == 0) + memcpy(task->bsd_ioctl_data, xdata, size); + free(xdata, M_TEMP); + } if (size > 0) { task->bsd_ioctl_data = NULL; task->bsd_ioctl_len = 0; } - if (error == EWOULDBLOCK) { /* update kqfilter status, if any */ linux_file_kqfilter_poll(filp,