MPTCP Linux Development
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: gang.yan@linux.dev
Cc: mptcp@lists.linux.dev, Gang Yan <yangang@kylinos.cn>
Subject: Re: [PATCH mptcp-net] selftests: mptcp: fix an UAF in mptcp_connect.c
Date: Fri, 14 Aug 2026 10:54:55 +0200	[thread overview]
Message-ID: <90d727ed-9c4c-4107-a283-1e9a0245d09b@kernel.org> (raw)
In-Reply-To: <0ce89b909d078e40f8f560255ad44ae8e2cfff00@linux.dev>

14 Aug 2026 08:42:38 gang.yan@linux.dev:

> August 14, 2026 at 1:06 PM, "Gang Yan" <gang.yan@linux.dev mailto:gang.yan@linux.dev?to=%22Gang%20Yan%22%20%3Cgang.yan%40linux.dev%3E > wrote:
>
>
>>
>> From: Gang Yan <yangang@kylinos.cn>
>>
>> At the end of 'sock_connect_mptcp()', it calls 'freeaddrinfo(addr)',
>> the 'peer' pointer (which points into 'addr') remains. Later, the main
>> loop uses this peer pointer for reconnection attempts. If the memory has
>> been freed and reused, the address data could be overwritten, resulting
>> in an invalid remote address.
>>
>> This patch removes the '**peer' out-parameter entirely and adds a
>> sock_reconnect() helper that resolves the address and connects in a
>> self-contained scope, so no pointer to freed memory escapes.
>> Also prints the reconnect destination address on stderr as suggested by
>> Paolo.
>>
>
> Hi Matt,
>
> Sorry for this, after reviewing sashiko's comment, I think this modification
> below should be better:
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> index ea4cb6c1bd5e..c81ec4400bef 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
> @@ -421,7 +421,8 @@ static int sock_connect_mptcp(const char * const remoteaddr,
>                 sock = -1;
>         }
>
> -       freeaddrinfo(addr);
> +       if (sock == -1)
> +               freeaddrinfo(addr);
>         if (sock != -1)
>                 SOCK_TEST_TCPULP(sock, proto);
>         return sock;
> @@ -1424,6 +1425,7 @@ int main_loop(void)
>         }
>
> out:
> +       freeaddrinfo(peer);

This assumes peer == addr. It is certainly the case but it looks wrong,
and I guess sashiko will complain like it did here.

We could add something on the commit message to say that it is always an IP address that is given, but maybe we should also just
handle that correctly: either peer here is not a pointer, and the content
is copied, or you pass &addr to sock_connect_mptcp, and you do the free here.

WDYT?

Cheers,
Matt


  reply	other threads:[~2026-08-14  8:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  5:06 [PATCH mptcp-net] selftests: mptcp: fix an UAF in mptcp_connect.c Gang Yan
2026-08-14  5:14 ` sashiko-bot
2026-08-14  6:18 ` MPTCP CI
2026-08-14  6:42 ` gang.yan
2026-08-14  8:54   ` Matthieu Baerts [this message]
2026-08-14  9:20     ` gang.yan
2026-08-14  9:35       ` Matthieu Baerts
2026-08-14 10:50   ` Paolo Abeni
2026-08-14 14:20     ` gang.yan

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=90d727ed-9c4c-4107-a283-1e9a0245d09b@kernel.org \
    --to=matttbe@kernel.org \
    --cc=gang.yan@linux.dev \
    --cc=mptcp@lists.linux.dev \
    --cc=yangang@kylinos.cn \
    /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