From: Paolo Abeni <pabeni@redhat.com>
To: Matthieu Baerts <matttbe@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [PATCH mptcp-next] mptcp: pm: reduce entries iterations on connect
Date: Thu, 25 Jul 2024 16:03:19 +0200 [thread overview]
Message-ID: <587e096f-0e76-40fd-9220-6d8dd2930838@redhat.com> (raw)
In-Reply-To: <4f926139-2872-4869-8ece-fd72cec3c83a@kernel.org>
On 7/22/24 17:55, Matthieu Baerts wrote:
> On 22/07/2024 17:14, Paolo Abeni wrote:
>> On 7/19/24 16:26, Matthieu Baerts (NGI0) wrote:
>>> diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
>>> index 1b0e1617e90a..9fed7c92e52b 100644
>>> --- a/net/mptcp/pm_netlink.c
>>> +++ b/net/mptcp/pm_netlink.c
>>> @@ -633,8 +633,9 @@ static void mptcp_pm_nl_subflow_established(struct
>>> mptcp_sock *msk)
>>> */
>>> static unsigned int fill_local_addresses_vec(struct mptcp_sock *msk,
>>> struct mptcp_addr_info *remote,
>>> - struct mptcp_addr_info *addrs)
>>> + struct mptcp_pm_addr_entry *entries)
>>> {
>>> + struct mptcp_pm_addr_entry new_entry;
>>> struct sock *sk = (struct sock *)msk;
>>> struct mptcp_pm_addr_entry *entry;
>>> struct mptcp_addr_info mpc_addr;
>>> @@ -655,14 +656,14 @@ static unsigned int
>>> fill_local_addresses_vec(struct mptcp_sock *msk,
>>> continue;
>>> if (msk->pm.subflows < subflows_max) {
>>> - msk->pm.subflows++;
>>> - addrs[i] = entry->addr;
>>> + memcpy(&new_entry, entry, sizeof(new_entry));
>>> /* Special case for ID0: set the correct endpoint */
>>> if (mptcp_addresses_equal(&entry->addr, &mpc_addr,
>>> entry->addr.port))
>>> - addrs[i].id = 0;
>>> + new_entry.addr.id = 0;
>>> - i++;
>>> + msk->pm.subflows++;
>>> + entries[i++] = new_entry;
>>
>> 'new_entry' is escaping the rcu protected section, dereferencing
>> 'entries' after the rcu unlock below could cause UaF.
>>
>> Note, AFAICS we already have a similar problem in select_local_address().
>
> Good catch!
>
> And with select_signal_address() since the beginning as well, no?
Yep.
>> One possibility would be to do a deep copy of mptcp_pm_addr_entry, but
>> that will waste a lot of memory on the stack. What about to copy the id
>> separately?
>
> Is it not what is already done here? Before, only 'entry->addr' was
> copied, now the whole 'entry' is duplicated with the 'memcpy()' call
> above. Is it not enough?
Yes, it is. I got lost into the incremental diffs.
> I'm doing that because we also need the 'flags' and 'ifindex' info from
> this structure -- which has 3 additional pointers we don't need, but I
> thought it was OK to re-use it -- on top of the address we had before.
>
> BTW, I just realised the copy is done twice (entry -> new_entry ->
> entries[i]). Same below. I can fix that.
Yes, would be better to avoid multiple copies.
The additional memory user is a bit concerning for the
fill_local_addresses_vec() case, where the total amount of data on the
stack grows from 192 (already quite big) to 384 (quite concerning)...
Paolo
next prev parent reply other threads:[~2024-07-25 14:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 14:26 [PATCH mptcp-next] mptcp: pm: reduce entries iterations on connect Matthieu Baerts (NGI0)
2024-07-19 15:20 ` MPTCP CI
2024-07-22 15:14 ` Paolo Abeni
2024-07-22 15:55 ` Matthieu Baerts
2024-07-25 14:03 ` Paolo Abeni [this message]
2024-07-26 9:46 ` Matthieu Baerts
2024-07-26 11:05 ` Matthieu Baerts
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=587e096f-0e76-40fd-9220-6d8dd2930838@redhat.com \
--to=pabeni@redhat.com \
--cc=matttbe@kernel.org \
--cc=mptcp@lists.linux.dev \
/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 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.