doing a cp in kernel space.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am doing a "cp" in kernel space.  That is, making a copy of a file (after
manipulating it a bit)  in kernel code.    I know it is bad design but the
purpose of the code is to learn so I don't really mind doing it.
1.  I am using the filp_open in kernel space (with O_CREAT|O_WRONLY).
2.  My source file is say a struct file *sourcefp;
3.  I want my destination file (say struct file *destfp) to have the same
rwx permissions as the source file.

using sourcefp->f_dentry->d_inode->i_mode as the mode (third parameter in
the filp_open) works fine.  Can someone point out the difference between
the i_mode in struct inode and the f_mode in the struct file.  Also is it
safe to use i_mode directly (without any macros)?  Do any macros exist for
doing this?


Another question I have is that is are there any security issues if I use
the following code blindly?
fs = get_fs();
set_fs(get_ds());

/* code here */

set_fs(fs);

I understand that the code above makes sure that kernel space pointers do
not fail in the verify_area function. Is it wrong (from a design point of
view) to use functions in the kernel space that expect user space pointers?
For the cp in kernel space part , I ended up using the read function
pointer of the struct file* -> file_operations.  Just wanted to know that
if I ever end up writing code that requires the get_fs/ set_fs as above,
then should I rethink the design?

BTW - The kernel level cp is only for learning purposes and not a part of
any design as such.

Thanks in advance.

-mohit

Regards,
Mohit Kalra

"It is a capital mistake to theorize before one has data.
Insensibly one begins to twist facts to suit theories, instead of theories
to suit facts."
-SH

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux