Solved

Using file operations in kernel level: llseek

Posted on 2003-11-23
3
559 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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