0
votes

I was working on some scripts that we have to build a small-time Linux OS that we produce at work. I found a bug in the scripts. We were building a kernel module against the wrong set of kernel headers.

What makes this interesting is that the kernel module built fine, so the script simply copied it to the location under /lib/modules/ that corresponded with the kernel that we intended to build against, not the one we actually built against. The script then ran depmod.

In this scenario (which is obviously wrong), what should the expected behavior be?

1

1 Answers

1
votes

A module which has been built with the wrong set of kernel headers can be loaded into the kernel, but its functionality is questionable (Undefined Behaviour).

It is possible that your module uses structures whose layout differs from the ones used by intended kernel.

If you are lucky and your module neither uses direct access (including access through macros and static inline functions) to the changed fields nor allocates memory for that structure (on the stack or on the heap), your module will operate as expected. Otherwise something will go wrong.