Solved

Using file operations in kernel level: llseek

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now