From: gang.yan@linux.dev
To: "Paolo Abeni" <pabeni@redhat.com>, 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 14:20:12 +0000 [thread overview]
Message-ID: <cbd1c616b7ade068ce1d432270f27ff18f86520c@linux.dev> (raw)
In-Reply-To: <a4d66633-1340-4a56-9dd2-18cdeff7629e@redhat.com>
August 14, 2026 at 6:50 PM, "Paolo Abeni" <pabeni@redhat.com mailto:pabeni@redhat.com?to=%22Paolo%20Abeni%22%20%3Cpabeni%40redhat.com%3E > wrote:
>
> Hi,
>
> On 8/14/26 8:42 AM, gang.yan@linux.dev wrote:
>
> >
> > 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.
> >
> I'm sorry for being in late.
>
Hi Paolo,
So nice to get your reply.
> This is in a better direction but still will be not fully correct:
> freeaddrinfo() must be called on the argument returned by getaddrinfo()
> - in this case: `addr`.
>
> Otherwise some addresses will not be freed.
>
> Since sock_connect_mptcp() is invoked only once per program execution,
> and not-freed memory will _not_ be leaked at process exit time, I think
> the easier solution is to remove the:
>
> freeaddrinfo(addr);
Sounds great!
>
> statement, adding a comment alike:
>
> /* All the allocated memory is released at exit() time, this
> * is executed only once and ownership of a single address has
> * to be transferred to the caller. Keep it simple and avoid
> * later freeaddrinfo() entirely.
> */
I've just send the v2 and using AI to simplify the comment —— hope you
don’t mind.
Thanks
Gang
> xgetaddrinfo(listenaddr, port, &hints, &addr);
>
> /P
>
prev parent reply other threads:[~2026-08-14 14:20 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
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 [this message]
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=cbd1c616b7ade068ce1d432270f27ff18f86520c@linux.dev \
--to=gang.yan@linux.dev \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--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