1

I'm using memset and memcpy in my linux kernel project. When I've tried to make the project, I got the following error:

In function ‘memset’, inlined from ‘init_minifw_read_write_module’ at /home/ido/CLionProjects/Firewall/KernelSpace/minfirewall.c:118:13: ./include/linux/string.h:327:3: error: call to ‘__write_overflow’ declared with attribute error: detected write beyond size of object passed as 1st parameter __write_overflow();

I didn't find any workaround for the above error.

Makefile:

obj-m += minfirewall.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

I'm running kernel version 4.18.0-15-generic.

Any ideas how to fix this error?

Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
Ido Segal
  • 430
  • 2
  • 7
  • 20

1 Answers1

1

This is due to _FORTIFY_SOURCE feature for compile-time and run-time protection for finding overflows in the common string (e.g. strcpy, strcmp) and memory (e.g. memcpy, memcmp) functions. Info is here and here.

You can explicitly turn this feature off by passing -D_FORTIFY_SOURCE=0 (-U_FORTIFY_SOURCE will work as well) to the compiler.

EDIT:

It looks like you are building a Linux kernel module. Passing a compiler option for kernel module Makefile is a bit specific.

Add following to your Makefile:

CFLAGS_minfirewall.o := -D_FORTIFY_SOURCE=0
Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
  • Can I passing it to the make file ? – Ido Segal Mar 12 '19 at 11:08
  • Of course. It depends on how Makefile is written. Typically `CFLAGS` is already present in Makefile, so you just need to add `-D_FORTIFY_SOURCE=0` to `CFLAGS` variable. Show me your Makefile, and I can tell you how to do this exactly. – Andrejs Cainikovs Mar 12 '19 at 11:10
  • [If Makefile is well written](https://stackoverflow.com/questions/2129391/append-to-gnu-make-variables-via-command-line), it might give you possibility to pass `CFLAGS` via command line: `make CFLAGS=-D_FORTIFY_SOURCE=0`. – Andrejs Cainikovs Mar 12 '19 at 11:19
  • I passed `make CFLAGS=-D_FORTIFY_SOURCE=0` and got "gcc: error: _FORTIFY_SOURCE=0: No such file or directory" – Ido Segal Mar 12 '19 at 11:26
  • Then, as I said, try to add `-D_FORTIFY_SOURCE=0` to `CFLAGS` within Makefile. – Andrejs Cainikovs Mar 12 '19 at 11:36
  • I've added my make file to the question.Thanks – Ido Segal Mar 12 '19 at 11:58
  • I've updated my answer. Hope this will work for you finally. – Andrejs Cainikovs Mar 12 '19 at 12:08
  • Hi Andrejs, thank you for all the information, but the issue is still persist. I've added the `CFLAGS_minfirewall.o := -D_FORTIFY_SOURCE=0` and then rum `make` and still got the error above. I missed something ? – Ido Segal Mar 12 '19 at 15:42