LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   iov_base in iovec structure (http://www.linuxquestions.org/questions/linux-kernel-70/iov_base-in-iovec-structure-4175436065/)

s.kr 11-07-2012 06:42 AM

iov_base in iovec structure
 
Hello!


There is a structure: iovec, contains user data in the kernel source.

I am trying to print data witch iov_base pointer points to(iov has iovec structure):

printk(KERN_INFO "Data is: %d", **((int**)iov.iov_base));

The problem is that I can see data smaller than 5 character(not in a normal way in dmesg messages) but, for data greater than 5 characters segmentation fault happens and I can not access to all of it.

I can not understand the problem! Do you have any idea?

Im going to print all user data.


with many thanks

zishan.shaikh 11-20-2012 03:27 AM

Try copying it into some temporary string upto iov_len characters & then print the string itself.

Regards,
Zishan Shaikh

sundialsvcs 11-20-2012 07:25 AM

Bear in mind the potential issue of null-terminated strings: never, in my opinion, appropriate for kernel programming. You should copy the data into a separate buffer, specifying a maximum length to be copied and ensuring that the buffer is properly terminated. Print e.g. from that.

s.kr 11-21-2012 03:15 AM

Thanks for reply.

I did that as you said:

**************************************
int data[iov.iov_len];
int i;

//zero the content
for (i=0;i<iov.iov_len;i++)
data[i]=0;

//fill data
data[i]=(*((int**)iov.iov_base))[i];

//print data
for (i=0;i<iov.iov_len;i++)
printk("%d",data[i]);
**************************************

But unfortunately nothing changes!

I get this message with typing only one character "A" in a file names 'sample':

#####################################
File Name to Write: sampleKilled
root@sk:/mnt# M-D DOS Format M-A Append M-B Backup File
Message from syslogd@sk at Nov 21 04:02:30 ...nd
kernel:[ 7781.177092] Oops: 0000 [#3] SMP

Message from syslogd@sk at Nov 21 04:02:30 ...
kernel:[ 7781.177095] last sysfs file: /sys/devices/virtual/mtd/mtd0/mtdblock0/queue/hw_sector_size

Message from syslogd@sk at Nov 21 04:02:30 ...
kernel:[ 7781.177202] Stack:

Message from syslogd@sk at Nov 21 04:02:30 ...
kernel:[ 7781.177217] Call Trace:

Message from syslogd@sk at Nov 21 04:02:30 ...
kernel:[ 7781.177252] Code: ff c3 e8 59 d9 fa e0 48 63 c3 48 3b 45 b8 72 e3 48 c7 c7 26 a6 35 a0 31 c0 e8 42 d9 fa e0 31 c9 eb 10 48 8b 45 b0 ff c1 48 8b 00 <8b> 04 90 41 89 04 94 48 63 d1 48 3b 55 b8 72 e7 48 c7 c7 e8 aa

Message from syslogd@sk at Nov 21 04:02:30 ...
kernel:[ 7781.177293] CR2: 0000000000000a41
######################################

and also get this one while typing more characters(more than 5):

######################################
File Name to Write: sampleSegmentation fault
root@sk:/mnt# M-D DOS Format M-A Append M-B Backup File
Message from syslogd@sk at Nov 21 04:08:54 ...nd
kernel:[ 8163.939796] general protection fault: 0000 [#5] SMP

Message from syslogd@sk at Nov 21 04:08:54 ...
kernel:[ 8163.939800] last sysfs file: /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq

Message from syslogd@sk at Nov 21 04:08:54 ...
kernel:[ 8163.939909] Stack:

Message from syslogd@sk at Nov 21 04:08:54 ...
kernel:[ 8163.939923] Call Trace:

Message from syslogd@sk at Nov 21 04:08:54 ...
kernel:[ 8163.939959] Code: ff c3 e8 59 d9 fa e0 48 63 c3 48 3b 45 b8 72 e3 48 c7 c7 26 a6 35 a0 31 c0 e8 42 d9 fa e0 31 c9 eb 10 48 8b 45 b0 ff c1 48 8b 00 <8b> 04 90 41 89 04 94 48 63 d1 48 3b 55 b8 72 e7 48 c7 c7 e8 aa


######################################

Do you know what is the problem and what I have to do?



Thanks.

small_rz 11-21-2012 03:22 AM

Hello
I am trying to install ns-2.28 on redhat 9 but I get this error:tk8.4.5 make faild! existing...
How can I fix it?
Thanks a lot

kakaka 12-11-2012 12:52 AM

Hi s.kr !

This is C language code, yes?


Quote:

Originally Posted by s.kr (Post 4833859)

[...]

int data[iov.iov_len];
int i;

//zero the content
for (i=0;i<iov.iov_len;i++)
data[i]=0;

//fill data
data[i]=(*((int**)iov.iov_base))[i];

//print data
for (i=0;i<iov.iov_len;i++)
printk("%d",data[i]);

[...]

You don't show this code:
Quote:

//fill data
data[i]=(*((int**)iov.iov_base))[i];
as being in a loop. Is it inside a loop? Or did you only intend to copy only as many bytes as fit inside one int on the processor that's being used?

Maybe this C code will show you what I mean:

Code:

# include <stdio.h>

# define IOV_LEN  20

int main(  int ac ,  char *av[]  )
{

    char iov_base[IOV_LEN] = "ME WANT CORE DUMP!" ;
    int data[IOV_LEN] ;
    int i ;

    printf(  "sizeof(iov_base)=%d\n", sizeof(iov_base)  ) ;
    printf(  "sizeof(\"ME WANT CORE DUMP!\")=%d\n", sizeof("ME WANT CORE DUMP!")  ) ;
    printf(  "sizeof(data)=%d\n", sizeof(data)  ) ;
    printf(  "sizeof(i)=%d\n", sizeof(i)  ) ;


    //zero the content
    for (  i=0 ;  i<IOV_LEN ;  i++  )
        data[i] = 0 ;

    printf(  "i = %d\n" ,  i  ) ;

    //fill data
    data[i] = ( *( (int**) iov_base ) )[i] ;

    printf(  "Executed assignment for filling data\n"  ) ;

    //print data
    for (  i=0 ;  i < IOV_LEN ;  i++  )
        printf(  "%d\n", data[i]  ) ;

    printf(  "Executed loop to print data\n"  ) ;

}

I'm expecting it will crash before it finishes executing the assignment statement. So we'll never see the message saying that it executed the assignment statement.

Here's the output when I run the compiled program:

Code:

sizeof(iov_base)=20
sizeof("ME WANT CORE DUMP!")=19
sizeof(data)=80
sizeof(i)=4
i = 20
Segmentation fault

When means it crashed while trying to execute the assignment statement.

Hope this helps.


All times are GMT -5. The time now is 03:34 PM.