freebsd-dev/sys/compat
Bill Paul a787e5ecf8 Add sanity checks to the ndis_packet and ndis_buffer pool handling
routines to guard against problems caused by (possibly) buggy drivers.

The RealTek 8180 wireless driver calls NdisFreeBuffer() to release
some of its buffers _after_ it's already called NdisFreeBufferPool()
to destroy the pool to which the buffers belong. In our implementation,
this error causes NdisFreeBuffer() to touch stale heap memory.

If you are running a release kernel, and hence have INVARIANTS et al
turned off, it turns out nothing happens. But if you're using a
development kernel config with INVARIANTS on, the malloc()/free()
sanity checks will scribble over the pool memory with 0xdeadc0de
once it's released so that any attempts to touch it will cause a
trap, and indeed this is what happens. It happens that I run 5.2-RELEASE
on my laptop, so when I tested the rtl8180.sys driver, it worked fine
for me, but people trying to run it with development systems checked
out or cvsupped from -current would get a page fault on driver load.

I can't find any reason why the NDISulator would cause the RealTek
driver to do the NdisFreeBufferPool() prematurely, and the same driver
obviously works with Windows -- or at least, it doesn't cause a crash:
the Microsoft documentation for NdisFreeBufferPool() says that failing
to return all buffers to the pool before calling  NdisFreeBufferPool()
causes a memory leak.

I've written to my contacts at RealTek asking them to check if this
is indeed a bug in their driver. In the meantime, these new sanity checks
will catch this problem and issue a warning rather than causing a trap.
The trick is to keep a count of outstanding buffers for each buffer pool,
and if the driver tries to call NdisFreeBufferPool() while there are still
buffers outstanding, we mark the pool for deletion and then defer
destroying it until after the last buffer has been reclaimed.
2004-03-04 00:17:14 +00:00
..
freebsd32 Regen (FWIW) 2004-02-21 23:38:58 +00:00
ia32 Add a note about the landmine in the middle of struct ia32_sigframe. 2004-02-21 23:36:31 +00:00
linprocfs Remove VFS_STATFS() call which violated the lock order and wasn't 2004-02-09 20:33:42 +00:00
linux Device megapatch 5/6: 2004-02-21 21:32:15 +00:00
ndis Add sanity checks to the ndis_packet and ndis_buffer pool handling 2004-03-04 00:17:14 +00:00
netbsd Don't include <sys/buf.h> needlessly. 2003-04-01 09:02:58 +00:00
pecoff Add sysentvec->sv_fixlimits() hook so that we can catch cases on 64 bit 2003-09-25 01:10:26 +00:00
svr4 I guess nobody has needed to use the SVR4olator to create device 2004-02-07 18:54:34 +00:00