Skip to content

File occasionally closes unexpectedly using Mono and P/Invoke #50

Description

@cheuschkel

Synopsis

In a C# Mono functional test app that makes ioctl calls via P/Invoke, I have a test that runs a MD5 hash 1000 consecutive times. Intermittently the /dev/crypto file descriptor will actually close. This happens usually in the middle of the test. It is nondeterministic what the failure rate is as it is sporadic, but it does not happen often.

Environment

Details

Once the fd closes, all following operations fail. Typically closing the failed fd and opening the file with a new fd for the next hash session is successful. After the fd is closed, the rest of the session can no longer access it (as would be expected).

An application log of what is happening can be seen below:

**open session 3515619450 fd 240135303
**end session 3515619450 fd 240135303
**open session 3201119842 fd 240135303
**end session 3201119842 fd 240135303
**close fd 240135303
**open fd 172288571
**open session 3262179618 fd 172288571
**end session 3262179618 fd 172288571
**open session 2893257947 fd 172288571
**end session 2893257947 fd 172288571
**close fd 172288571
**open fd 442451715
ERROR: received UnixIOException after sending CIOCGSESSION fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCCRYPT fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCCRYPT fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCFSESSION fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCGSESSION fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException when closing cryptodev fd 442451715!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
**open fd 1068122414
ERROR: received UnixIOException after sending CIOCGSESSION fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCCRYPT fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCCRYPT fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCFSESSION fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException after sending CIOCGSESSION fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
ERROR: received UnixIOException when closing cryptodev fd 1068122414!
Exception: SecurityServices.Platform.PlatformCryptoDev.Drivers.Ioctl.UnixIOException (0x80004005): errno 9
**open fd 518239958
**open session 2603267706 fd 518239958
**end session 2603267706 fd 518239958
**open session 4256969686 fd 518239958
**end session 4256969686 fd 518239958
**close fd 518239958
**open fd 851201225
**open session 29900735 fd 851201225
**end session 29900735 fd 851201225
**open session 324552913 fd 851201225
**end session 324552913 fd 851201225
**close fd 851201225

The exception can be triggered from any ioctl call in the sequence consisting of:

I verified that running lsof /dev/crypto proves that the file is actually closed:

"good" session - breakpoint set after successful operation:

root@tsi:~# lsof /dev/crypto
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient 633 root    4u   CHR  10,56      0t0 4611 /dev/crypto
mono    768 root    6u   CHR  10,56      0t0  4611 /dev/crypto

"bad" session - there is no active file descriptor for Mono with /dev/crypto in this case:

root@tsi:~# lsof /dev/crypto
dhclient  633                 root    4u      CHR      10,56      0t0       4611 /dev/crypto

I checked to see if dhclient was perhaps interfering with my process's file interaction, so I killed the process and re-ran the test but got the same failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions