Accessing Userspace Memory (Screenplay)

New ioctl: GET_ONE_EVENT

  • Add ioctl

  • Wonder what the output parameter could be ⟶ discussion

    • An event, obviously

    • struct my_event has list_head member ⟶ only valid in kernel

    • Extract user-relevant data into misc.h: struct my_event is for user, struct my_event_node is for kernel

Getting One Event

Start out like so …

case MY_GET_ONE_EVENT: {
    if (dev->events.nevents > 0) {
        ...
    }
}
  • race condition

  • ⟶ new method bool my_device_get_one_event()

    • ⟶ new method bool my_event_get_one_event()

copy_to_user()

  • Draw diagram, user space memory

  • Use copy_to_user() to transfer event to userspace

    • -EFAULT

Userspace Test Program

  • trivial