netlink: handle EMSGSIZE errors in the core
authorJakub Kicinski <kuba@kernel.org>
Sun, 3 Mar 2024 05:24:06 +0000 (21:24 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 6 Mar 2024 08:07:44 +0000 (08:07 +0000)
commitb5a899154aa94cc573db3ae1f61dabe7bfe8b579
treea21b6298b73942fc0409d196eab419893671738f
parente3350ba4a5b7573d4e14ee1dff8c414646435a04
netlink: handle EMSGSIZE errors in the core

Eric points out that our current suggested way of handling
EMSGSIZE errors ((err == -EMSGSIZE) ? skb->len : err) will
break if we didn't fit even a single object into the buffer
provided by the user. This should not happen for well behaved
applications, but we can fix that, and free netlink families
from dealing with that completely by moving error handling
into the core.

Let's assume from now on that all EMSGSIZE errors in dumps are
because we run out of skb space. Families can now propagate
the error nla_put_*() etc generated and not worry about any
return value magic. If some family really wants to send EMSGSIZE
to user space, assuming it generates the same error on the next
dump iteration the skb->len should be 0, and user space should
still see the EMSGSIZE.

This should simplify families and prevent mistakes in return
values which lead to DONE being forced into a separate recv()
call as discovered by Ido some time ago.

Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/af_netlink.c