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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

8 Comments

Can I passing it to the make file ?
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.
If Makefile is well written, it might give you possibility to pass CFLAGS via command line: make CFLAGS=-D_FORTIFY_SOURCE=0.
I passed make CFLAGS=-D_FORTIFY_SOURCE=0 and got "gcc: error: _FORTIFY_SOURCE=0: No such file or directory"
Then, as I said, try to add -D_FORTIFY_SOURCE=0 to CFLAGS within Makefile.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.