随笔分类 -  Linux驱动

使用call_usermodehelper在Linux内核中直接运行用户空间程序
摘要:by沈东良/良少http://blog.csdn.net/shendl2011.07.19系统初始化时kernel_init在内核态创建和运行应用程序以完成系统初始化 内核刚刚启动时,只有内核态的代码,后来在init过程中,在内核态运行了一些初始化系统的程序,才产生了工作在用户空间的进程。/* This is a non __init function. Force it to be noinline otherwise gcc736 * makes it inline to init() and it becomes part of init.text section737 */... 阅读全文
posted @ 2011-12-14 11:05 chingliuyu 阅读(506) 评论(0) 推荐(0)
installing kernel source code in Redhat or centos, kernel headers install
摘要:安装内核源码步骤installing kernel source code in Redhat or centos, kernel headers install 2011-03-10 15:15 Both CentOS and RHEL5 includes following packages: Kernel-headers : It includes the C header files th... 阅读全文
posted @ 2011-11-05 09:21 chingliuyu 阅读(1614) 评论(0) 推荐(0)
Linux Security Module的注册层次
摘要:LinuxSecurityModule的注册层次===================================================作者:ietf AT doit.com.cn所有源文件来自于linux kernel 2.6.20请在GNU Library General Public License下参考。引用请注明出处。===================================================selinux的出现着实扰乱了文件系统的进度,不过送算慢慢搞清楚了其中的来龙去脉。下面将通过2.6.20内核中的security代码进行一番简单的分析。该 阅读全文
posted @ 2011-09-21 15:50 chingliuyu 阅读(780) 评论(0) 推荐(0)
Security-Enhanced Linux(SELinux)
摘要:http://space.doit.com.cn/45811/viewspace-2096.htmlSecurity-EnhancedLinux(SELinux),这在linux2.6的内核中,是你不得不关注的对象。无论是文件系统还是网络接口,到处都能不经意的瞥到它幽灵般的身影。其钩子的实现方式严重的影响着对内核的正常阅读,为此,很有必要把这个幽灵就出来使之大白于天下。本篇文章内容系东拼西凑,绝非原创,特此声明。一、什么是selinux美国国家安全局(NationalSecurityAgency,NSA)长时间以来就关注大部分操作系统中受限的安全能力。毕竟,他们的工作之一就是要确保美国国防部使 阅读全文
posted @ 2011-09-21 15:46 chingliuyu 阅读(663) 评论(0) 推荐(0)
使用kprobes,截获execve系统调用,更谨慎的hook syscallTable的写法
摘要:转载,原文出处:http://blog.chinaunix.net/u/548/showart.php?id=386423关于截获execve等系统调用,很久以来存在一个问题:新函数不能直接调旧函数,否则导致stack不平衡,出错。曾经有高人用一串的汇编代码去平衡堆栈, 但对于偶们这些汇编菜鸟来说, 连阅读都很困难。而且, 好像gcc4.x下不支持 它使用的一种寻址方式了。这次使用kprobes来直接找do_execve,直接照搬sys_execve的实现代码。至于LICENSE的问题,谁用谁负责,我只是从技术角度上说可以这样做。(我的代码是GPL的)只截获了open和execve作为示例,其 阅读全文
posted @ 2011-09-16 17:02 chingliuyu 阅读(731) 评论(0) 推荐(0)
什麼是 "asmlinkage"?--syscall原型说明
摘要:http://www.jollen.org/blog/2006/10/_asmlinkage.html什麼是 "asmlinkage"?jollen發表於 October 26, 2006 4:15 PM有網友來信問到,kernel 裡的 system call 實作函數中(C 函數),為什麼每一個函數原型宣告的前面都有一個 "asmlinkage" 的字串?例如:asmlinkagelong sys_nice(int increment)"asmlinkage" 是在 i386 system call 實作中相當重要的一個 gcc 阅读全文
posted @ 2011-09-16 16:53 chingliuyu 阅读(204) 评论(0) 推荐(0)
linux内核中用d_path得到绝对路径名
摘要:http://blogold.chinaunix.net/u2/86590/showart_2185876.htmllinux内核中用d_path得到绝对路径名Linux 内核的d_path()函数转换目录数据结构(dentry结构)到ASCII路径名字,指定的目录数据结构(dentry结构)路径返回在一个缓冲区中,这个缓冲区得内核开发人员自己申请,自己释放。在linux2.4.18以前的内核中,指定的目录数据结构(dentry结构)路径返回在一段大小为PAGE_SIZE字节的固定缓冲区中。 这样就存在一个著名的d_path()路径截断漏洞,也就是如果提交的的目录数据结构(dentry结构)路 阅读全文
posted @ 2011-09-16 16:11 chingliuyu 阅读(3839) 评论(0) 推荐(0)
读LDD3,内存映射与DMA--PAGE_SHIFT,页帧号。
摘要:一,linux系统处理的地址类型1,用户虚拟地址:这是用户空间程序见到的常规地址。每个进程都有自己的虚拟地址空间2,物理地址物理地址用于处理器和系统内存之间3,总线地址总线地址在外围总线和内存这间使用4,内核逻辑地址内核逻辑地址组成了内核的常规地址空间。它一对一的映射部分或全部系统内存。在大多数架构中,内核逻辑地址与物理地址的不同,仅是它们之间存在一个固定的偏移。kmalloc 分配的就是逻辑地址,__get_free_pages?5,内核虚拟地址。它与内核逻辑地址的不同这处在于,内核虚拟地址不是一一对应到物理地址。内核虚拟地址空间是连续,但其映射的物理地址可以是离散的。内核逻辑地址是连续的, 阅读全文
posted @ 2011-09-09 09:44 chingliuyu 阅读(892) 评论(0) 推荐(0)
Linux Memory Mapping--mmap kernel 2.6
摘要:近几天有个项目需要实现用户层与内核共享内存。在前几篇博客中找到的均是kernel2.4 的。实现过程中,改的痛苦。对kernel源码才,勉强搞定。后来在此网站(http://www.scs.ch/~frey/linux/memorymap.html)发现原来有一个demo:#include <linux/config.h>#include <linux/version.h>#include <linux/init.h>#include <linux/module.h>#include <linux/fs.h>#include < 阅读全文
posted @ 2011-09-08 16:21 chingliuyu 阅读(507) 评论(0) 推荐(0)
Avoid memory copying between user space and kernel space
摘要:http://www.linuxforums.org/forum/kernel/158548-avoid-memory-copying-between-user-space-kernel-space.html1. you allocate memory in the kernel device driver2. You write a "mmap" function in the device driver3. This mmap file_ops function will do a remap_pfn when invoked by the user-space app 阅读全文
posted @ 2011-09-01 23:45 chingliuyu 阅读(393) 评论(0) 推荐(0)
Kernel Space - User Space Interfaces_Mmap
摘要:http://people.ee.ethz.ch/~arkeller/linux/kernel_user_space_howto.html#s8#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/fs.h>#include <linux/debugfs.h>#include <linux/mm.h> /* mmap related stuff */struct dentry *file1;struc 阅读全文
posted @ 2011-09-01 23:22 chingliuyu 阅读(464) 评论(0) 推荐(0)
利用mmap /dev/mem 读写Linux内存---root 权限
摘要:利用mmap /dev/mem 读写Linux内存分类: linux linux kernel2011-08-02 14:00 114人阅读 评论(1)收藏 举报使用 hexedit /dev/mem 可以显示所有物理内存中的信息。 运用mmap将/dev/mem map出来,然后直接对其读写可以实现用户空间的内核操作。以下是我写的一个sampleview plain#include<stdio.h>#include<unistd.h>#include<sys/mman.h>#include<sys/types.h>#include<sys 阅读全文
posted @ 2011-09-01 22:28 chingliuyu 阅读(1886) 评论(0) 推荐(0)
linux内核中读写文件
摘要:#include <linux/kernel.h>#include <linux/module.h>#include <linux/init.h>#include <linux/fs.h>#include <linux/string.h>#include <linux/mm.h>#include <linux/syscalls.h>#include <asm/unistd.h>#include <asm/uaccess.h>#define MY_FILE "/root/LogF 阅读全文
posted @ 2011-08-30 23:29 chingliuyu 阅读(634) 评论(0) 推荐(0)
Linux内核中读写文件数据的方法
摘要:Linux内核中读写文件数据的方法有时候需要在Linuxkernel--大多是在需要调试的驱动程序--中读写文件数据。在kernel中操作文件没有标准库可用,需要利用kernel的一些函数,这些函数主要有: filp_open() filp_close(), vfs_read()vfs_write(),set_fs(),get_fs()等,这些函数在linux/fs.h和asm/uaccess.h头文件中声明。下面介绍主要步骤:1. 打开文件filp_open()在kernel中可以打开文件,其原形如下:strcut file* filp_open(const char* filename, 阅读全文
posted @ 2011-08-30 23:17 chingliuyu 阅读(1165) 评论(0) 推荐(0)
linux驱动current,引用当前进程,及task_struct
摘要:尽管内核模块不象应用程序一样顺序执行, 内核做的大部分动作是代表一个特定进程的. 内核代码可以引用当前进程, 通过存取全局项 current, 它在 <asm/current.h> 中定义, 它产生一个指针指向结构 task_struct, 在 <linux/sched.h> 定义. current 指针指向当前在运行的进程. 在一个系统调用执行期间, 例如 open 或者 read, 当前进程是发出调用的进程. 内核代码可以通过使用 current 来使用进程特定的信息, 如果它需要这样.实际上, current 不真正地是一个全局变量. 支持 SMP 系统的需要强迫 阅读全文
posted @ 2011-08-29 13:38 chingliuyu 阅读(1223) 评论(0) 推荐(0)
控制寄存器 cr0,cr2,cr3
摘要:《Linux内核完全剖析—基于0.12内核》第4章80x86保护模式及其编程控制寄存器(CR0~CR3)用于控制和确定处理器的操作模式以及当前执行任务的特性,如图4-3所示。CR0中含有控制处理器操作模式和状态的系统控制标志;CR1保留不用;CR2含有导致页错误的线性地址;CR3中含有页目录表物理内存基地址,因此该寄存器也被称为页目录基地址寄存器PDBR(Page-Directory Base address Register)。(点击查看大图)图4-3 控制寄存器CR0~CR31.CR0中协处理器控制位CR0的4个位:扩展类型位ET、任务切换位TS、仿真位EM和数学存在位MP用于控制80x8 阅读全文
posted @ 2011-08-28 14:25 chingliuyu 阅读(2822) 评论(0) 推荐(0)
hook syscall table and clear cr0
摘要:一个简单的linux rootkit2011-01-17 14:58http://hi.baidu.com/shazi129/blog/item/53974aec2f0fc5c32e2e21f1.html下面提供一个相对完整的rootkit,在Fedora 12上编译运行成功。#include <linux/module.h>#include <linux/kernel.h>#include <asm/unistd.h>MODULE_LICENSE("GPL");// addr of sys_call_talbe = 0xc077e3a8 阅读全文
posted @ 2011-08-26 23:34 chingliuyu 阅读(525) 评论(0) 推荐(0)
get system call table in x86-64 Linux
摘要:http://bbs.chinaunix.net/thread-2143235-1-1.htmlLinux System Call Tablehttp://bluemaster.iu.hio.no/edu/dark/lin-asm/syscalls.html#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include <asm/uaccess.h>#include <asm/fcntl.h>#include <asm/unist 阅读全文
posted @ 2011-08-26 16:56 chingliuyu 阅读(906) 评论(0) 推荐(0)
linux 2.6.22-14 动态添加syscall - [Linux]
摘要:linux 2.6.22-14 动态添加syscall- [Linux]版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://technica.blogbus.com/logs/18945123.htmlLinux System Call Tablehttp://bluemaster.iu.hio.no/edu/dark/lin-asm/syscalls.html 这两天在做系统软件大作业,写一个kernel module,添加自己的syscall,实现通过访问内核全局数据获得关于所有进程和CPU等信息。作业本身不难,但是被kernel的各个版本搞死了,书上网上很多东西 阅读全文
posted @ 2011-08-26 13:48 chingliuyu 阅读(1000) 评论(0) 推荐(0)
seq_file实例实现ps:my_ps
摘要:richardhesidu发表于 2005-11-27 11:11贴一个我写的吧. 纯粹是为了讨论, 免得有人说我侵犯知识产权.#include <linux/init.h>#include <linux/module.h>#include <linux/proc_fs.h> //proc_fs#include <linux/seq_file.h> //seq_file#include <linux/fs.h> //struct file,struct inode#include <linux/sched.h> //nex 阅读全文
posted @ 2011-07-13 15:24 chingliuyu 阅读(232) 评论(0) 推荐(0)