0

I am reading about copy_from_user(…) and copy_to_user(…) which copies from user and writes back to user space from kernel. when i see the internal implementation of copy_from_user(…), it is having two functions access_ok(…) and memcpy(…), when i read about access_ok(…), it is saying access_ok(…) is used to check whether the userspace pointer is valid or not.

What check does access_ok(…) is doing to check the pointer validity?

datenwolf
  • 159,371
  • 13
  • 185
  • 298
anikhan
  • 1,147
  • 3
  • 18
  • 44
  • 1
    https://stackoverflow.com/questions/12357752/what-is-the-point-of-using-the-linux-macro-access-ok – Matt Sep 06 '17 at 09:00

1 Answers1

0

In short it checks that memory is actually mapped at the given address. This is done by looking at the page mapping table, testing if that address has a matching entry there.

Furthermore it is tested that the address resides in user space, which is simply testing that its numeric value is in the lower half of the valid range of address values.

datenwolf
  • 159,371
  • 13
  • 185
  • 298