CreateFile returning success without entry into dispatch

Hi,

I have an app that talks to my driver. In one test scenario the app opens a handle to the driver (CreateFile), sends an ioctl and closes the handle. This works correctly as expected with the test running in a loop.

When I run the test for long hours (overnight), I observe that the ioctl call fails with Invalid Handle error. While debugging this I noticed that when the issue is reproduced the CreateFile call is getting completed successfully *without* an entry into driver’s dispatch routine (IRP_MJ_CREATE)!
When I subsequently called ioctl with the handle returned by the CreateFile, I get an Invalid Handle error.

In what scenario the CreateFile gets succeeded without corresponding entry into the dispatch? Will appreciate some tips to debug this further, thanks.

Regards,
Suresh

That?s simply not possible. If you have a handle, you have a file object. If you have a file object, it was successfully created. If a file object was created, your create dispatch entry point returned success.

You have some sort of bug like a race condition in your test code.

Peter
OSR
@OSRDrivers

How are checking for success after the call to CreateFile? Are you sharing the handle across threads?

Bent from my phone


From: xxxxx@lists.osr.com on behalf of xxxxx@yahoo.com
Sent: Thursday, March 29, 2018 6:39:56 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] CreateFile returning success without entry into dispatch

Hi,

I have an app that talks to my driver. In one test scenario the app opens a handle to the driver (CreateFile), sends an ioctl and closes the handle. This works correctly as expected with the test running in a loop.

When I run the test for long hours (overnight), I observe that the ioctl call fails with Invalid Handle error. While debugging this I noticed that when the issue is reproduced the CreateFile call is getting completed successfully without an entry into driver’s dispatch routine (IRP_MJ_CREATE)!
When I subsequently called ioctl with the handle returned by the CreateFile, I get an Invalid Handle error.

In what scenario the CreateFile gets succeeded without corresponding entry into the dispatch? Will appreciate some tips to debug this further, thanks.

Regards,
Suresh


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

> How are checking for success after the call to CreateFile?

We are checking for a return value of INVALID_HANDLE_VALUE from CreateFile to deduce a failure, otherwise we treat it as success and proceed to use the returned handle in subsequent call to ioctl.

Are you sharing the handle across threads?

No, it is a single thread which opens, uses and closes the handle in each iteration.

Here is the snapshot of the call:

handle = CreateFile(driver_name,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
FILE_FLAG_OVERLAPPED,
NULL);
if (INVALID_HANDLE_VALUE == handle) {
handle = NULL;
}
return handle;

Wait, isn’t 0 a valid handle?

> Wait, isn’t 0 a valid handle?

Oh, is it? Thanks for catching that. We then better return a negative value if CreateFile fails.
However in our current scenario we ARE getting a non-zero handle returned from CreateFile (without an entry into dispatch).

No, no… zero is not a valid handle for any practical purpose.

Peter
OSR
@OSRDrivers