Several issues, see below…
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of disney_cheng@qq.com
Sent: Tuesday, December 14, 2010 10:56 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] A crash after copying data to a buffer getting from an MDL
I wrote a virtual USB bus driver in Windows, it’s a WDM driver. After it
enumerate the USBSTOR driver, in the usb bulk or interrupt transfer phase,
the USBSTOR driver will send some IRPs with MDL pointer. It means that using
direct I/O method (but strangely, the “Method” in the IRP is “Neither”).
When I use the MDL to copy data, it cause a crash. The code to deal with the
mdl is below:
if(Irp->MdlAddress != NULL)
{
buf = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
//It will not crash without this sentence
RtlMoveMemory(buf, data, dataLength); }
***************
There is a serious error here unless you have omitted the code in the
posting. Where is the test that sees if MmGetSystemAddressForMdlSafe
worked? Do you know buf is non-NULL? But it is hard to guess what is going
on here. What is the address of ‘data’? How was it obtained? What is the
value of dataLength? How was it obtained? Essentially, you have apparently
made no attempt to determine what has gone wrong here. You have not
explained to use where the other two parameters come from, so we have no
idea what they mean, or if they could be the problem. You will get these
errors if buf is illegal, if buf has any illegal state from buf to
buf+dataLength-1, if data is illegal, or there is any illegal state from
data to data+datalength-1. We see 1/3 of the problem, which has an obvious
error, but we’re missing the other 2/3.
Note that for USB transfers, you can only transfer the maximum bulk transfer
size on any transaction, e.g., 1K bytes for USB 1.0, 2K bytes for high-speed
USB 2.0, etc., and since you have said nothing about the expected buffer
sizes, or any attempt you are making to limit transfer sizes, there is no
way to tell what is going on here. I might as well say
“I have an error in this statement. What’s wrong?
SUM = DATA + SUM;”
Until you explain where *all* these values come from, or actually tell us,
by using the debugger, what you are seeing for thse values, there’s no good
way to guess, except using psychic vibrations, what is going on. I’m mpt
very good at debugging via psychic vibrations.
******************
Without copying data, it will not crash. But when crash happen, there always
be some delay from copying, and the point it crash down, not always at one
place.
When I print out the data from the buffer before copying to it, I saw some
times it’s not all zero. It should be all zero. Possibly, it means the “buf”
pointer dosn’t point to the right buffer the data shall be copied to. The
data was copied to an unknow place in the kernel, it cause a crash.
The question is why would I get a wrong virtual address by using
MmGetSystemAddressForMdlSafe(), is this a bug of USBSTOR driver or what?
Should I do something else before copying data? BTW, usually the “buf” is
“f8xxxxxx”, it’s higher then normal virtual address like “81xxxxxx”. Does it
mean something?
***********
You could get NULL, an illegal address that I do not see you testing for.
Kernel addresses are going to be in the valid kernel range. With a default
(not 3GB) boot, this means they will potentially be in the range
80000000-FFFFFFFF. I think the higest upper addresses have some specific
value range used for devices, but F8xxxxxx sounds like a reasonable value.
***********
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
–
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.