problem with copyin ( ) - HP UX

This is a discussion on problem with copyin ( ) - HP UX ; Hi all, I have the following structure framework. struct foo3 { char *name; int len ; }; struct foo3 { int type; char *name; int len ; }; Struct foo1 { union foo2 { struct foo3 *f3; struct foo4 *f4; ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: problem with copyin ( )

  1. problem with copyin ( )

    Hi all,

    I have the following structure framework.


    struct foo3 {
    char *name;
    int len ;
    };

    struct foo3 {
    int type;
    char *name;
    int len ;
    };

    Struct foo1 {

    union foo2 {
    struct foo3 *f3;
    struct foo4 *f4;
    }foo2;
    };

    in Main ()
    {

    struct foo1 f1;

    After populating f1, I passed it through an ioctl to the kernel.


    In the kerenel ....

    my_ioctl( )
    {
    struct foo1 v1;
    struct foo3 *v3;
    copyin (iocp->ioc_up, &v1, sizeof (struct foo1 ));
    f3 = allocated memory for this.
    copyin(v1.foo2.foo3,f3, sizeof(struct foo3));
    ...
    ...
    }


    The last copyin fails with a -1.

    Kindly help.

    Thanks,
    Sandeep.







    I fill in this structure and through ioctl

  2. Re: problem with copyin ( )

    Sandeep K Sinha wrote:
    > Hi all,
    >
    > I have the following structure framework.
    >
    >
    > struct foo3 {
    > char *name;
    > int len ;
    > };
    >
    > struct foo3 {
    > int type;
    > char *name;
    > int len ;
    > };


    Conflicting definitions for foo3 -- presumably one
    is foo4? Which one?

    >
    > Struct foo1 {
    >
    > union foo2 {
    > struct foo3 *f3;
    > struct foo4 *f4;
    > }foo2;
    > };
    >
    > in Main ()
    > {
    >
    > struct foo1 f1;
    >
    > After populating f1, I passed it through an ioctl to the kernel.


    Not that it might be important for us to see how f3 gets a value
    or anything..

    >
    >
    > In the kerenel ....


    (kernel)

    >
    > my_ioctl( )
    > {
    > struct foo1 v1;
    > struct foo3 *v3;


    Unused local v3, fyi.

    > copyin (iocp->ioc_up, &v1, sizeof (struct foo1 ));
    > f3 = allocated memory for this.
    > copyin(v1.foo2.foo3,f3, sizeof(struct foo3));


    Syntax error. Union foo2 has no field foo3. (Did you
    mean f3 here?)

    Barring what I _think_ you meant, some details regarding is
    this a 32-bit to 64-bit conversion upcall (32-bit user to
    64-bit kernel), the values of f3 and f4 in foo2 at the time
    of the ioctl compared with the values see in v1 after the
    first copyin() would be where I'd start. There isn't enough
    here to really be sure, but my bet is that you're trying to
    read from a bad address in user space on the second copyin().
    [Actual compilable code stripped down to the simplest case
    would be nice here].

    Don

    > ..
    > ..
    > }
    >
    >
    > The last copyin fails with a -1.
    >


  3. Re: problem with copyin ( )

    On May 28, 1:25 pm, Sandeep K Sinha wrote:
    > Hi all,
    >
    > I have the following structure framework.
    >
    > struct foo3 {
    > char *name;
    > int len ;
    >
    > };
    >
    > struct foo3 {
    > int type;
    > char *name;
    > int len ;
    >
    > };
    >
    > Struct foo1 {
    >
    > union foo2 {
    > struct foo3 *f3;
    > struct foo4 *f4;
    > }foo2;
    > };
    >
    > in Main ()
    > {
    >
    > struct foo1 f1;
    >
    > After populating f1, I passed it through an ioctl to the kernel.
    >
    > In the kerenel ....
    >
    > my_ioctl( )
    > {
    > struct foo1 v1;
    > struct foo3 *v3;
    > copyin (iocp->ioc_up, &v1, sizeof (struct foo1 ));
    > f3 = allocated memory for this.
    > copyin(v1.foo2.foo3,f3, sizeof(struct foo3));
    > ..
    > ..
    >
    > }
    >
    > The last copyin fails with a -1.
    >
    > Kindly help.
    >
    > Thanks,
    > Sandeep.
    >
    > I fill in this structure and through ioctl


    Sorry for my previous mail. I was in a hurry so lots of typos and all
    that.

    Here is the actual code :

    struct voo1 {
    char *src;
    int len;
    };

    struct voo2 {
    char flag;
    char *dest;
    int len;
    };



    struct foo {
    int cmd;
    union str {
    struct voo1 *v1;
    struct voo2 *v2;

    } str;
    };

    Now, In user space I allocate struct foo f1;
    And invoke a ioctl on some device, with f1 as one of the parameters.

    In kernel :

    struct foo nsbuf;
    struct voo1 *v1;
    if (copyin(iocp->ioc_up, &nsbuf, sizeof (struct foo))) {
    return EFAULT;
    }
    v1= allocate memory ;

    if(copyin((void *)nsbuf.str.v1, v1, sizeof (struct v1 ))) {
    return EFAULT;
    <<<<<<<<--------------- This call fails.
    }

    Everything looks pretty OK here. But still its failing.
    This is just a code snippet. So, you might find some variables unused.

    Thanks & Regards,
    Sandeepksinha.

  4. Re: problem with copyin ( )

    Sandeep K Sinha wrote:
    > Sorry for my previous mail. I was in a hurry so lots of typos and all
    > that.
    >
    > Here is the actual code :
    >
    > struct voo1 {
    > char *src;
    > int len;
    > };
    >
    > struct voo2 {
    > char flag;
    > char *dest;
    > int len;
    > };
    >
    >
    >
    > struct foo {
    > int cmd;
    > union str {
    > struct voo1 *v1;
    > struct voo2 *v2;
    >
    > } str;
    > };
    >
    > Now, In user space I allocate struct foo f1;


    But what about v1 or v2? struct foo's union is just a union of the
    pointers. Great... so you have one of two types of pointers -- but
    if there isn't space allocated there, they are either garbage or NULL.

    > And invoke a ioctl on some device, with f1 as one of the parameters.
    >
    > In kernel :
    >
    > struct foo nsbuf;
    > struct voo1 *v1;
    > if (copyin(iocp->ioc_up, &nsbuf, sizeof (struct foo))) {
    > return EFAULT;
    > }
    > v1= allocate memory ;
    >
    > if(copyin((void *)nsbuf.str.v1, v1, sizeof (struct v1 ))) {
    > return EFAULT;
    > <<<<<<<<--------------- This call fails.


    Using the debugger or printf() to get nsbuf.str.v1's value would be
    nice. That had better match (minus the space id, of course) what you
    got in user space.

    Don

    > }
    >
    > Everything looks pretty OK here. But still its failing.
    > This is just a code snippet. So, you might find some variables unused.
    >


    --
    kernel, n:
    A part of an operating system that preserves the medieval traditions
    of sorcery and black art.

+ Reply to Thread