Windows: Prevent simultaneous pioctls
authorJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 6 Sep 2009 18:45:42 +0000 (14:45 -0400)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Tue, 8 Sep 2009 17:14:54 +0000 (10:14 -0700)
commit132268042d1992d39614e72d67957b2b10ebfba6
tree36c805532464b555911a6e41b5cc44478c2c8b46
parent60caadec3a7d6ef64744be8533205ecfa0ff4179
Windows: Prevent simultaneous pioctls

The Windows pioctl implementation makes an incorrect assumption.
It is not true that every CreateFile() operation results in a
SMB NTCreateX operation being delivered to SMB Server.  The SMB
client can combine open requests from multiple processes or threads
onto a single SMB file descriptor and locally manage the operations.
This is a problem for pioctls since the Transceive operation requires
that a WriteFile/ReadFile combination must belong to the same request.

Prior to this change simultaneous pioctl operations would be
combined and the individual reads and writes could overlap resulting
in responses going to the wrong requestor and end of file errors
being received by the others.

Due to lack of data validation in fs.c, ktc_nt.c, symlink.c,
etc random crashes are produced.

This change alters the sharing mode under which the pioctl file is
opened.  Instead of FILE_SHARE_READ | FILE_SHARE_WRITE, only
FILE_SHARE_READ is specified to CreateFile().  This ensures that
the CreateFile will fail with a sharing violation if the pioctl
file was previously opened for writing.

A sharing violation check is provided and the CreateFile is retried
indefinitely until the open succeeds or the error is not a sharing
violation.

LICENSE MIT

Reviewed-on: http://gerrit.openafs.org/404
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Asanka Herath <asanka@secure-endpoints.com>
Reviewed-by: Asanka Herath <asanka@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
src/sys/pioctl_nt.c