Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upSECURITY: malloc((uint64_t)length + 1) is unsafe, especially on 32-bit systems #273
Comments
This comment has been minimized.
This comment has been minimized.
|
Thanks for reporting. What fix do you propose? |
This comment has been minimized.
This comment has been minimized.
|
One more question @solardiz: How did you get to know that a uint_64t, when availabale, is actually 32 bits on 32-bit systems? |
This comment has been minimized.
This comment has been minimized.
|
Considering that (part of) the fix should be sanity-limiting the allocation size (since it's not great to let the remote system cause us to allocate almost 4 GiB), we can do just that and with a sane limit (applied prior to any typecasts or math) it'll also prevent 32-bit integer overflows and thus be a complete fix. I don't currently have time to propose a specific patch. Maybe @PaulCher will, as it's his incomplete fixes that we'll be fixing now? I sure hope |
This comment has been minimized.
This comment has been minimized.
|
My bad, I completely forgot about 32-bit platforms... Actually before proposing the patch I took a glance at how previous integer overflow issues were fixed in libvnc, so there must be even more. Well, I looked up how they deal with this kind of problems in other VNC projects. In ultravnc every temporary allocations are limited to 100MB (function Probably for things like "reason of connection loss" more strict limitations can be enforced. As @solardiz stated in another issue Qemu is using limit of 1MB for cut text buffer. |
This comment has been minimized.
This comment has been minimized.
|
@solardiz thanks for the explanation, makes sense! |
This comment has been minimized.
This comment has been minimized.
|
I think this issue isn't fully fixed yet. Please re-open. There are more instances of the vulnerable pattern in the tree:
Also, while 045a044 does avoid the integer overflow in The above list of remaining issues is probably non-exhaustive. |
This comment has been minimized.
This comment has been minimized.
|
Regarding the rfbProcessFileTransferReadBuffer(), what's the reasonable file size? I can imagine people could want to transfer 4-GiB files (even larger but that's not supported by the protocol). Even if we choose a smaller limit, a user can connect multiple times, ask for a large file transfer and that will exhaust the physical memory. We could implement some per-user limit, but some VNC authentication methods do not have a concept of user accounts. I think this is out of scope of the VNC server. This can be easily implemented on an operating system level by setting the process memory limits (ulimit -m -v). Then the malloc() fails and the server refuses the transfer. Even if we choose some arbitrary limit, being it a compile-time option will make hard times for users willing to change the limit (they can have a system with smaller or larger memory). Shouldn't the file size limit be a run-time option? |
This ammends a 5028218 fix for a heap out-of-bound write access in rfbProcessFileTransferReadBuffer() when reading a transfered file content in a server. The former fix did not work on platforms with a 32-bit size_t type (expected by malloc()) or with a 32-bit int type (expected by rfbReadExact()); It also fixes the same issue in InitialiseRFBConnection() when reading a display name in a client. It also corrects a cast in HandleRFBServerMessage() when a client reads a cut text from a server. This allocation is already guarded since commit c5ba3fe. CVE-2018-15127 <LibVNC#243> <LibVNC#273>
This comment has been minimized.
This comment has been minimized.
|
Closing this now, futher sanity checking for plausible allocation sizes should be collected in #275 |
This ammends 15bb719 fix for a heap out-of-bound write access in rfbProcessFileTransferReadBuffer() when reading a transfered file content in a server. The former fix did not work on platforms with a 32-bit int type (expected by rfbReadExact()). CVE-2018-15127 <LibVNC#243> <LibVNC#273>
This ammends 15bb719 fix for a heap out-of-bound write access in rfbProcessFileTransferReadBuffer() when reading a transfered file content in a server. The former fix did not work on platforms with a 32-bit int type (expected by rfbReadExact()). CVE-2018-15127 <LibVNC#243> <LibVNC#273>
This comment has been minimized.
This comment has been minimized.
|
The following CVEs were assigned for the incomplete fixes: CVE-2018-20748: c5ba3fe CVE-2018-20749: CVE-2018-20750: |
The fixes for #247 are incomplete, as I explained in:
https://www.openwall.com/lists/oss-security/2018/12/10/8
"Upstream's fix appears to be to add casts to (uint64_t) before adding 1 in those many malloc() calls. On platforms with larger than 32-bit size_t, this should be sufficient against integer overflows since the sizes are read from 32-bit protocol fields, but it isn't sufficient to prevent maliciously large memory allocation on the client by a rogue server. On a platform with 32-bit size_t, this isn't even sufficient to prevent the integer overflows."
Edit: I've just realized the fixes were the issue reporter's, and were merely accepted upstream. But that doesn't change anything with respect to the project needing even further fixes.