All of lore.kernel.org
 help / color / mirror / Atom feed
* recvmmsg/sendmmsg result types inconsistent, integer overflows?
@ 2014-06-11  4:12 Rich Felker
  2014-06-11  5:08 ` Michael Kerrisk
  2014-06-11  5:24 ` Mike Galbraith
  0 siblings, 2 replies; 8+ messages in thread
From: Rich Felker @ 2014-06-11  4:12 UTC (permalink / raw)
  To: linux-kernel

While looking to add support for the recvmmsg and sendmmsg syscalls in
musl libc, I ran into some disturbing findings on the kernel side. In
the struct mmsghdr, the field where the result for each message is
stored has type int, which is inconsistent with the return type
ssize_t of recvmsg/sendmsg. So I tried to track down what happens when
the result is or would be larger than 2GB, and quickly found an
explanation for why the type in the structure was defined wrong:
internally, the kernel uses int as the return type for revcmsg and
sendmsg. Oops.

A bit more RTFS'ing brought me to tcp_sendmsg in net/ipv4/tcp.c (I
figured let's look at a stream-based protocol, since datagrams can
likely never be that big for any existing protocol), and as far as I
can tell, it's haphazardly mixing int and size_t with no checks for
overflows. I looked for anywhere the kernel might try to verify before
starting that the sum of the lengths of all the iovec components
doesn't overflow INT_MAX or even SIZE_MAX, but didn't find any such
checks.

Is there some magic that makes this all safe, or is this a big mess of
possibly-security-relevant bugs?

Rich

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

end of thread, other threads:[~2014-06-12 18:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-11  4:12 recvmmsg/sendmmsg result types inconsistent, integer overflows? Rich Felker
2014-06-11  5:08 ` Michael Kerrisk
2014-06-11  5:24 ` Mike Galbraith
2014-06-11  5:50   ` Eric Dumazet
2014-06-11 15:15     ` Rich Felker
2014-06-12  6:04       ` Michael Kerrisk (man-pages)
2014-06-12 14:13         ` Rich Felker
2014-06-12 18:53           ` Michael Kerrisk (man-pages)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.