Reputation: 9
I'm writing a Linux kernel (6.1.0-23-amd64) module with netfilter hooks. Module is loaded via insmod. There is no interaction with any userspace applications. I found that global variable value in my module (i.e. memory buffer for network data processing) is occasionally rewritten with wrong data. So the question is - what does this mean? How can I protect global vars from simultaneous rewriting? Thanks.
Local variables are working perfectly - so there is definitely no problem with data itself.
Upvotes: 0
Views: 41
Reputation: 9
Here is what I understand now (just counldn't ask right question). From [this article][1]
...do not execute sequentially— a kernel module registers itself to handle requests using its initialization function, which runs and then terminates. The type of requests that it can handle are defined within the module code. This is quite similar to the event-driven programming model that is commonly utilized in graphical-user interface (GUI) applications...
...can be interrupted — one conceptually difficult aspect of kernel modules is that they can be used by several different programs/processes at the same time. We have to carefully construct our modules so that they have a consistent and valid behavior when they are interrupted... [1]: https://labs.dese.iisc.ac.in/embeddedlab/the-hello-world-linux-loadable-kernel-module-2/
Thanks again for your comments.
Upvotes: 0