0

I'm writing a kernel module that would write some data to user space buffer via copy_to_user. However, I found that copy_to_user always fails (returns non-zero) after the process forks. (copy_to_user works fine if I don't fork the process.) copy_to_user was called right after forked and I've used access_ok to check accessibility of the destination address.

I'm aware that after forking, child process will share meory with parent process due to copy-on-write mechanism. So I assume the reason that copy_to_user failed after fork might due to COW page fault.

My questions are,

  1. Is my assumption about COW mechanism causing copy_to_user failed true?
  2. If above is true, why didn't kernel handle page fault? Or What should I do to make copy_to_user work after process fork?
Vic Chang
  • 1
  • 2
  • 1
    Please show a [mre]. – stark Jul 03 '23 at 14:56
  • "I've used `access_ok` to check accessibility of the destination address..." - Don't confuse yourself: successful call to `access_ok` just means that the address doesn't belong to the kernel and **may** belong to user, if mapped. Successful `access_ok` doesn't confirm that the address can be accessed in the particular address space. – Tsyvarev Jul 03 '23 at 22:09

0 Answers0