zfs/cmd/zstream
Richard Yao 73968defdd
Reject streams that set ->drr_payloadlen to unreasonably large values
In the zstream code, Coverity reported:

"The argument could be controlled by an attacker, who could invoke the
function with arbitrary values (for example, a very high or negative
buffer size)."

It did not report this in the kernel. This is likely because the
userspace code stored this in an int before passing it into the
allocator, while the kernel code stored it in a uint32_t.

However, this did reveal a potentially real problem. On 32-bit systems
and systems with only 4GB of physical memory or less in general, it is
possible to pass a large enough value that the system will hang. Even
worse, on Linux systems, the kernel memory allocator is not able to
support allocations up to the maximum 4GB allocation size that this
allows.

This had already been limited in userspace to 64MB by
`ZFS_SENDRECV_MAX_NVLIST`, but we need a hard limit in the kernel to
protect systems. After some discussion, we settle on 256MB as a hard
upper limit. Attempting to receive a stream that requires more memory
than that will result in E2BIG being returned to user space.

Reported-by: Coverity (CID-1529836)
Reported-by: Coverity (CID-1529837)
Reported-by: Coverity (CID-1529838)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14285
2023-01-23 13:16:22 -08:00
..
Makefile.am Add ability to recompress send streams with new compression algorithm 2022-11-10 15:23:46 -08:00
zstream.c Add ability to recompress send streams with new compression algorithm 2022-11-10 15:23:46 -08:00
zstream.h Add ability to recompress send streams with new compression algorithm 2022-11-10 15:23:46 -08:00
zstream_decompress.c Reject streams that set ->drr_payloadlen to unreasonably large values 2023-01-23 13:16:22 -08:00
zstream_dump.c Fix declarations of non-global variables 2022-10-18 11:05:32 -07:00
zstream_recompress.c Reject streams that set ->drr_payloadlen to unreasonably large values 2023-01-23 13:16:22 -08:00
zstream_redup.c Reject streams that set ->drr_payloadlen to unreasonably large values 2023-01-23 13:16:22 -08:00
zstream_token.c Fix userland dereference NULL return value bugs 2022-09-30 17:02:57 -07:00