diff mbox series

netlink: fixup regression in RTM_GETADDR

Message ID 20181230181549.25733-1-baloo@gandi.net
State Superseded, archived
Delegated to: David Miller
Headers show
Series netlink: fixup regression in RTM_GETADDR | expand

Commit Message

Arthur Gautier Dec. 30, 2018, 6:15 p.m. UTC
From: Arthur Gautier <baloo@gandi.net>

This commit fixes a regression in AF_INET/RTM_GETADDR and
AF_INET6/RTM_GETADDR. The AF_UNSPEC/RTM_GETADDR was not affected by this as
rtnl_dump_all would just hide the errno.

Before this commit, the kernel would stop dumping addresses once the first
skb was full and end the stream with NLMSG_DONE(-EMSGSIZE). The callback
should be kept alive as the userspace is expected to call back with a new
empty skb.

Fixes: d7e38611b81e ("net/ipv4: Put target net when address dump fails due to bad attributes")
Fixes: 242afaa6968c ("net/ipv6: Put target net when address dump fails due to bad attributes")

Cc: David Ahern <dsahern@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Signed-off-by: Arthur Gautier <baloo@gandi.net>
---
 net/netlink/af_netlink.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

David Ahern Dec. 31, 2018, 1:48 a.m. UTC | #1
On 12/30/18 11:15 AM, baloo@gandi.net wrote:
> From: Arthur Gautier <baloo@gandi.net>
> 
> This commit fixes a regression in AF_INET/RTM_GETADDR and
> AF_INET6/RTM_GETADDR. The AF_UNSPEC/RTM_GETADDR was not affected by this as
> rtnl_dump_all would just hide the errno.
> 
> Before this commit, the kernel would stop dumping addresses once the first
> skb was full and end the stream with NLMSG_DONE(-EMSGSIZE). The callback
> should be kept alive as the userspace is expected to call back with a new
> empty skb.
> 
> Fixes: d7e38611b81e ("net/ipv4: Put target net when address dump fails due to bad attributes")
> Fixes: 242afaa6968c ("net/ipv6: Put target net when address dump fails due to bad attributes")
> 
> Cc: David Ahern <dsahern@gmail.com>
> Cc: "David S . Miller" <davem@davemloft.net>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Arthur Gautier <baloo@gandi.net>
> ---
>  net/netlink/af_netlink.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
> index 3c023d6120f65..0a48bca246bc4 100644
> --- a/net/netlink/af_netlink.c
> +++ b/net/netlink/af_netlink.c
> @@ -2245,6 +2245,15 @@ static int netlink_dump(struct sock *sk)
>  		cb->extack = NULL;
>  	}
>  
> +	/* Should the dump method run out of space, we have to
> +	 * keep the dumper running until completion.
> +	 * Just ignore the error, userspace should call back with a
> +	 * new skb until dump is complete
> +	 */
> +	if (nlk->dump_done_errno == -EMSGSIZE) {
> +		nlk->dump_done_errno = skb->len;
> +	}
> +
>  	if (nlk->dump_done_errno > 0 ||
>  	    skb_tailroom(skb) < nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
>  		mutex_unlock(nlk->cb_mutex);
> 

This should be in inet_dump_ifaddr and inet6_dump_addr. Instead of:
	return err < 0 ? err : skb->len;

it should be
	return skb->len ? : err;
diff mbox series

Patch

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 3c023d6120f65..0a48bca246bc4 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2245,6 +2245,15 @@  static int netlink_dump(struct sock *sk)
 		cb->extack = NULL;
 	}
 
+	/* Should the dump method run out of space, we have to
+	 * keep the dumper running until completion.
+	 * Just ignore the error, userspace should call back with a
+	 * new skb until dump is complete
+	 */
+	if (nlk->dump_done_errno == -EMSGSIZE) {
+		nlk->dump_done_errno = skb->len;
+	}
+
 	if (nlk->dump_done_errno > 0 ||
 	    skb_tailroom(skb) < nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
 		mutex_unlock(nlk->cb_mutex);