Solved

Using file operations in kernel level: llseek

Posted on 2003-11-23
3
553 Views
Last Modified: 2008-02-26
Hello, I try to write a patch for exec() in linux kernel. I try to control if the binay has been patched before it is executed. So I try to patch the fs/exec.c file do_execve function.

I try to set the file position to N bytes from the beginning and read just 3 bytes from the file but while using llseek function I got segmentation fault.

Here is my code:

.....
                        mm_segment_t old_fs;
                        old_fs = get_fs();
                        set_fs(get_ds());
                        offset=bprm.file->f_op->llseek(bprm.file,VERIFYSIZE+1,0)
;
                        retval=offset;
                        if (retval < 0)
                                goto out;
                        retval=bprm.file->f_op->read(bprm.file,bufferAuth,3, &of
fset);
                        if (retval < 0)
                              goto out;
                        if ((retval=strcmp(CMPSTR,bufferAuth)) !=0 ){
                              goto out;
                              goto out;
                        }
                        set_fs(old_fs);
                        break;
                }
        }

VERIFYSIZE is the bytes that the file position must go.

Regards

--feyza

0
Comment
Question by:feyzataskazan
3 Comments
 
LVL 2

Expert Comment

by:asbharadwaj
ID: 9808797
May be f_op->llseek is NULL
Its a function pointer and may not have been set

Just check for this
0
 
LVL 24

Accepted Solution

by:
shivsa earned 500 total points
ID: 9808907
try to use lseek64, it is more safe than llseek.
0
 

Author Comment

by:feyzataskazan
ID: 9814443
Shivsa,
After your comment, I used sys_open, sys_lseek(lseek64), sys_read and sys_close functions and I have been succesfull. Thank you..

Before that I've controlled llseek function, it is not null, file position does not go to the correct offset adress..

Thank you for your answer asbharadwaj..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i create a game board using shell script 2 78
Software required to mount Linux LVM Volume 6 391
Percona cluster member randomly crash 15 534
awk file 6 77
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question