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 8448649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:29:08+00:00 2026-06-10T10:29:08+00:00

Structures involved are like the following. struct node { int a; int b; }

  • 0

Structures involved are like the following.
struct node {
int a;
int b;
}

struct ioctl_node {
    struct node **ptr;
    int         count; //Stores the no of pointers this ptr is pointing to.
};

In user space, I have populated a structure of ioctl_node with count = 3.
And ptr[0] and ptr[2] is pointing to two structs of type node, whereas ptr[1] is NULL. I want this to be passed to kernel.
I have issued ioctl call to pass this info from user space to kernel space.

I did the following in kernel space.

struct ioctl_node k_node;

copy_from_user(&k_node, arg, sizeof(struct ioctl_node)) //arg is the source

//k_node.count is showing the right value what I have set in the user space.

struct node *tmp = NULL;

I then did, copy_from_user(&tmp, k_node.ptr, sizeof(struct node *) and this call is also returning success.
But, I am having difficulty, in copying the full contents of **ptr properly in kernel space.
Can anybody plese help, how can I be able to do that. How should I do the next copy_from_user to copy all the contents. I tried, but its giving copy error.

  • 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-06-10T10:29:09+00:00Added an answer on June 10, 2026 at 10:29 am

    copy_from_user copies one block of consecutive bytes from user space to kernel space. You’ll need to first copy the struct ioctl_node, then copy the pointers to individual nodes, then copy the struct node‘s in a loop. Be sure to allocate the right amount of memory. Since you know the number of nodes in advance, you can allocate an array of them.

    struct node_data {
        size_t node_count;
        struct nodes *nodes;
    };
    struct node_data *read_nodes(struct ioctl_node_user_pointer *arg)
    {
        struct node_data *nd = NULL;
        struct ioctl_node kin = {0};
        struct node *node_user_pointers = NULL;
        int i;
        int err;
        /* Step 1: retrieve the root node */
        nd = kmalloc(sizeof(*nd), GFP_KERNEL);
        if (!nd) {
            err = -ENOMEM;
            goto error;
        }
        if (copy_from_user(ioctl_node_user_pointer, &kin, sizeof(kin))) {
            err = -EFAULT;
            goto error;
        }
        if (kin->count < 0 || kin->count > ((size_t)-1)/sizeof(*nodes)) {
            err = -EINVAL;
            goto error;
        }
        nd->node_count = kin.count;
        /* Step 2: retrieve the pointers to individual nodes */
        node_user_pointers = kmalloc(sizeof(*node_user_pointers) * nd->node_count, GFP_KERNEL);
        if (node_user_pointers) {
            err = -ENOMEM;
            goto error;
        }
        if (copy_from_user(kin->nodes, node_user_pointers, sizeof(*node_user_pointers) * nd->node_count)) {
            err = -EFAULT;
            goto error;
        }
        /* Step 3: retrieve the nodes themselves */
        nd->nodes = kmalloc(sizeof(*nodes) * nd->node_count, GFP_KERNEL);
        if (!nd->nodes) {
            err = -ENOMEM;
            goto error;
        }
        for (i = 0; i < head.count; i++) {
            if (copy_from_user(node_user_pointers[i], nd->nodes + i, sizeof(nd->nodes[0]))) {
                err = -EFAULT;
                goto error;
            }
        }
        kfree(node_user_pointers);
        return nd;
    error:
        if (nd) {
            kfree(nd->nodes);
            kfree(nd);
        }
        kfree(node_user_pointers);
        return ERR_PTR(err);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I structures like the following typedef struct { char *ptr; size_t used; size_t size;
I have some C structures related to a 'list' data structure. They look like
EDIT following resolution, this has been substantially edited to dump irrelevant detail and explain
Say I have a class, something like the following; class MyClass { public: MyClass();
So I've always developed PHP pages like this: <?php goes at the top, ?>
I would like to understand the overall process involved in compilation and execution of
My intended program flow would look like the following if it were possible: typedef
In a project I am involved in we have the following hardware setup: Linux
This seems like a common problem, but I'm unable find an adequate solution. I'm
I have a xml file roughly like this: <batch> <header> <headerStuff /> </header> <contents>

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.