1

I'm writing an application which reports back readings from CPU temperature sensors, and the fan speed monitor. However, according to the Intel documentation on PECI, the instructions required must be run in ring 0 mode, i.e. kernel mode, or an exception is thrown.

I encountered code online to transition from protected mode to kernel mode, but none from user to kernel mode, and I read it was forbidden by the kernel. Is there a work around, hopefully that does not require patching the kernel, to allow a program initially in user mode to run as kernel mode?

3

No. The kernel is specifically designed to disallow user mode code from running in ring 0.

In order to do this, you will have to write a kernel module, and then talk to your module through some method (perhaps ioctl) from your user mode program.

Writing a kernel module does not require patching the kernel, but the kernel module must be written very carefully. It is best to start with an example module that does something similar, and modify it to suit your needs.

  • If I write a kernel module, what mode will the assembly code start off in? – AnonymousPhysicist Jul 3 '14 at 7:44
  • Kernel modules (at least in Linux) run at ring 0. – Greg Hewgill Jul 3 '14 at 8:23
0

Here's a pretty nice guide to get started with; http://www.thegeekstuff.com/2013/07/write-linux-kernel-module/

The makefile didn't work for me (nothing to be done for 'all'), but just running the kernel make command directly works fine;

user@gauss:~/a$ make -C /lib/modules/$(uname -r)/build M=$PWD modules
make: Entering directory `/usr/src/linux-headers-3.13.0-29-generic'
  CC [M]  /home/user/a/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/user/a/hello.mod.o
  LD [M]  /home/user/a/hello.ko
make: Leaving directory `/usr/src/linux-headers-3.13.0-29-generic'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.