Solved

Using file operations in kernel level: llseek

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

16 Experts available now in Live!

Get 1:1 Help Now