lkrg-org / lkrg

Linux Kernel Runtime Guard
https://lkrg.org
Other
410 stars 72 forks source link

Net: Skip unregister_console() if we never reached register_console() #328

Closed solardiz closed 5 months ago

solardiz commented 6 months ago

Right now, lkrg_register_net() does not return a status, and on unload we call lkrg_deregister_net() unconditionally. If we keep that, then lkrg_deregister_net() should be made smarter not to shut down things that were never initialized. With the current code, the easiest way to do this is to wrap the entirety of lkrg_deregister_net() code in if (kmsg_file). It already has that check, but only for (not) calling filp_close(). We already similarly check kmsg_file in lkrg_queue_net(), which the rest of LKRG also calls unconditionally.

Meanwhile, our calling of unregister_console() appears to be harmless, only producing a superfluous kernel message about that.