Page MenuHomeFreeBSD

busdma: avoid buflen underflow
ClosedPublic

Authored by mhorne on Jun 25 2024, 5:05 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 24, 3:05 AM
Unknown Object (File)
Oct 5 2024, 2:02 PM
Unknown Object (File)
Oct 1 2024, 7:10 AM
Unknown Object (File)
Sep 30 2024, 12:18 AM
Unknown Object (File)
Sep 25 2024, 3:51 AM
Unknown Object (File)
Sep 16 2024, 8:40 PM
Unknown Object (File)
Sep 7 2024, 6:52 PM
Unknown Object (File)
Sep 7 2024, 6:52 PM

Details

Summary

The loop condition in the dmamap_load_buffer() method is 'buflen > 0',
and buflen is an unsigned type (bus_size_t).

A recent change made it possible for sgsize to exceed the remaining
buflen, when the tag has a large alignment requirement. The result is
that we would not break out of the loop at the correct time. Fix this by
avoiding underflow in the subtraction at the end of the loop.

PR: 279383
Reported by: Robert Morris <rtm@lcs.mit.edu>
Fixes: a77e1f0f81df ("busdma: better handling of small segment bouncing")

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I could apply the same guard to bounce_bus_dmamap_load_phys() methods, but in those functions it is easier to see that underflow is not possible, so I haven't yet.

sys/arm64/arm64/busdma_bounce.c
864–867

Note: arm and arm64 implementations are actually lacking the line

sgsize = roundup2(sgsize, dmat->common.alignment);

found in the other implementations, and are therefore not susceptible to the same underflow. Still, I think it is wise to add the check here too.

This revision is now accepted and ready to land.Jun 25 2024, 5:15 PM
This revision was automatically updated to reflect the committed changes.