From: Wen Yang <wenyang@linux.alibaba.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, David Ahern <dsahern@kernel.org>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
Baoyou Xie <baoyou.xie@alibaba-inc.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ipv4: return early for possible invalid uaddr
Date: Wed, 11 Aug 2021 11:41:15 +0800 [thread overview]
Message-ID: <72dd5ee4-d7f3-576c-c7b9-3f8f4980faf3@linux.alibaba.com> (raw)
In-Reply-To: <20210809153251.4c51c3cd@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
在 2021/8/10 上午6:32, Jakub Kicinski 写道:
> On Sun, 8 Aug 2021 01:19:38 +0800 Wen Yang wrote:
>> The inet_dgram_connect() first calls inet_autobind() to select an
>> ephemeral port, then checks uaddr in udp_pre_connect() or
>> __ip4_datagram_connect(), but the port is not released until the socket
>> is closed.
>>
>> We should return early for invalid uaddr to improve performance and
>> simplify the code a bit,
>
> The performance improvement would be if the benchmark is calling
> connect with invalid arguments? That seems like an extremely rare
> scenario in real life.
>
Thanks for your comments.
On the one hand, it is the performance impact, but we also found that it
may cause DoS: simulate a scenario where udp connect is frequently
performed (illegal addrlen, and the socket is not closed), the local
ports will be exhausted quickly.
>> and also switch from a mix of tabs and spaces to just tabs.
>
> Please never mix unrelated whitespace cleanup into patches making real
> code changes.
>
OK.
>> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
>> index 5464818..97b6fc4 100644
>> --- a/net/ipv4/af_inet.c
>> +++ b/net/ipv4/af_inet.c
>> @@ -569,6 +569,11 @@ int inet_dgram_connect(struct socket *sock, struct sockaddr *uaddr,
>> if (uaddr->sa_family == AF_UNSPEC)
>> return sk->sk_prot->disconnect(sk, flags);
>>
>> + if (uaddr->sa_family != AF_INET)
>> + return -EAFNOSUPPORT;
>
> And what about IPv6 which also calls this function?
>
Sorry that currently only ipv4 has been modified, we will continue to
improve, and the v2 patch will be submitted later, thank you.
--
Best wishes,
Wen
>> + if (addr_len < sizeof(struct sockaddr_in))
>> + return -EINVAL;
>> +
>> if (BPF_CGROUP_PRE_CONNECT_ENABLED(sk)) {
>> err = sk->sk_prot->pre_connect(sk, uaddr, addr_len);
>> if (err)
prev parent reply other threads:[~2021-08-11 3:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-07 17:19 Wen Yang
2021-08-09 22:32 ` Jakub Kicinski
2021-08-11 3:41 ` Wen Yang [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=72dd5ee4-d7f3-576c-c7b9-3f8f4980faf3@linux.alibaba.com \
--to=wenyang@linux.alibaba.com \
--cc=baoyou.xie@alibaba-inc.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/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
all inboxes | Powered by JetHome®