We'll try a quick Proof of Concept in our vmalloc_demo kernel module. We allocate a region of memory specifying the page protection to be read-only (or RO) via the __vmalloc() kernel API. We then test it by reading and writing to the read-only memory region. A code snippet from it is seen as follows.
Note that we have kept the (silly) WR2ROMEM_BUG macro in the following code undefined by default, so that you, innocent reader, don't have our evil vmalloc_demo kernel module simply crash on you. So in order to try this PoC, please un-comment the define statement (as shown here), thus allowing the buggy code to execute:
static int vmalloc_try(void)
{
[...]
/* 5. __vmalloc(): allocate some 42 pages and set protections to RO */
/* #undef WR2ROMEM_BUG */
#define WR2ROMEM_BUG /* 'Normal' usage: keep this commented out, else we
* will crash! Read the book...