[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210809153251.4c51c3cd@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com>
Date: Mon, 9 Aug 2021 15:32:51 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Wen Yang <wenyang@...ux.alibaba.com>
Cc: davem@...emloft.net, David Ahern <dsahern@...nel.org>,
Hideaki YOSHIFUJI <yoshfuji@...ux-ipv6.org>,
Baoyou Xie <baoyou.xie@...baba-inc.com>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ipv4: return early for possible invalid uaddr
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.
> 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.
> 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?
> + 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)
Powered by blists - more mailing lists