Solved

write to userspace files in kernel

Posted on 2001-08-16
3
241 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
3 Comments
 
LVL 5

Accepted Solution

by:
bryanh earned 200 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

706 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