Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[NETLINK]: Limit NLMSG_GOODSIZE to 8K.

Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

David S. Miller and committed by
David S. Miller
fc910a27 ca043569

+14 -5
+9 -2
include/linux/netlink.h
··· 171 171 172 172 /* 173 173 * skb should fit one page. This choice is good for headerless malloc. 174 + * But we should limit to 8K so that userspace does not have to 175 + * use enormous buffer sizes on recvmsg() calls just to avoid 176 + * MSG_TRUNC when PAGE_SIZE is very large. 174 177 */ 175 - #define NLMSG_GOODORDER 0 176 - #define NLMSG_GOODSIZE (SKB_MAX_ORDER(0, NLMSG_GOODORDER)) 178 + #if PAGE_SIZE < 8192UL 179 + #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE) 180 + #else 181 + #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL) 182 + #endif 183 + 177 184 #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN) 178 185 179 186
+5 -3
include/linux/skbuff.h
··· 39 39 40 40 #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ 41 41 ~(SMP_CACHE_BYTES - 1)) 42 - #define SKB_MAX_ORDER(X, ORDER) (((PAGE_SIZE << (ORDER)) - (X) - \ 43 - sizeof(struct skb_shared_info)) & \ 44 - ~(SMP_CACHE_BYTES - 1)) 42 + #define SKB_WITH_OVERHEAD(X) \ 43 + (((X) - sizeof(struct skb_shared_info)) & \ 44 + ~(SMP_CACHE_BYTES - 1)) 45 + #define SKB_MAX_ORDER(X, ORDER) \ 46 + SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) 45 47 #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) 46 48 #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) 47 49