freebsd11_network: Fix MLEN/MHLEN macros after mbufq changes.
In 02cb8503d2, I added the m_next and
m_nextpkt structures to mbuf, as per FreeBSD's mbufq system that
FreeBSD 11.1's net80211 code uses. What I didn't realize (and
korli and PulkoMandy who reviewed my code didn't notice either)
is that the data fields in mbuf are sometimes dealt with through
these LEN macros, which were now incorrect after such changes.
This caused an out-of-bounds memory write for data above a certain
size that was attempting to be written into an mbuf that under the
old sizing would have been fine, but under this new sizing was invalid,
and this manifested itself as a KDL under the guarded_heap (#14207).
It possibly also manifested itself as a stack-smash with the new net80211
code (uncommitted on a local machine, and the reason I tried using
the guarded heap in the first place.)
Now we use FreeBSD 11's macros, which use offsetof instead of raw
integer math. This means that we can't specify the struct size in mbuf
as these structs are computed from mbuf's definition, and thus have
to rely on the allocator giving mbuf the correct size (as FreeBSD
does also.)
This commit is contained in:
@@ -12,8 +12,10 @@
|
||||
#include <vm/uma.h>
|
||||
|
||||
|
||||
#define MLEN ((int)(MSIZE - sizeof(struct m_hdr)))
|
||||
#define MHLEN ((int)(MLEN - sizeof(struct pkthdr)))
|
||||
#define MHSIZE __offsetof(struct mbuf, m_dat)
|
||||
#define MPKTHSIZE __offsetof(struct mbuf, m_pktdat)
|
||||
#define MLEN ((int)(MSIZE - MHSIZE))
|
||||
#define MHLEN ((int)(MSIZE - MPKTHSIZE))
|
||||
|
||||
#define MINCLSIZE (MHLEN + 1)
|
||||
|
||||
@@ -137,10 +139,10 @@ struct mbuf {
|
||||
struct pkthdr MH_pkthdr;
|
||||
union {
|
||||
struct m_ext MH_ext;
|
||||
char MH_databuf[MHLEN];
|
||||
char MH_databuf[0];
|
||||
} MH_dat;
|
||||
} MH;
|
||||
char M_databuf[MLEN];
|
||||
char M_databuf[0];
|
||||
} M_dat;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user