Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3305134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:08:08+00:00 2026-05-17T21:08:08+00:00

Consider a Linux driver that uses get_user_pages (or get_page ) to map pages from

  • 0

Consider a Linux driver that uses get_user_pages (or get_page) to map pages from the calling process. The physical address of the pages are then passed to a hardware device. Both the process and the device may read and write to the pages until the parties decide to end the communication. In particular, the communication may continue using the pages after the system call that calls get_user_pages returns. The system call is in effect setting up a shared memory zone between the process and the hardware device.

I’m concerned about what happens if the process calls fork (it could be from another thread, and could happen either while the syscall that calls get_user_pages is in progress or later). In particular, if the parent writes to the shared memory area after the fork, what do I know about the underlying physical address (presumably changed due to copy-on-write)? I want to understand:

  1. what the kernel needs to do to defend against a potentially misbehaving process (I don’t want to create a security hole!);
  2. what restrictions the process need to obey so that the functionality of our driver works correctly (i.e. the physical memory remains mapped at the same address in the parent process).

    • Ideally, I would like the common case where the child process doesn’t use our driver at all (it probably calls exec almost immediately) to work.
    • Ideally, the parent process should not have to take any special steps when allocating the memory, as we have existing code that passes a stack-allocated buffer to the driver.
    • I’m aware of madvise with MADV_DONTFORK, and it would be ok to have the memory disappear from the child process’s space, but it’s not applicable to a stack-allocated buffer.
    • “Don’t use fork while you have a connection active with our driver” would be annoying, but acceptable as a last resort if point 1 is satisfied.

I’m willing to be pointed to documentation or source code. I’ve looked in particular at Linux Device Drivers, but didn’t find this issue addressed. RTFS applied to even just the relevant part of the kernel source is a bit overwhelming.

The kernel version is not completely fixed but is a recent one (let’s say ​≥2.6.26). We’re only targetting Arm platforms (single-processor so far but multicore is just round the corner), if it matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:08:08+00:00Added an answer on May 17, 2026 at 9:08 pm

    A fork() will not interfere with get_user_pages(): get_user_pages() will give you a struct page.

    You would need to kmap() it before being able to access it, and this mapping is done in kernel space, not userspace.

    EDIT: get_user_pages() touch the page table, but you should not be worried about this (it just make sure that the pages are mapped in userspace), and returns -EFAULT if it had any problem doing so.

    If you fork(), until copy-on-write is performed, the child will be able to see that page.
    Once copy-on-write is done (because the child/the driver/the parent wrote to the page through the userspace mapping — not the kernel kmap() the driver has), that page will no longer be shared. If you still hold a kmap() on the page (in the driver code), you will not be able to know if you are holding the parent page or the child’s.

    1) It’s not a security hole, because once you execve(), all of that is gone.

    2) When you fork() you want both process to be identical (It’s a fork !!). I would think that your design should allow both the parent and the child to access the driver. Execve() will flush everything.

    What about adding some functionality in userspace like:

     f = open("/dev/your_thing")
     mapping = mmap(f, ...)
    

    When mmap() is called on your device, you install a memory mapping, with special flags:
    http://os1a.cs.columbia.edu/lxr/source/include/linux/mm.h#071

    You have some interesting things like:

    #define VM_SHARED       0x00000008
    #define VM_LOCKED       0x00002000
    #define VM_DONTCOPY     0x00020000      /* Do not copy this vma on fork */
    

    VM_SHARED will disable copy on write
    VM_LOCKED will disable swapping on that page
    VM_DONTCOPY will tell the kernel not to copy the vma region on fork, although I don’t think it’s a good idea

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following 2 queries: select tblA.a,tblA.b,tblA.c,tblA.d from tblA where tblA.a not in (select
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the Oracle emp table. I'd like to get the employees with the top
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.