如果我这样做,--strip-debug或者--strip-unneeded我有.ko列出所有函数名称nm,如果我这样做,strip foo.ko我有一个拒绝加载的内核模块.
有没有人知道如何删除模块加载不需要的所有符号的快捷方式,以便人们无法对API进行反向工程设计?
PS:对于所有开源bigots传教士; 这是一般公众在任何情况下都不会使用的东西,因此不需要将问题变成GPL火焰战争.
我在使用我的机器上构建任何内核模块时遇到问题.每当我构建一个模块时,modpost总是说零模块:
MODPOST 0 modules
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我编写了一个测试模块(hello.c):
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}
module_init(hello_start);
module_exit(hello_end);
Run Code Online (Sandbox Code Playgroud)
这是模块的Makefile:
obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(shell pwd) clean
Run Code Online (Sandbox Code Playgroud)
当我在我的机器上构建它时,我得到以下输出:
make -C …Run Code Online (Sandbox Code Playgroud) 这个问题有两个问题:
1-如何从USB设备手动分离驱动程序并附加另一个驱动程序?例如,我有一个设备,当连接自动使用USB存储驱动程序.
// usbview输出
Vendor Id: xxxx
Product Id: xxxx
...
Number of Interfaces: 2
Interface Number: 0
Name: usb-storage
Number of Endpoints: 2
...
Interface Number: 1
Name: (none)
Number of Endpoints: 2
...
Run Code Online (Sandbox Code Playgroud)
我不想使用usb-storage驱动程序,因此我在主机上运行了一个应用程序,我在其中使用libusb库来分离usb存储驱动程序然后我声明了接口.然后,我可以在USB设备和主机Linux系统上运行的应用程序之间发送数据.
如何在应用程序外手动分离驱动程序?
2-如何自动分配驱动程序以附加到设备插件上.我目前有一个udev规则设置来自动设置设备权限.
SUBSYSTEM=="usb", ATTR{idVendor}=="xxxx", MODE="0666"
Run Code Online (Sandbox Code Playgroud)
我可以使用udev规则将驱动程序分配给USB设备上的特定接口吗?例如,如果我想在接口0而不是usb-storage上自动使用usbnet模块,那么在udev中是否可以使用?
谢谢,
(我对StackExchange如何使用它的不同网站或者它们都是一样的有点困惑.这是一个Linux问题所以它也发布在Unix和Linux上.请原谅我,如果它也不应该在这里发布,但是StackOverflow也处理Linux,所以...)
我正在为某个基于ARM的Linux板(实际上是一个自定义UART驱动程序)实现自定义串行总线驱动程序.该驱动程序应通过自定义协议启用与总线另一端的某个MCU的通信.驱动程序不会(实际上也不能)将其任何功能暴露给用户空间,也不可能在用户空间中实现它(因此,需要自定义驱动程序而不是使用库存TTY子系统).
司机将实现通信协议和UART读/写,并有一组更高级别的功能,导出到它的用户,让他们与MCU通信(例如read_register(),drive_gpios()所有这些东西).该模块只有一个用户.
呼叫模块必须等待操作的完成(前述read_register()和其他).我正在考虑使用信号量:用户模块将调用我的驱动程序的函数,它将启动传输并等待信号量; 我的驱动程序的IRQ处理程序将向MCU发送请求并读取答案,并在完成后发布到信号量,从而唤醒调用模块.但我对内核编程并不熟悉,而且我对众多可能的替代实现(tasklets?等待队列?)感到困惑.
问题是:我的基于信号量的方法是好还是太天真了?有哪些可能的选择?我可能会遗失任何陷阱吗?
这可能听起来像一个奇怪的问题,但当我去打开文件时:
int fd;
fd = open("/dev/somedevice", O_RDWR);
Run Code Online (Sandbox Code Playgroud)
我究竟回到了什么地方?我可以看到手册页说:
The open() function shall return a file descriptor for the named file that is the lowest file descriptor not currently open for that process
但是这样吗?它只是一个int或是否在幕后附加了数据?我问的原因是我找到了一些代码(Linux/C),我们从用户空间打开文件:
//User space code:
int fdC;
if ((fdC = open(DEVICE, O_RDWR)) < 0) {
printf("Error opening device %s (%s)\n", DEVICE, strerror(errno));
goto error_exit;
}
while (!fQuit) {
if ((nRet = read(fdC, &rx_message, 1)) > 0) {
Run Code Online (Sandbox Code Playgroud)
然后在内核端,该模块的文件操作(提供fd)映射读取到n_read()函数:
struct file_operations can_fops = {
owner: THIS_MODULE, …Run Code Online (Sandbox Code Playgroud) 我正在为linux编写以太网网络驱动程序.我想接收数据包,编辑并重新发送它们.我知道如何在packet_interceptor函数中编辑数据包,但是如何在此函数中丢弃传入的数据包?
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <net/sock.h>
struct packet_type my_proto;
int packet_interceptor(struct sk_buff *skb,
struct net_device *dev,
struct packet_type *pt,
struct net_device *orig_dev) {
// I dont want certain packets go to upper in net_devices for further processing.
// How can I drop sk_buff here?!
return 0;
}
static int hello_init( void ) {
printk(KERN_INFO "Hello, world!\n");
my_proto.type = htons(ETH_P_ALL);
my_proto.dev = NULL;
my_proto.func = packet_interceptor;
dev_add_pack(&my_proto);
return 0;
}
static void hello_exit(void) {
dev_remove_pack(&my_proto);
printk(KERN_INFO …Run Code Online (Sandbox Code Playgroud) c network-programming netfilter kernel-module linux-device-driver
我想用石灰倾倒我的手机内存,但在这个过程中我遇到了一些问题.1.Downloaded内核源码和构建,创建了zImage.
2.改变石灰的Makefile作为指导说,然后我做石灰.(尽管我的案例已创建lime.ko文件和lime-3.8.0-29-generic.ko文件,但在此步骤中出现问题)
3.命令./adb push~/lime-forensics/src/lime-3.8.0-29-generic.ko /sdcard/lime.ko成功推送
4.Rooted phone接受以root身份访问adb shell,并且lime insmod命令失败以转储内存
问题是当在adb shell类型命令insmod /sdcard/lime.ko"path =/sdcard/ram.lime format = lime"时出现此错误
# insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime>
insmod: init_module '/sdcard/lime.ko' failed (Exec format error).
Run Code Online (Sandbox Code Playgroud)
我犯了什么可能的错误以及如何解决此错误并继续?
我正在编写一个Linux内核模块(LKM)作为伪驱动程序 - 我无法弄清楚如何在LKM(wait.c)和用户级程序(user.c)之间进行IOCTL调用).
设备驱动程序的幻数是0xBF--LKM不与物理块/字符设备通信,它只是一个练习.据我所知,IOCTL调用KERN_IOCTL_CREATE_EVENT格式不正确且幻数不正确.
我试图使用的IOCTL调用是:
#include <sys/ioctl.h>
#define KERN_IOCTL_CREATE_EVENT _IOWR(WAIT_DEVICE_MAGIC, 1, int)
int main(){
int ret;
int fd;
fd = open("/dev/wait", 0);
if(fd < 0){
return -1;
}
ret = ioctl(fd, KERN_IOCTL_CREATE_EVENT, 0);
Run Code Online (Sandbox Code Playgroud)
错误:
[fail]: KERN_IOCTL_CREATE_EVENT: Inappropriate ioctl for device
Run Code Online (Sandbox Code Playgroud)
用户模式应用程序可以打开/关闭指向设备的文件描述符:/dev/wait但case/ switchstatement不接受IOCTL调用.有什么建议?
这是输出 # uname -a
Linux vagrant-ubuntu-trusty-64 3.13.11.11+ #1 SMP Mon Dec 1 20:50:23 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
wait.c
#include <linux/miscdevice.h>
#include <linux/moduleparam.h>
#include …Run Code Online (Sandbox Code Playgroud) 这个问题是关于linux内核4.10的.
加载树外LKM会导致内核打印警告:
module: loading out-of-tree module taints kernel.
这可以从这个check.c模块中得出:
if (!get_modinfo(info, "intree")) {
阅读get_modinfo它的接缝"intree"只是.ko文件中的魔法字符串livnig .
readelf在我的系统中找到的随机LKM上运行显示:
readelf -a imon.ko | grep intree
161: 00000000000006c0 9 OBJECT LOCAL DEFAULT 13 __UNIQUE_ID_intree1
在寻找intree简单的自定义hello_world时,LKM不会返回任何结果.
实际情况如此吗?
如何将某些模块标记为树内?是通过向模块添加宏(如MODULE_LICENCE),还是通过以特定方式或其他方式构建模块来完成的?
所以我正在尝试读取内核中的系统寄存器,最近我遇到了一些障碍。
在 ARM64 中,某些系统寄存器(例如OSECCR_EL1)并不总是被实现。如果它们被实施,那么尝试 mrs 指令就可以了——没有什么不好的事情发生。但是如果它们没有实现,那么内核会由于未定义的指令而抛出 Oops。
然而,这并非不合理,因为我在运行这mrs条指令时处于内核模块中,我没有看到从这个 oops 中恢复的简单方法,甚至没有认识到特定的系统寄存器读取将在第一名。
是否有任何简单的方法可以预先确定系统寄存器是否有效,或者至少以一种不会立即停止我的内核模块函数执行的方式处理内核 oops?