Solved

Using file operations in kernel level: llseek

Posted on 2003-11-23
3
552 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 76
Shell script awk command 2 108
mysql server issue in linux server 5 64
Linux 10 108
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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 …

832 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