My original attempt at fixing this simply converted all of the BUG_ON() calls in ecryptfs_miscdev_*() to if statements that gracefully handled the various conditions. This mostly worked (and will probably be a part of the final solution) except for handling the case where a passed fd was the last one closed. In that situation, ecryptfs_miscdev_release() cannot do its job because we may not be able to look up the daemon with ecryptfs_find_daemon_by_euid() since the current euid may not match the original euid.
My original attempt at fixing this simply converted all of the BUG_ON() calls in ecryptfs_ miscdev_ *() to if statements that gracefully handled the various conditions. This mostly worked (and will probably be a part of the final solution) except for handling the case where a passed fd was the last one closed. In that situation, ecryptfs_ miscdev_ release( ) cannot do its job because we may not be able to look up the daemon with ecryptfs_ find_daemon_ by_euid( ) since the current euid may not match the original euid.