The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

форумы  помощь  поиск  регистрация  майллист  ВХОД  слежка  RSS
"struct file"
Вариант для распечатки Архивированная нить - только для чтения! 
Пред. тема | След. тема 
Форумы Программирование под UNIX (Public)
Изначальное сообщение [Проследить за развитием треда]

"struct file"
Сообщение от FreeGL Искать по авторуВ закладки on 30-Мрт-03, 11:46  (MSK)
Привет! может мне ктото сказать каким образом или с помощью какой функции
можно связать структуру "struct file" с каким либо файлом, например "/etc/passwd",
я попробывал ниже приведенный код, но нечего не вышло:(

# cat m.c
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>

int fd, errno ;
struct file *tty_file ;

static inline _syscall2(int, open, const char *, pathname, int, flags) ;

int
init_module()
{
fd = open("/etc/passwd", 00) ;
tty_file = fget(fd) ;
printk("%d\n", tty_file->f_uid) ;
return 0 ;
}

void cleanup_module()
{
}
EOF

Компилю
# gcc -c m.c
загружаю
# insmod -f m.o

После чего модуль уходит в "segfault" с ощибкой "Упс"  и в "/var/log/messages" пишеться

Unable to handle kernel NULL pointer dereference at virtual address 0000004c
printing eip:
d08600bd
pgd entry c8834000: 0000000000000000
pmd entry c8834000: 0000000000000000
... pmd not present!
Oops: 0000
CPU:    0
EIP:    0010:[<d08600bd>]
EFLAGS: 00010282
eax: 00000000   ebx: d0860000   ecx: ffffffff
  edx: 00000000
esi: d0860080   edi: 00000000   ebp: c8833f14
  esp: c8833f04
ds: 0018   es: 0018   ss: 0018
Process insmod (pid: 1007, stackpage=c8833000)Mar 30 09:36:33 localhost kernel: Stack: c0229900 00000216 000042f9 c012972e 00000250 c0114aa8 c8832000 0804b500
       0807dc88 bfffca98 00000000 00000008 00000000 c8833f60 00000060 00000000
        c95f0000 00000154 00000060 00000001 c95f2000 ffffffea ca6e24e0 00000060
Call Trace: [<c012972e>] [<c0114aa8>] [<d085e000>] [<d0860060>] [<c0106f23>]
Code: ff 70 4c 68 4f 01 86 d0 e8 a2 3c 8b ef 83 c4 10 b8 00 00 00
Пример кода взят из Прака (там где описывался кейлогер под Линукс), только там код чуть другой
(но у меня с ним такиеже траблы)
"F1" please:)

  Рекомендовать в FAQ | Cообщить модератору | Наверх

 Оглавление

Индекс форумов | Темы | Пред. тема | След. тема
Сообщения по теме

1. "struct file"
Сообщение от genie emailИскать по авторуВ закладки on 31-Мрт-03, 02:20  (MSK)
You cannot call open() directly from the kernel, because of the incorrect memory mapping. You need to set FS to point to your DS, otherwise the code behind open() will try to do copy_from_user() which is incorrect. I can send you a bit of code I wrote a while ago when I needed this file capability in the driver.
  Рекомендовать в FAQ | Cообщить модератору | Наверх

2. "struct file"
Сообщение от genie emailИскать по авторуВ закладки on 01-Апр-03, 15:13  (MSK)
Vot ono:

#define MODULE
#include <linux/module.h>
#include <linux/mm.h>
#include <asm/segment.h>
#include <asm/uaccess.h>

int init_module(void)      
{
    mm_segment_t fs=get_fs();
    struct file *f;
    
    set_fs(KERNEL_DS);
    f=filp_open("/tmp/hello.world",O_CREAT,00700);
    printk("f returned: %p\n",f);
    if(f)
    {
ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
if(f->f_op && (write = f->f_op->write) != NULL)
    write(f,"aaa",3,&f->f_pos);
filp_close(f,0);
    }
    set_fs(fs);
}

void cleanup_module(coid)  { printk("Goodbye\n"); }

  Рекомендовать в FAQ | Cообщить модератору | Наверх

3. "struct file"
Сообщение от FreeGL Искать по авторуВ закладки on 01-Апр-03, 16:55  (MSK)
>Vot ono:
>
>#define MODULE
>#include <linux/module.h>
>#include <linux/mm.h>
>#include <asm/segment.h>
>#include <asm/uaccess.h>
>
>int init_module(void)
>{
>    mm_segment_t fs=get_fs();
>    struct file *f;
>
>    set_fs(KERNEL_DS);
>    f=filp_open("/tmp/hello.world",O_CREAT,00700);
>    printk("f returned: %p\n",f);
>    if(f)
>    {
> ssize_t (*write)(struct file *, const char *, size_t, loff_t *);
> if(f->f_op && (write = f->f_op->write) != NULL)
>     write(f,"aaa",3,&f->f_pos);
> filp_close(f,0);
>    }
>    set_fs(fs);
>}
>
>void cleanup_module(coid)  { printk("Goodbye\n"); }

10x for help!

  Рекомендовать в FAQ | Cообщить модератору | Наверх


Удалить

Индекс форумов | Темы | Пред. тема | След. тема
Пожалуйста, прежде чем написать сообщение, ознакомьтесь с данными рекомендациями.




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2025 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру