public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] netlink: trim skb to exact size to avoid MSG_TRUNC
@ 2015-10-13  1:15 Ronen Arad
  2015-10-13  8:56 ` Thomas Graf
  2015-10-15  8:55 ` [PATCH net-next v2] netlink: Trim skb to alloc " Ronen Arad
  0 siblings, 2 replies; 7+ messages in thread
From: Ronen Arad @ 2015-10-13  1:15 UTC (permalink / raw)
  To: netdev; +Cc: Ronen Arad

The available room in the skb allocated in netlink_dump for iproute2
show requests (e.g. "ip link [show]", "bridge [-c] vlan show") should
be trimmed to the exact size requested in order to avoid MSG_TRUNC flag
set in netlink_recvmg.
This was handled properly for small skb allocated when no interface has
many VLANs configured. This patch applies the same logic to larger skbs
which are allocated using the calculated min_dump_alloc size.

Signed-off-by: Ronen Arad <ronen.arad@intel.com>
---
 net/netlink/af_netlink.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 8f060d7..d628253 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2817,9 +2817,13 @@ static int netlink_dump(struct sock *sk)
 			skb_reserve(skb, skb_tailroom(skb) -
 					 nlk->max_recvmsg_len);
 	}
-	if (!skb)
+	if (!skb) {
 		skb = netlink_alloc_skb(sk, alloc_size, nlk->portid,
 					GFP_KERNEL);
+		/* available room should be exact amount to avoid MSG_TRUNC */
+		if (skb)
+			skb_reserve(skb, skb_tailroom(skb) - alloc_size);
+	}
 	if (!skb)
 		goto errout_skb;
 	netlink_skb_set_owner_r(skb, sk);
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-19  2:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-13  1:15 [PATCH] netlink: trim skb to exact size to avoid MSG_TRUNC Ronen Arad
2015-10-13  8:56 ` Thomas Graf
2015-10-13 17:52   ` Arad, Ronen
2015-10-14  7:44     ` Thomas Graf
2015-10-15  6:41       ` Arad, Ronen
2015-10-15  8:55 ` [PATCH net-next v2] netlink: Trim skb to alloc " Ronen Arad
2015-10-19  2:33   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox