编译内核后kernel panic,求助!

发布于 2022-10-15 04:26:07 字数 884 浏览 23 评论 0

改写了security下的Root_plug.c 然后向想将其编译入内核,以前编译成功过。这次想改进一下,改进之后编译内核时可以通过,但是reboot之后就会报错:

无标题.jpg (138.04 KB, 下载次数: 17)

下载附件

kernel panic

2011-06-13 17:11 上传

有没有哪位遇到过类似情况的?请教如何解决?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

海拔太高太耀眼 2022-10-22 04:26:07

等答案!  改的啥!

独享拥抱 2022-10-22 04:26:07

回复 2# taojie2000

char* getfullpath(struct dentry *dentry)
{
        char *path=NULL, *start=NULL;
    char *fullpath=NULL;
    const struct path *ppath = NULL;
    struct fs_struct *fs = current->fs;
    fullpath = kmalloc(PATH_MAX,GFP_KERNEL);
    if(!fullpath) goto OUT;
    memset(fullpath,0,PATH_MAX);

    path = kmalloc(PATH_MAX,GFP_KERNEL);
    if(!path) {
        kfree(fullpath);
        goto OUT;
    }

    //get the dentry and vfsmnt
    read_lock(&fs->lock);
         ppath =&fs->pwd;
         read_unlock(&fs->lock);
         
    //get the path
    start = d_path(ppath,path,PATH_MAX);
    strcat(fullpath,start);
    kfree(path);

OUT:
    return fullpath;
}  
改之后
char* getfullpath(struct dentry *dentry)
{
        char *path=NULL, *start=NULL;
    char *fullpath=NULL;
    const struct path *ppath = NULL;
    const unsigned char *name=dentry->d_name.name;//新增
    struct fs_struct *fs = current->fs;
    char *name2=(char *)name;//新增
    fullpath = kmalloc(PATH_MAX,GFP_KERNEL);
    if(!fullpath) goto OUT;
    memset(fullpath,0,PATH_MAX);

    path = kmalloc(PATH_MAX,GFP_KERNEL);
    if(!path) {
        kfree(fullpath);
        goto OUT;
    }

    //get the dentry and vfsmnt
    read_lock(&fs->lock);
         ppath =&fs->pwd;
         read_unlock(&fs->lock);
         
    //get the path
    start = d_path(ppath,path,PATH_MAX);
    strcat(fullpath,start);

    strcat(fullpath,"/");//新增
    strcat(fullpath,name2);//新增
    kfree(path);

OUT:
    return fullpath;
}

这个函数的作用是获得当前DENTRY 的绝对路径,原来那个就没有用到参数dentry,而只用CURRENT提取。提取出来的是dentry所在的目录并不包含dentry对应的文件名,所以我就想从传递来的dentry结构里提取出名字后加在路径的最后,我在想是不是 name和name2都没有kmalloc引起的。

酒与心事 2022-10-22 04:26:07

自己顶 希望大家都来看看

你的背包 2022-10-22 04:26:07

自己顶 不要沉

北恋 2022-10-22 04:26:07

没有前因后果,不知道怎么帮你分析
从 OOPS 信息上看,问题出在 dongyu_delete 函数偏移 0x0e 的指令位置

酒几许 2022-10-22 04:26:07

本帖最后由 1jjk 于 2011-06-14 11:07 编辑

分析分析

Can you post here output of disassemble of getfullpath? You can get
that by running gdb on vmlinux and then doing 'disass getfullpath'.

欲拥i 2022-10-22 04:26:07

回复 6# platinum

    以下是我这个root_plug的源码:

  1. /*
  2. * Root Plug sample LSM module
  3. *
  4. * Originally written for a Linux Journal.
  5. *
  6. * Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
  7. *
  8. * Prevents any programs running with egid == 0 if a specific USB device
  9. * is not present in the system.  Yes, it can be gotten around, but is a
  10. * nice starting point for people to play with, and learn the LSM
  11. * interface.
  12. *
  13. * If you want to turn this into something with a semblance of security,
  14. * you need to hook the task_* functions also.
  15. *
  16. * See http://www.linuxjournal.com/article.php?sid=6279 for more information
  17. * about this code.
  18. *
  19. *        This program is free software; you can redistribute it and/or
  20. *        modify it under the terms of the GNU General Public License as
  21. *        published by the Free Software Foundation, version 2 of the
  22. *        License.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/security.h>
  27. #include <linux/moduleparam.h>
  28. #include <asm/current.h>
  29. #include <linux/fs_struct.h>
  30. #include <linux/mount.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/dcache.h>
  33. /* should we print out debug messages */
  34. static int debug = 0;
  35. module_param(debug, bool, 0600);
  36. #define MY_NAME "root_plug"
  37. #define root_dbg(fmt, arg...)                                        \
  38.         do {                                                        \
  39.                 if (debug)                                        \
  40.                         printk(KERN_DEBUG "%s: %s: " fmt ,        \
  41.                                 MY_NAME , __func__ ,         \
  42.                                 ## arg);                        \
  43.         } while (0)
  44. char* getfullpath(struct dentry *dentry)
  45. {
  46.         char *path=NULL, *start=NULL;
  47.     char *fullpath=NULL;
  48.     const struct path *ppath = NULL;
  49.          const unsigned char *name=NULL;dentry->d_name.name;
  50.     struct fs_struct *fs = current->fs;
  51.          char *name2=NULL;
  52.          name=dentry->d_name.name;
  53.          name2=(char *)name;
  54.     fullpath = kmalloc(PATH_MAX,GFP_KERNEL);
  55.     if(!fullpath) goto OUT;
  56.     memset(fullpath,0,PATH_MAX);
  57.     path = kmalloc(PATH_MAX,GFP_KERNEL);
  58.     if(!path) {
  59.         kfree(fullpath);
  60.         goto OUT;
  61.     }
  62.     //get the dentry and vfsmnt
  63.     read_lock(&fs->lock);
  64.          ppath =&fs->pwd;
  65.          read_unlock(&fs->lock);
  66.          
  67.     //get the path
  68.     start = d_path(ppath,path,PATH_MAX);
  69.     strcat(fullpath,start);
  70.     strcat(fullpath,"/");
  71.     strcat(fullpath,name2);
  72.     kfree(path);
  73. OUT:
  74.     return fullpath;
  75. }
  76. void putfullpath(char* fullpath)
  77. {
  78.   if(fullpath)
  79.     kfree(fullpath);
  80. }
  81. static int dongyu_inode_create (struct inode *inode, struct dentry *dentry,
  82.                                int mask)
  83. {
  84.         char* fullpath = NULL;
  85.         fullpath = getfullpath(dentry);
  86.    if(!fullpath){
  87.     printk("Get fullpath error!\n");
  88.     return 0;
  89.         }
  90.         printk(KERN_INFO"taskname:%s action:inode_create target:%s\n",current->comm,fullpath);
  91.         putfullpath(fullpath);       
  92.         return 0;
  93. }
  94. static int dongyu_inode_mkdir (struct inode *inode, struct dentry *dentry,
  95.                               int mask)
  96. {
  97.    char* fullpath = NULL;
  98.         fullpath = getfullpath(dentry);
  99.    if(!fullpath){
  100.     printk("Get fullpath error!\n");
  101.     return 0;
  102.         }
  103.         printk(KERN_INFO"taskname:%s action:inode_mkdir target:%s\n",current->comm,fullpath);
  104.         putfullpath(fullpath);       
  105.         return 0;
  106. }
  107. static int dongyu_inode_rmdir (struct inode *inode, struct dentry *dentry)
  108. {
  109.         char* fullpath = NULL;
  110.         fullpath = getfullpath(dentry);
  111.    if(!fullpath){
  112.     printk("Get fullpath error!\n");
  113.     return 0;
  114.         }
  115.         printk(KERN_INFO"taskname:%s action:inode_removedir target:%s\n",current->comm,fullpath);
  116.         putfullpath(fullpath);       
  117.         return 0;
  118. }
  119. static int dongyu_inode_rename (struct inode *old_inode,
  120.                                struct dentry *old_dentry,
  121.                                struct inode *new_inode,
  122.                                struct dentry *new_dentry)
  123. {
  124.         char* oldfullpath = NULL;
  125.         char* newfullpath = NULL;
  126.         oldfullpath = getfullpath(old_dentry);
  127.         newfullpath = getfullpath(new_dentry);
  128.    if(!oldfullpath||!newfullpath){
  129.     printk("Get fullpath error!\n");
  130.     return 0;
  131.         }
  132.         printk(KERN_INFO"taskname:%s action:inode_renamedir oldtarget:%s newtarget:%s\n",current->comm,oldfullpath,newfullpath);
  133.         putfullpath(oldfullpath);       
  134.         putfullpath(newfullpath);
  135.         return 0;
  136. }
  137. static void dongyu_delete (struct inode *inode)
  138. {
  139.         struct dentry *dentry = d_find_alias(inode);       
  140.         char* fullpath = NULL;
  141.         fullpath = getfullpath(dentry);
  142.    if(!fullpath){
  143.     printk("Get fullpath error!\n");
  144.     return ;
  145.         }
  146.         printk(KERN_INFO"taskname:%s action:inode_delete target:%s\n",current->comm,fullpath);
  147.         putfullpath(fullpath);       
  148.         return;
  149. }
  150. static int rootplug_bprm_check_security (struct linux_binprm *bprm)
  151. {
  152.         return 0;
  153. }
  154. static struct security_operations rootplug_security_ops = {
  155.         /* Use the capability functions for some of the hooks */
  156.         .ptrace_may_access =                cap_ptrace_may_access,
  157.         .ptrace_traceme =                cap_ptrace_traceme,
  158.         .capget =                        cap_capget,
  159.         .capset =                        cap_capset,
  160.         .capable =                        cap_capable,
  161.         .bprm_set_creds =                cap_bprm_set_creds,
  162.    .inode_create=                        dongyu_inode_create,
  163.         .inode_mkdir=                        dongyu_inode_mkdir,
  164.         .inode_rmdir=                        dongyu_inode_rmdir,
  165.         .inode_rename=                        dongyu_inode_rename,
  166.         .inode_delete=                        dongyu_delete,
  167.         .task_fix_setuid =                cap_task_fix_setuid,
  168.         .task_prctl =                        cap_task_prctl,
  169.         .bprm_check_security =                rootplug_bprm_check_security,
  170. };
  171. static int __init rootplug_init (void)
  172. {
  173.         /* register ourselves with the security framework */
  174.         if (register_security (&rootplug_security_ops)) {
  175.                 printk (KERN_INFO
  176.                         "Failure registering Root Plug module with the kernel\n");
  177.                         return -EINVAL;
  178.         }
  179.         printk (KERN_INFO "Root Plug module initialized\n");
  180.         return 0;
  181. }
  182. security_initcall (rootplug_init);

复制代码

时光是把杀猪刀 2022-10-22 04:26:07

本帖最后由 1jjk 于 2011-06-14 13:19 编辑

  1. struct dentry *d_find_alias(struct inode *inode)
  2. {
  3.     struct dentry *de = NULL;
  4.     if (!list_empty(&inode->i_dentry)) {
  5.         spin_lock(&inode->i_lock);
  6.         de = __d_find_alias(inode, 0);
  7.         spin_unlock(&inode->i_lock);
  8.     }   
  9.     return de;
  10. }

复制代码很明显,你没有check find的return,

不过最好还是把disassable后的打出来,分析一下

So要识趣 2022-10-22 04:26:07

应该就是楼上说的原因,以前返回值说不定就是空的,只是没人用,所以不报错。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文