]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
ktrace: Handle uio_resid underflow via MSG_TRUNC
authorMark Johnston <markj@FreeBSD.org>
Mon, 16 Oct 2023 20:11:55 +0000 (16:11 -0400)
committerMark Johnston <markj@FreeBSD.org>
Tue, 17 Oct 2023 13:12:19 +0000 (09:12 -0400)
commit761ae1ce798add862d78728cc5ac5240ce7db779
tree962974929ae7b4174e21088511e3aaa7b1980da4
parenta37e484d049758c70f2d61be0d28a115b6f2f01e
ktrace: Handle uio_resid underflow via MSG_TRUNC

When recvmsg(2) is used with MSG_TRUNC on an atomic socket type (DGRAM
or SEQPACKET), soreceive_generic() and uipc_peek_dgram() may
intentionally underflow uio_resid so that userspace can find out how
many bytes it should have asked for.

If this happens, and KTR_GENIO is enabled, ktrgenio() will attempt to
copy in beyond the end of the output buffer's iovec.  In general this
will silently cause the ktrace operation to fail since it'll result in
EFAULT from uiomove().  Let's be more careful and make sure not to try
and copy more bytes than we have.

Fixes: be1f485d7d6b ("sockets: add MSG_TRUNC flag handling for recvfrom()/recvmsg().")
Reported by: syzbot+30b4bb0c0bc0f53ac198@syzkaller.appspotmail.com
Reviewed by: kib
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42099
sys/kern/uipc_syscalls.c