Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results


Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

Correct way to copy SID in WFP Callouts.

Vitaly_TkachenkoVitaly_Tkachenko Member Posts: 16
edited February 6 in NTDEV

Hi all,

I'm working on a callout driver, and one of its features is to intercept network connection events. I have a callout at the FWPS_LAYER_ALE_FLOW_ESTABLISHED_V4 layer. This layer has a fixed data field FWPS_FIELD_ALE_FLOW_ESTABLISHED_V4_ALE_USER_ID, which contains a TOKEN_ACCESS_INFORMATION pointer that provides the SID of the user account that owns the connection. My goal is to copy this SID to a buffer and pass it to user-mode for further processing. My question is: what is the correct way to copy this SID to the buffer?

I was going to use standard Sid functions, but the documentation is quite clear:

  • The WFP engine calls the callout classify function at IRQL <= DISPATCH_LEVEL.
  • RtlCopySid(), RtlLengthSid(), which are needed to allocate the buffer and copy the sid, must be called at IRQL <= APC_LEVEL.

This means that we can only use the Sid functions to copy the user's SID when the callout's classify function is called at IRQL < DISPATCH_LEVEL, but this never actually happens. So we can't use Sid functions at all, if I'm not missing something.

My other approach was to convert the SID to a Unicode String (RtlConvertSidToUnicodeString()) and pass that string to user mode. And this approach works. But as I know it's not recommended to use unicode at the DISPATCH_LEVEL, because unicode charactes code pages memory may be paged and in this case the driver will crash.

So what is the correct way to copy user's SID in this case?

Thank you in advance,


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online