MPTCP Linux Development
 help / color / mirror / Atom feed
From: gang.yan@linux.dev
To: mptcp@lists.linux.dev
Cc: "Gang Yan" <yangang@kylinos.cn>
Subject: Re: [PATCH mptcp-net] selftests: mptcp: fix an UAF in mptcp_connect.c
Date: Fri, 14 Aug 2026 06:42:33 +0000	[thread overview]
Message-ID: <0ce89b909d078e40f8f560255ad44ae8e2cfff00@linux.dev> (raw)
In-Reply-To: <20260814050625.80231-1-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);
        if (cfg_input)
                close(fd_in);

If you think it's OK, I can send v2 immediately.

Thanks
Gang

  parent reply	other threads:[~2026-08-14  6:42 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 [this message]
2026-08-14  8:54   ` Matthieu Baerts
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=0ce89b909d078e40f8f560255ad44ae8e2cfff00@linux.dev \
    --to=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