* [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message.
@ 2016-11-14 22:20 dwilder
[not found] ` <e9409957290af5249750afa0f10de3a6-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: dwilder @ 2016-11-14 22:20 UTC (permalink / raw)
To: mtk.manpages; +Cc: linux-man, netdev
The example code in netlink(7) (for reading netlink message) suggests
using
a 4k read buffer with recvmsg. This can cause truncated messages on
systems
using a page size is >4096. Please see:
linux/include/linux/netlink.h (in the kernel source)
<snip>
/*
* skb should fit one page. This choice is good for headerless
malloc.
* But we should limit to 8K so that userspace does not have to
* use enormous buffer sizes on recvmsg() calls just to avoid
* MSG_TRUNC when PAGE_SIZE is very large.
*/
#if PAGE_SIZE < 8192UL
#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE)
#else
#define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL)
#endif
#define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
<snip>
I was troubleshooting some up-stream code on a ppc64le system
(page:size of 64k) This code had duplicated the example from netlink(7)
and
was using a 4k buffer. On x86-64 with a 4k page size this is not a
problem,
however on the 64k page system some messages were truncated. Using an
8k buffer
as implied in netlink.h prevents problems with any page size.
Lets change the example so others don't propagate the problem further.
Signed-off-by David Wilder <dwilder@us.ibm.com>
--- man7/netlink.7.orig 2016-11-14 13:30:36.522101156 -0800
+++ man7/netlink.7 2016-11-14 13:30:51.002086354 -0800
@@ -511,7 +511,7 @@
.in +4n
.nf
int len;
-char buf[4096];
+char buf[8192];
struct iovec iov = { buf, sizeof(buf) };
struct sockaddr_nl sa;
struct msghdr msg;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message.
[not found] ` <e9409957290af5249750afa0f10de3a6-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
@ 2016-11-14 22:36 ` Rick Jones
2017-08-16 0:40 ` Michael Kerrisk (man-pages)
2017-08-16 0:37 ` Michael Kerrisk (man-pages)
1 sibling, 1 reply; 4+ messages in thread
From: Rick Jones @ 2016-11-14 22:36 UTC (permalink / raw)
To: dwilder, mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA
> Lets change the example so others don't propagate the problem further.
>
> Signed-off-by David Wilder <dwilder-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
>
> --- man7/netlink.7.orig 2016-11-14 13:30:36.522101156 -0800
> +++ man7/netlink.7 2016-11-14 13:30:51.002086354 -0800
> @@ -511,7 +511,7 @@
> .in +4n
> .nf
> int len;
> -char buf[4096];
> +char buf[8192];
Since there doesn't seem to be a define one could use in the user space
linux/netlink.h (?), but there are comments in the example code in the
manpage, how about also including a brief comment to the effect that
using 8192 bytes will avoid message truncation problems on platforms
with a large PAGE_SIZE?
/* avoid msg truncation on > 4096 byte PAGE_SIZE platforms */
or something like that.
rick jones
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message.
[not found] ` <e9409957290af5249750afa0f10de3a6-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-11-14 22:36 ` Rick Jones
@ 2017-08-16 0:37 ` Michael Kerrisk (man-pages)
1 sibling, 0 replies; 4+ messages in thread
From: Michael Kerrisk (man-pages) @ 2017-08-16 0:37 UTC (permalink / raw)
To: dwilder
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
linux-man-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA
On 11/14/2016 11:20 PM, dwilder wrote:
> The example code in netlink(7) (for reading netlink message) suggests
> using
> a 4k read buffer with recvmsg. This can cause truncated messages on
> systems
> using a page size is >4096. Please see:
> linux/include/linux/netlink.h (in the kernel source)
>
> <snip>
> /*
> * skb should fit one page. This choice is good for headerless
> malloc.
> * But we should limit to 8K so that userspace does not have to
> * use enormous buffer sizes on recvmsg() calls just to avoid
> * MSG_TRUNC when PAGE_SIZE is very large.
> */
> #if PAGE_SIZE < 8192UL
> #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE)
> #else
> #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL)
> #endif
>
> #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
> <snip>
>
> I was troubleshooting some up-stream code on a ppc64le system
> (page:size of 64k) This code had duplicated the example from netlink(7)
> and
> was using a 4k buffer. On x86-64 with a 4k page size this is not a
> problem,
> however on the 64k page system some messages were truncated. Using an
> 8k buffer
> as implied in netlink.h prevents problems with any page size.
>
> Lets change the example so others don't propagate the problem further.
>
> Signed-off-by David Wilder <dwilder-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Thanks, David. Patch applied.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message.
2016-11-14 22:36 ` Rick Jones
@ 2017-08-16 0:40 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 4+ messages in thread
From: Michael Kerrisk (man-pages) @ 2017-08-16 0:40 UTC (permalink / raw)
To: Rick Jones, dwilder; +Cc: mtk.manpages, linux-man, netdev
On 11/14/2016 11:36 PM, Rick Jones wrote:
>> Lets change the example so others don't propagate the problem further.
>>
>> Signed-off-by David Wilder <dwilder@us.ibm.com>
>>
>> --- man7/netlink.7.orig 2016-11-14 13:30:36.522101156 -0800
>> +++ man7/netlink.7 2016-11-14 13:30:51.002086354 -0800
>> @@ -511,7 +511,7 @@
>> .in +4n
>> .nf
>> int len;
>> -char buf[4096];
>> +char buf[8192];
>
> Since there doesn't seem to be a define one could use in the user space
> linux/netlink.h (?), but there are comments in the example code in the
> manpage, how about also including a brief comment to the effect that
> using 8192 bytes will avoid message truncation problems on platforms
> with a large PAGE_SIZE?
>
> /* avoid msg truncation on > 4096 byte PAGE_SIZE platforms */
>
> or something like that.
Thanks for the suggestion, Rick. Done!
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-08-16 0:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-14 22:20 [patch] netlink.7: srcfix Change buffer size in example code about reading netlink message dwilder
[not found] ` <e9409957290af5249750afa0f10de3a6-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2016-11-14 22:36 ` Rick Jones
2017-08-16 0:40 ` Michael Kerrisk (man-pages)
2017-08-16 0:37 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).