From: Simon Horman <horms@kernel.org>
To: maoyixie.tju@gmail.com
Cc: 'Simon Horman' <horms@kernel.org>,
achender@kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com,
praveen.kakkolangara@aumovio.com, netdev@vger.kernel.org,
linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com,
linux-kernel@vger.kernel.org, maoyi.xie@ntu.edu.sg
Subject: Re: [PATCH net v4] rds: filter RDS_INFO_* getsockopt by caller's netns
Date: Mon, 18 May 2026 11:15:32 +0100 [thread overview]
Message-ID: <20260518101531.473574-2-horms@kernel.org> (raw)
In-Reply-To: <20260513143904.2497520-1-maoyi.xie@ntu.edu.sg>
From: 'Simon Horman' <horms@kernel.org>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
rds: filter RDS_INFO_* getsockopt by caller's netns
This commit adds network namespace filtering to the RDS_INFO_* getsockopt
handlers to restrict visibility of sockets and connections. It removes global
counters and replaces them with a per-netns count gathered from a first pass
over the lists.
> diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c
> index 76f625986a7f2..ace52d3ce0597 100644
> --- a/net/rds/af_rds.c
> +++ b/net/rds/af_rds.c
[ ... ]
> @@ -806,6 +811,7 @@ static void rds_sock_info(struct socket *sock, unsigned int len,
> struct rds_info_iterator *iter,
> struct rds_info_lengths *lens)
> {
> + struct net *net = sock_net(sock->sk);
> struct rds_info_socket sinfo;
> unsigned int cnt = 0;
> struct rds_sock *rs;
> @@ -814,12 +820,22 @@ static void rds_sock_info(struct socket *sock, unsigned int len,
>
> spin_lock_bh(&rds_sock_lock);
>
> - if (len < rds_sock_count) {
> - cnt = rds_sock_count;
> - goto out;
> + /* First pass: count entries visible in the caller's netns. */
> + list_for_each_entry(rs, &rds_sock_list, rs_item) {
> + if (!net_eq(sock_net(rds_rs_to_sk(rs)), net))
> + continue;
> + if (!ipv6_addr_v4mapped(&rs->rs_bound_addr))
> + continue;
> + cnt++;
> }
>
> + if (len < cnt)
> + goto out;
> +
> list_for_each_entry(rs, &rds_sock_list, rs_item) {
> + /* Only show sockets in the caller's netns. */
> + if (!net_eq(sock_net(rds_rs_to_sk(rs)), net))
> + continue;
> /* This option only supports IPv4 sockets. */
> if (!ipv6_addr_v4mapped(&rs->rs_bound_addr))
> continue;
> @@ -832,7 +848,6 @@ static void rds_sock_info(struct socket *sock, unsigned int len,
> sinfo.inum = sock_i_ino(rds_rs_to_sk(rs));
>
> rds_info_copy(iter, &sinfo, sizeof(sinfo));
Could a concurrent bind cause this second pass to copy more items than we
counted in the first pass?
If rds_bind() updates rs_bound_addr concurrently without holding
rds_sock_lock, an unbound socket could be skipped during the first pass but
match in the second pass.
Because the second pass does not limit the number of copied items to the
length checked after the first pass, rds_info_copy() could be called more
times than the user-supplied buffer can handle.
For example, if a caller provides a length of 0, the iter pages array may
be NULL. If the first pass computes cnt = 0, the length check (len < cnt)
evaluates to false and the second pass executes. If a socket is bound
concurrently and matches the second pass, could this lead to an out-of-bounds
read or a crash when rds_info_copy() dereferences iter->pages?
next prev parent reply other threads:[~2026-05-18 10:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 14:39 [PATCH net v4] rds: filter RDS_INFO_* getsockopt by caller's netns Maoyi Xie
2026-05-18 10:15 ` Simon Horman [this message]
2026-05-18 17:33 ` Maoyi Xie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260518101531.473574-2-horms@kernel.org \
--to=horms@kernel.org \
--cc=achender@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=maoyi.xie@ntu.edu.sg \
--cc=maoyixie.tju@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=praveen.kakkolangara@aumovio.com \
--cc=rds-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox