DriverUnload question

Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email


This is a bad idea. You should be able to unload a driver at anytime, the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded (unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

Ok, to disable calling of unload, have you driver up the reference count to
the device you create. This will effectively lock out calling unload, since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

No, call ObReferenceObject/ObDereferenceObject with a pointer to your device
object. This will effective disable the unload routine, since the system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
Sent: Friday, July 02, 2004 7:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

So there is no way to get this to work then?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: 02 July 2004 16:14
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
Sent: Friday, July 02, 2004 7:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email

On Fri, 2004-07-02 at 10:13, Doron Holan wrote:

IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

Just for the sake of argument, could he exchange a null into unload on
his DRIVER_OBJECT? There are obvious synch issues to deal with, not to
mention Don’s well-made point that this is probably not the best way to
go about the design, but in theory?

-sd

Sorry, but as far as I know and the Windows source indicates this also, the
driver will not be unloaded if any device on the list from the Driver object
has reference count other than zero! I know this is how things worked in NT
4.0 since I had to track down a nasty bug where a devices reference count
was incremented and the driver would not unload.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Doron Holan” wrote in message
news:xxxxx@ntdev…
IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
Sent: Friday, July 02, 2004 7:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I think the misunderstanding here is the difference between the unload
routine being called and the driver image itself actually unloading.
What you are referring to is the unload routine was invoked, but a
reference was leaked, so the image itself was not unloaded. Adding a
reference will get you this far. The question now becomes once you are
in this state, will the system ever attempt to unload you again? I am
pretty sure the answer is no. So you are now left in this really quasi
half dead state.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: Friday, July 02, 2004 11:15 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Sorry, but as far as I know and the Windows source indicates this also,
the
driver will not be unloaded if any device on the list from the Driver
object
has reference count other than zero! I know this is how things worked
in NT
4.0 since I had to track down a nasty bug where a devices reference
count
was incremented and the driver would not unload.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Doron Holan” wrote in message
news:xxxxx@ntdev…
IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
Sent: Friday, July 02, 2004 7:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

So essentially I would call IoGetAttachedDeviceReference to increment
the reference count by one and then when I want to allow removal of the
device I would then call ObDereferenceObject to decrement the reference
count and allowing the removal of the driver.

Is this what you meant?

Thanks,
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:35
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

Ok, to disable calling of unload, have you driver up the reference count
to
the device you create. This will effectively lock out calling unload,
since
the system knows the device is in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
The trouble is that we are developing software for parents to protect
their kids, and as we all know kids these days are very adept when it
comes to computers and most parents would not realise that their own
children have administrative privileges. The driver is not a WDM driver
so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
all possible.

If there are instability problems related to this then we would
obviously have to consider them.

Thanks
Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:21
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

This is a bad idea. You should be able to unload a driver at anytime,
the
system provides enough security that only someone with the correct
permissions can unload a driver. If this is a WDM driver there is
typically not a lot to do in unload anyway. Note if it is an unload
routine, you can fail query remove so that you do not get unloaded
(unless a
surprise remove) occurs.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
news:xxxxx@ntdev…
Hi,

Is there a way I can set the DriverUnload routine dynamically so that
the driver it’s self can decide whether it is able to be unloaded or
not?

So essentially I will not set the Unload routine in DriverEntry to
prevent the driver removal using net stop but then later in the driver
somewhere I can then update the DRIVER_OBJECT somehow to then allow then
net stop to work.

Many thanks
Ceri


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com


This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email



Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Your original idea is correct. We use it for NT4 style driver for years. There is the only trap: when somebody tries to unload driver (net stop, SCM functions) and unload handler isn’t set in this moment, system remembers it and driver can’t be unloaded until reboot even if unload routine is set later. Some low level routines (ZwUnloadDriver) could work; I haven’t tried it.

It is also possible there are race conditions which can cause BSOD. I haven’t examined how system handles it but if there is something like

if (DriverObject->UnloadHandler != NULL) {
DriverObject->UnloadHandler(DriverObject);
}

even interlocked exchange may not be enough (may be if code is optimized enough). The risk depends how often you change unload handler state. Normally, it should be very low.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Ceri Coburn[SMTP:xxxxx@first4internet.co.uk]
Reply To: Windows System Software Devs Interest List
Sent: Friday, July 02, 2004 5:16 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

So there is no way to get this to work then?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: 02 July 2004 16:14
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

IIRC, if this in an NT4 style driver, unload is called while there are
still device objects that the driver created and it is up to the driver
to delete them before returning from unload. Bumping a ref count won’t
help here if that is the case.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
Sent: Friday, July 02, 2004 7:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Hi,

Ah I see. OK. Thanks very much for your help.

Ceri

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
Sent: 02 July 2004 15:53
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] DriverUnload question

No, call ObReferenceObject/ObDereferenceObject with a pointer to your
device
object. This will effective disable the unload routine, since the
system
will see the device in use.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting

“Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> Hi,
>
> So essentially I would call IoGetAttachedDeviceReference to increment
> the reference count by one and then when I want to allow removal of the
> device I would then call ObDereferenceObject to decrement the reference
> count and allowing the removal of the driver.
>
> Is this what you meant?
>
> Thanks,
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:35
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> Ok, to disable calling of unload, have you driver up the reference count
> to
> the device you create. This will effectively lock out calling unload,
> since
> the system knows the device is in use.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>
>
> “Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> The trouble is that we are developing software for parents to protect
> their kids, and as we all know kids these days are very adept when it
> comes to computers and most parents would not realise that their own>
> children have administrative privileges. The driver is not a WDM driver
> so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
> all possible.
>
> If there are instability problems related to this then we would
> obviously have to consider them.
>
> Thanks
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:21
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> This is a bad idea. You should be able to unload a driver at anytime,
> the
> system provides enough security that only someone with the correct
> permissions can unload a driver. If this is a WDM driver there is
> typically not a lot to do in unload anyway. Note if it is an unload
> routine, you can fail query remove so that you do not get unloaded
> (unless a
> surprise remove) occurs.
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
> “Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> Hi,
>
> Is there a way I can set the DriverUnload routine dynamically so that
> the driver it’s self can decide whether it is able to be unloaded or
> not?
>
> So essentially I will not set the Unload routine in DriverEntry to
> prevent the driver removal using net stop but then later in the driver
> somewhere I can then update the DRIVER_OBJECT somehow to then allow then
> net stop to work.
>
> Many thanks
> Ceri
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit > http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Open the file on your own device object and hold it. This causes “net stop”
to fail.
Close the file when you want to allow the unload.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Ceri Coburn”
To: “Windows System Software Devs Interest List”
Sent: Friday, July 02, 2004 6:15 PM
Subject: [ntdev] DriverUnload question

> Hi,
>
> Is there a way I can set the DriverUnload routine dynamically so that
> the driver it’s self can decide whether it is able to be unloaded or
> not?
>
> So essentially I will not set the Unload routine in DriverEntry to
> prevent the driver removal using net stop but then later in the driver
> somewhere I can then update the DRIVER_OBJECT somehow to then allow then
> net stop to work.
>
> Many thanks
> Ceri
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Maxim, just to understand it better - this will also lock the driver module
file (because it's in use?) ... I mean usually you could delete the driver
module although the driver is loaded.

Oliver

Open the file on your own device object and hold it. This causes "net
stop"
to fail.
Close the file when you want to allow the unload.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

--

May the source be with you, stranger ... :wink:

I have reverse-engineered this path once.

The ObXxx reference counts are not used in this check.
Only DeviceObject->ReferenceCount is used, which is a count of existing
file objects referencing this device.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Don Burn”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Friday, July 02, 2004 10:15 PM
Subject: Re:[ntdev] DriverUnload question

> Sorry, but as far as I know and the Windows source indicates this also, the
> driver will not be unloaded if any device on the list from the Driver object
> has reference count other than zero! I know this is how things worked in NT
> 4.0 since I had to track down a nasty bug where a devices reference count
> was incremented and the driver would not unload.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>
>
> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> IIRC, if this in an NT4 style driver, unload is called while there are
> still device objects that the driver created and it is up to the driver
> to delete them before returning from unload. Bumping a ref count won’t
> help here if that is the case.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
> Sent: Friday, July 02, 2004 7:55 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] DriverUnload question
>
> Hi,
>
> Ah I see. OK. Thanks very much for your help.
>
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:53
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> No, call ObReferenceObject/ObDereferenceObject with a pointer to your
> device
> object. This will effective disable the unload routine, since the
> system
> will see the device in use.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>
> “Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> Hi,
>
> So essentially I would call IoGetAttachedDeviceReference to increment
> the reference count by one and then when I want to allow removal of the
> device I would then call ObDereferenceObject to decrement the reference
> count and allowing the removal of the driver.
>
> Is this what you meant?
>
> Thanks,
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:35
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> Ok, to disable calling of unload, have you driver up the reference count
> to
> the device you create. This will effectively lock out calling unload,
> since
> the system knows the device is in use.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>
>
> “Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> The trouble is that we are developing software for parents to protect
> their kids, and as we all know kids these days are very adept when it
> comes to computers and most parents would not realise that their own
> children have administrative privileges. The driver is not a WDM driver
> so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
> all possible.
>
> If there are instability problems related to this then we would
> obviously have to consider them.
>
> Thanks
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:21
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> This is a bad idea. You should be able to unload a driver at anytime,
> the
> system provides enough security that only someone with the correct
> permissions can unload a driver. If this is a WDM driver there is
> typically not a lot to do in unload anyway. Note if it is an unload
> routine, you can fail query remove so that you do not get unloaded
> (unless a
> surprise remove) occurs.
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
> “Ceri Coburn” wrote in message
> news:xxxxx@ntdev…
> Hi,
>
> Is there a way I can set the DriverUnload routine dynamically so that
> the driver it’s self can decide whether it is able to be unloaded or
> not?
>
> So essentially I will not set the Unload routine in DriverEntry to
> prevent the driver removal using net stop but then later in the driver
> somewhere I can then update the DRIVER_OBJECT somehow to then allow then
> net stop to work.
>
> Many thanks
> Ceri
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Again, IIRC correctly, outstanding file handles will not make a
difference. After you have deleted the device, all i/o sent will be
completed with error by the i/o manager, but holding the handle open
will not pin an NT4 style driver from unloading.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Friday, July 02, 2004 3:42 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DriverUnload question

Open the file on your own device object and hold it. This causes
“net stop”
to fail.
Close the file when you want to allow the unload.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Ceri Coburn”
To: “Windows System Software Devs Interest List”
Sent: Friday, July 02, 2004 6:15 PM
Subject: [ntdev] DriverUnload question

> Hi,
>
> Is there a way I can set the DriverUnload routine dynamically so that
> the driver it’s self can decide whether it is able to be unloaded or
> not?
>
> So essentially I will not set the Unload routine in DriverEntry to
> prevent the driver removal using net stop but then later in the driver
> somewhere I can then update the DRIVER_OBJECT somehow to then allow
then
> net stop to work.
>
> Many thanks
> Ceri
>
>
>
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
>

>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I tried below mentioned trap and have to correct myself. The bad effect applies for “net stop” only i.e. once unsuccessful, unsuccessful until reboot. However, SCM functions still work well. Instead “net stop driver” use “sc stop driver” which will fail when unload handler is zeroed and succeeds when it is reset back to unload function. AFAIK sc.exe is part of OS installation since w2k.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Michal Vodicka[SMTP:xxxxx@upek.com]
Reply To: Windows System Software Devs Interest List
Sent: Friday, July 02, 2004 11:19 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] DriverUnload question

Your original idea is correct. We use it for NT4 style driver for years. There is the only trap: when somebody tries to unload driver (net stop, SCM functions) and unload handler isn’t set in this moment, system remembers it and driver can’t be unloaded until reboot even if unload routine is set later. Some low level routines (ZwUnloadDriver) could work; I haven’t tried it.

It is also possible there are race conditions which can cause BSOD. I haven’t examined how system handles it but if there is something like

if (DriverObject->UnloadHandler != NULL) {
DriverObject->UnloadHandler(DriverObject);
}

even interlocked exchange may not be enough (may be if code is optimized enough). The risk depends how often you change unload handler state. Normally, it should be very low.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]

> ----------
> From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Ceri Coburn[SMTP:xxxxx@first4internet.co.uk]
> Reply To: Windows System Software Devs Interest List
> Sent: Friday, July 02, 2004 5:16 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] DriverUnload question
>
> So there is no way to get this to work then?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
> Sent: 02 July 2004 16:14
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] DriverUnload question
>
> IIRC, if this in an NT4 style driver, unload is called while there are
> still device objects that the driver created and it is up to the driver
> to delete them before returning from unload. Bumping a ref count won’t
> help here if that is the case.
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Ceri Coburn
> Sent: Friday, July 02, 2004 7:55 AM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] DriverUnload question
>
> Hi,
>
> Ah I see. OK. Thanks very much for your help.
>
> Ceri
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> Sent: 02 July 2004 15:53
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] DriverUnload question
>
> No, call ObReferenceObject/ObDereferenceObject with a pointer to your
> device
> object. This will effective disable the unload routine, since the
> system
> will see the device in use.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>
>
> “Ceri Coburn” wrote in message
> > news:xxxxx@ntdev…
> > Hi,
> >
> > So essentially I would call IoGetAttachedDeviceReference to increment
> > the reference count by one and then when I want to allow removal of the>
> > device I would then call ObDereferenceObject to decrement the reference
> > count and allowing the removal of the driver.
> >
> > Is this what you meant?
> >
> > Thanks,
> > Ceri
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> > Sent: 02 July 2004 15:35
> > To: Windows System Software Devs Interest List
> > Subject: Re:[ntdev] DriverUnload question
> >
> > Ok, to disable calling of unload, have you driver up the reference count
> > to
> > the device you create. This will effectively lock out calling unload,
> > since
> > the system knows the device is in use.
> >
> >
> > –
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >
> >
> >
> > “Ceri Coburn” wrote in message
> > news:xxxxx@ntdev…
> > The trouble is that we are developing software for parents to protect
> > their kids, and as we all know kids these days are very adept when it
> > comes to computers and most parents would not realise that their own>
> > children have administrative privileges. The driver is not a WDM driver
> > so I cannot respond to QUERY_REMOVE so I was just wondering if it is at
> > all possible.
> >
> > If there are instability problems related to this then we would
> > obviously have to consider them.
> >
> > Thanks
> > Ceri
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn
> > Sent: 02 July 2004 15:21
> > To: Windows System Software Devs Interest List
> > Subject: Re:[ntdev] DriverUnload question
> >
> > This is a bad idea. You should be able to unload a driver at anytime,
> > the
> > system provides enough security that only someone with the correct
> > permissions can unload a driver. If this is a WDM driver there is
> > typically not a lot to do in unload anyway. Note if it is an unload
> > routine, you can fail query remove so that you do not get unloaded
> > (unless a
> > surprise remove) occurs.
> >
> > –
> > Don Burn (MVP, Windows DDK)
> > Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >
> > “Ceri Coburn” wrote in message
> > news:xxxxx@ntdev…
> > Hi,
> >
> > Is there a way I can set the DriverUnload routine dynamically so that
> > the driver it’s self can decide whether it is able to be unloaded or
> > not?
> >
> > So essentially I will not set the Unload routine in DriverEntry to
> > prevent the driver removal using net stop but then later in the driver
> > somewhere I can then update the DRIVER_OBJECT somehow to then allow then
> > net stop to work.
> >
> > Many thanks
> > Ceri
> >
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit > http://www.messagelabs.com/email
> >

> >
> >
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@first4internet.co.uk
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> >
> >
> >
> > This email has been scanned by the MessageLabs Email Security System.
> > For more information please visit http://www.messagelabs.com/email
> >

> >
> > —
> > Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@upek.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@upek.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

No. Driver files are never locked in any NT I know. You can delete any
driver file for a loaded driver.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 03, 2004 2:49 AM
Subject: Re: [ntdev] DriverUnload question

> Maxim, just to understand it better - this will also lock the driver module
> file (because it’s in use?) … I mean usually you could delete the driver
> module although the driver is loaded.
>
> Oliver
>
> > Open the file on your own device object and hold it. This causes “net
> > stop”
> > to fail.
> > Close the file when you want to allow the unload.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
>
> –
> ---------------------------------------------------
> May the source be with you, stranger … :wink:
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

No. Max suggests to open device object and not driver file itself.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http:://www.upek.com]


From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of xxxxx@gmxpro.net[SMTP:xxxxx@gmxpro.net]
Reply To: Windows System Software Devs Interest List
Sent: Saturday, July 03, 2004 12:49 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] DriverUnload question

Maxim, just to understand it better - this will also lock the driver module
file (because it’s in use?) … I mean usually you could delete the driver
module although the driver is loaded.

Oliver

> Open the file on your own device object and hold it. This causes “net
> stop”
> to fail.
> Close the file when you want to allow the unload.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com

May the source be with you, stranger … :wink:


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@upek.com
To unsubscribe send a blank email to xxxxx@lists.osr.com