Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

write to userspace files in kernel

Posted on 2001-08-16
3
Medium Priority
?
258 Views
Last Modified: 2012-05-04
 I use kernel 2.4.2 ,add following code into
  ipchains_core.c, to record every packet :

  struct file *myfile;
  char log_file[100];
  char buf[100];
  ...
  strcpy(log_file,"/var/log/my.log");

  strcpy(buf,"This is a test!\n");
  ..
  myfile=filp_open(log_file,O_WRONLY|O_APPEND,0600);
  ...
  myfile->f_op->write(myfile,buf,strlen(buf),    \
                      &myfile- >f_pos);
  ...

  filp_close(myfile,NULL);
   
  ...
  when the new kernel go in work, code is called,
  this kernel breaks down at once!
  I don't know why this kernel breaks down,
  I need your help, please.

0
Comment
Question by:verybigcat
2 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 800 total points
ID: 6399472
This is a very common error.  The "buf" parameter is an address in user space.   You're passing an address in kernel space, which as a user space address is rather arbitrary.

You have to use get_ds() and set_ds() to make the kernel address space the user address space while the write operation runs.

Because this is a frequent question on EE, I have an example program at <ftp://giraffe-data.com/pub/filewrite.c> that shows this.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9915941
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:#6399472}

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

Industry Leaders: 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

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…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

824 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