* [PATCH 6.12.y] net: call getsockopt_iter if available
@ 2026-10-22 11:15 Emanuele Ghidoli
2026-10-22 12:39 ` [6.12.y] " bluez.test.bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Emanuele Ghidoli @ 2026-10-22 11:15 UTC (permalink / raw)
To: stable
Cc: Breno Leitao, Greg Kroah-Hartman, Sasha Levin, Jakub Kicinski,
Stanislav Fomichev, Luiz Augusto von Dentz, netdev,
linux-bluetooth, regressions, Emanuele Ghidoli
From: Breno Leitao <leitao@debian.org>
commit 5bd0dec150f56b6307d599132dcb7c01007bbecc upstream.
Update do_sock_getsockopt() to use the new getsockopt_iter callback
when available. Add do_sock_getsockopt_iter() helper that:
1. Reads optlen from user/kernel space
2. Initializes a sockopt_t with the appropriate iov_iter (kvec for
kernel, ubuf for user buffers) and sets opt.optlen
3. Calls the protocol's getsockopt_iter callback
4. Writes opt.optlen back to user/kernel space
The optlen is always written back, even on failure. Some protocols
(e.g. CAN raw) return -ERANGE and set optlen to the required buffer
size so userspace knows how much to allocate.
The callback is responsible for setting opt.optlen to indicate the
returned data size.
Important to say that iov_out does not need to be copied back in
do_sock_getsockopt().
When optval is not kernel (the userspace path), sockptr_to_sockopt()
sets up opt->iter_out as a ITER_DEST ubuf iterator pointing directly at
the userspace buffer (optval.user). So when getsockopt_iter
implementations call copy_to_iter(..., &opt->iter_out), the data is
written directly to userspace — no intermediate kernel buffer is
involved.
When optval.is_kernel is true (the in-kernel path, e.g. from io_uring),
the kvec points at the already-provided kernel buffer (optval.kernel),
so the data lands in the caller's buffer directly via the kvec-backed
iterator.
In both cases the iterator writes to the final destination in-place at
protocol callback. There's nothing to copy back — only optlen needs to
be written back.
Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20260408-getsockopt-v3-2-061bb9cb355d@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
---
Clean cherry-pick of the upstream commit, no changes. Needed in 6.12.y
only.
v6.12.114 picked up commit 41fbf726915b ("net: add getsockopt_iter
callback to proto_ops", upstream 67fab22a7adc) and commit 22ebe6ab0b67
("Bluetooth: L2CAP: convert to getsockopt_iter", upstream bf01627cc04b)
as dependencies of commit 3af72bf8f73c ("Bluetooth: L2CAP: access
chan->conn safely in get/setsockopt", upstream ca2c4c264986), but not
this patch, which is the one making do_sock_getsockopt() actually call
->getsockopt_iter().
Since l2cap_sock_ops no longer provides ->getsockopt, every getsockopt()
on an L2CAP socket at SOL_L2CAP/SOL_BLUETOOTH level fails with
-EOPNOTSUPP on v6.12.114. As a result bluetoothd never registers the
adapter and bluetoothctl reports "No default controller available":
BlueZ's btio calls getsockopt(L2CAP_OPTIONS) while bluetoothd sets up
the BR/EDR ATT listening socket of the GATT database, and the adapter
is dropped when that fails. Our CI sees this on every Bluetooth-enabled
board running v6.12.114 (i.MX 8M Plus and AM62 based, BlueZ 5.72),
while v6.12.113 was fine. The same regression was reported with an
Intel AX201 on Debian 13:
https://bugzilla.kernel.org/show_bug.cgi?id=222177
L2CAP is the only user of ->getsockopt_iter in 6.12.y. The other stable
trees either did not get these backports or already contain the
upstream commit. The patch applies cleanly on v6.12.114.
Tested on a Verdin iMX8M Plus with our v6.12.114 based kernel plus
this patch.
The root cause analysis (comparing CI logs, reviewing the
v6.12.113..v6.12.114 changes and reading the BlueZ code) was done with
the help of an AI coding assistant (Claude); I reviewed the analysis
and the backport.
net/socket.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 51 insertions(+), 3 deletions(-)
diff --git a/net/socket.c b/net/socket.c
index 723bc3a1ba5c..b8d662e19310 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -77,6 +77,7 @@
#include <linux/mount.h>
#include <linux/pseudo_fs.h>
#include <linux/security.h>
+#include <linux/uio.h>
#include <linux/syscalls.h>
#include <linux/compat.h>
#include <linux/kmod.h>
@@ -2345,11 +2346,45 @@ SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
INDIRECT_CALLABLE_DECLARE(bool tcp_bpf_bypass_getsockopt(int level,
int optname));
+/*
+ * Initialize a sockopt_t from sockptr optval/optlen, setting up iov_iter
+ * for both input and output directions.
+ * It is important to remember that both iov points to the same data, but,
+ * .iter_in is read-only and .iter_out is write-only by the protocol callbacks
+ */
+static int sockptr_to_sockopt(sockopt_t *opt, sockptr_t optval,
+ sockptr_t optlen, struct kvec *kvec)
+{
+ int koptlen;
+
+ if (copy_from_sockptr(&koptlen, optlen, sizeof(int)))
+ return -EFAULT;
+
+ if (koptlen < 0)
+ return -EINVAL;
+
+ if (optval.is_kernel) {
+ kvec->iov_base = optval.kernel;
+ kvec->iov_len = koptlen;
+ iov_iter_kvec(&opt->iter_out, ITER_DEST, kvec, 1, koptlen);
+ iov_iter_kvec(&opt->iter_in, ITER_SOURCE, kvec, 1, koptlen);
+ } else {
+ iov_iter_ubuf(&opt->iter_out, ITER_DEST, optval.user, koptlen);
+ iov_iter_ubuf(&opt->iter_in, ITER_SOURCE, optval.user,
+ koptlen);
+ }
+ opt->optlen = koptlen;
+
+ return 0;
+}
+
int do_sock_getsockopt(struct socket *sock, bool compat, int level,
int optname, sockptr_t optval, sockptr_t optlen)
{
int max_optlen __maybe_unused = 0;
const struct proto_ops *ops;
+ struct kvec kvec;
+ sockopt_t opt;
int err;
err = security_socket_getsockopt(sock, level, optname);
@@ -2362,15 +2397,28 @@ int do_sock_getsockopt(struct socket *sock, bool compat, int level,
ops = READ_ONCE(sock->ops);
if (level == SOL_SOCKET) {
err = sk_getsockopt(sock->sk, level, optname, optval, optlen);
- } else if (unlikely(!ops->getsockopt)) {
- err = -EOPNOTSUPP;
- } else {
+ } else if (ops->getsockopt_iter) {
+ err = sockptr_to_sockopt(&opt, optval, optlen, &kvec);
+ if (err)
+ return err;
+
+ err = ops->getsockopt_iter(sock, level, optname, &opt);
+
+ /* Always write back optlen, even on failure. Some protocols
+ * (e.g. CAN raw) return -ERANGE and set optlen to the
+ * required buffer size so userspace can discover it.
+ */
+ if (copy_to_sockptr(optlen, &opt.optlen, sizeof(int)))
+ return -EFAULT;
+ } else if (ops->getsockopt) {
if (WARN_ONCE(optval.is_kernel || optlen.is_kernel,
"Invalid argument type"))
return -EOPNOTSUPP;
err = ops->getsockopt(sock, level, optname, optval.user,
optlen.user);
+ } else {
+ err = -EOPNOTSUPP;
}
if (!compat)
base-commit: 85d82e0d7c2dfd3e75d34f35b7ebbf41f45c9c4e
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* RE: [6.12.y] net: call getsockopt_iter if available
2026-10-22 11:15 [PATCH 6.12.y] net: call getsockopt_iter if available Emanuele Ghidoli
@ 2026-10-22 12:39 ` bluez.test.bot
2026-10-23 20:02 ` [PATCH 6.12.y] " Sasha Levin
2026-10-26 10:09 ` Breno Leitao
2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2026-10-22 12:39 UTC (permalink / raw)
To: linux-bluetooth, ghidoliemanuele
[-- Attachment #1: Type: text/plain, Size: 821 bytes --]
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: net/socket.c:77
error: net/socket.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6.12.y] net: call getsockopt_iter if available
2026-10-22 11:15 [PATCH 6.12.y] net: call getsockopt_iter if available Emanuele Ghidoli
2026-10-22 12:39 ` [6.12.y] " bluez.test.bot
@ 2026-10-23 20:02 ` Sasha Levin
2026-10-26 10:09 ` Breno Leitao
2 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-10-23 20:02 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Breno Leitao, Greg Kroah-Hartman, Jakub Kicinski,
Stanislav Fomichev, Luiz Augusto von Dentz, netdev,
linux-bluetooth, regressions, Emanuele Ghidoli, Emanuele Ghidoli
> Update do_sock_getsockopt() to use the new getsockopt_iter callback
> when available. Add do_sock_getsockopt_iter() helper that:
Queued for 6.12, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 6.12.y] net: call getsockopt_iter if available
2026-10-22 11:15 [PATCH 6.12.y] net: call getsockopt_iter if available Emanuele Ghidoli
2026-10-22 12:39 ` [6.12.y] " bluez.test.bot
2026-10-23 20:02 ` [PATCH 6.12.y] " Sasha Levin
@ 2026-10-26 10:09 ` Breno Leitao
2 siblings, 0 replies; 4+ messages in thread
From: Breno Leitao @ 2026-10-26 10:09 UTC (permalink / raw)
To: Emanuele Ghidoli
Cc: stable, Greg Kroah-Hartman, Sasha Levin, Jakub Kicinski,
Stanislav Fomichev, Luiz Augusto von Dentz, netdev,
linux-bluetooth, regressions, Emanuele Ghidoli
On Thu, Oct 22, 2026 at 01:15:21PM +0200, Emanuele Ghidoli wrote:
>
> v6.12.114 picked up commit 41fbf726915b ("net: add getsockopt_iter
> callback to proto_ops", upstream 67fab22a7adc) and commit 22ebe6ab0b67
> ("Bluetooth: L2CAP: convert to getsockopt_iter", upstream bf01627cc04b)
> as dependencies of commit 3af72bf8f73c ("Bluetooth: L2CAP: access
> chan->conn safely in get/setsockopt", upstream ca2c4c264986), but not
> this patch, which is the one making do_sock_getsockopt() actually call
> ->getsockopt_iter().
Right, if you got the protocol's conversion to getsockopt iterator, you
need this one as well.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-26 10:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 11:15 [PATCH 6.12.y] net: call getsockopt_iter if available Emanuele Ghidoli
2026-10-22 12:39 ` [6.12.y] " bluez.test.bot
2026-10-23 20:02 ` [PATCH 6.12.y] " Sasha Levin
2026-10-26 10:09 ` Breno Leitao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.