Solved

Syscall from module

Posted on 2001-07-17
8
237 Views
Last Modified: 2008-01-16
Hi

I want to be abe to write to a file from a driver module - loaded into the kernel ....

I tried this
char buffer[6]="sunny";

int fd = sys_open(filename, 1 , 0)
sys_write(fd, buffer, sizeof(buffer));

and nothing happens. "sunny" isnot written to filename

Can somebody plsssss helppppppppp --I am a novice kernel hacker on a deadline
0
Comment
Question by:sunny447492
8 Comments
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
// add
fsync(fd);
close(fd);
0
 

Author Comment

by:sunny447492
Comment Utility
Nopes it didnt work
0
 
LVL 5

Expert Comment

by:bryanh
Comment Utility
You don't mention a return code from sys_write(), and the code you show doesn't even get it.

One problem with your code is that the "buffer" argument to sys_write() is an address in the user address space, whereas your buffer is in the kernel address space.  You have to use get_ds() and set_ds() to set the user address space to the kernel address space while sys_write() runs.

Incidentally, people usually go in a layer lower than sys_open/sys_write and call filp_open() and file->f_op->write().  In fact, in my experience the sys_* system call handlers aren't exported for use by loadable kernel modules.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:sunny447492
Comment Utility
Hi Bryanh,

Thanks for your reply. I had come across an article writtn by Rubini about using get_ds() and set_ds() and I even tried it but was not successful. Would you be able to provide a code snippet thats tested to do such a call -
? I can then give you the points :>

Thanks

Regards,

Sunny
0
 

Author Comment

by:sunny447492
Comment Utility
Hi Bryanh,

Thanks for your reply. I had come across an article writtn by Rubini about using get_ds() and set_ds() and I even tried it but was not successful. Would you be able to provide a code snippet thats tested to do such a call -
? I can then give you the points :>

Thanks

Regards,

Sunny
0
 
LVL 5

Accepted Solution

by:
bryanh earned 200 total points
Comment Utility
I've put an example program at ftp://giraffe-data.com/pub/filewrite.c  .  You can contact me at bryanh@giraffe-data.com.  This file is a loadable kernel module -- just compile it and insmod it to see it go.  It works for me.
0
 
LVL 20

Expert Comment

by:jmcg
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#6318081}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

9 Experts available now in Live!

Get 1:1 Help Now