kmod-project / kmod

kmod - Linux kernel module handling
GNU Lesser General Public License v2.1
50 stars 39 forks source link

libkmod: Avoid overflows while parsing files #234

Closed stoeckmann closed 2 weeks ago

stoeckmann commented 3 weeks ago

Specially crafted files could overflow internal counters, allowing out of boundary writes. Make sure that neither counters nor resulting calculations overflow.

Another round of "is it even possible?"

Proof of Concept:

  1. Create a file which contains more than 2^32 pre dependencies

    (echo -n "softdep poc pre: "; yes a | tr '\n' ' ' | dd bs=4096 count=2097153; echo) > poc.conf
  2. Try to insert poc module

    modprobe -C poc.conf poc

This should lead to a segmentation fault or

SUMMARY: AddressSanitizer: heap-buffer-overflow ../libkmod/libkmod-config.c:371 in kmod_config_add_softdep

The file will be around 8 GB in size, memory peaks around that as well (didn't measure exactly, better have 16 GB or more). So, yes. It can happen. It's highly unlikely but we have the overflow checks already available, so let's just check instead of adjusting various data types and return values from unsigned int to size_t. Not worth it.

lucasdemarchi commented 2 weeks ago

Applied, thanks