-1

i am new with kernel modules development and have decided to write my first kernel module today.

my module is supposed to receive 2 numbers as input, seperated by a whitespace and have those numbers added together.

the kernel module communicates via a proc entry named calc (/proc/calc), so reading from the file will be there returned output and writing to that file would be giving new input (2 numbers seperated by a whitespace)

when loading the module (insmod) my shell gets stuck, when interrupting it and looking at dmesg i see a kernel BUG line, here is the trace.

i am not sure if that is a bug in my code, or is it an actual bug at the linux kernel, and would love to understand what i've done wrong and how can i start debugging my module with the given dmesg log.

here is the source code of my module.

my makefile is the very standard one,

obj-m += calc.o
KDIR := /lib/modules/$(shell uname -r)/build

all:
    $(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
    $(MAKE) -C $(KDIR) M=$(PWD) clean

Many many thanks in advance!

EDIT: i am using ubuntu 16.04.02, release 4.10.0-28, quite standard.

Community
  • 1
  • 1

2 Answers2

0

Have you created device file ?

root@xyz-PC:~/s_flow/dd# ls -l /dev/my_device

if not then first create the device file using below command

root@achal:~/dd/char1# mknod /dev/my_device c  300  0

in my system(ubuntu 14.04) it's all good as below.

root@xyz:~/s_flow/dd# dmesg
[  519.751941] calc: module verification failed: signature and/or required key missing - tainting kernel
[  519.752368] Calculator initializing
[  519.752372] Initializing proc entry at /proc/calc
[  519.752380] initialized calc proc entry
[  519.752384] mallocing last_message for 128 bytes
[  519.752386] malloc finished, resetting calc
[  519.752389] calc reset, all good :

can you give application program details which is using this module ?

Achal
  • 11,821
  • 2
  • 15
  • 37
0

The problem is the statement last_message = ""; is wrong.. You are assigning invalid memory address to pointer last_message. That's why OOPS is coming. last_message should be changed like this

static void reset_calc(void) {
    last_message_size = 0;
    last_message = "";
    last_message_type = WAS_LAST_READ; // we expect the first action to     be write
    }

should be changed to

   memset(last_message,0,MAX_MESSAGE_SIZE);
Varun
  • 447
  • 4
  • 9