eclipse 编译内核模块_如何为我自己编写的内核模块禁用rmmod?(How to disable rmmod for my own written kernel module?)...

如何为我自己编写的内核模块禁用rmmod?(How to disable rmmod for my own written kernel module?)

如果用户进程正在使用内核模块,我希望另一个进程无法为该模块触发rmmod。 如何实现这种功能?

Linux内核编程中的-beginner。

If a user process is working with kernel module, I want that another process can't fire rmmod for that module. How to achieve this type of functionality?

-beginner in Linux kernel programming.

原文:https://stackoverflow.com/questions/9291314

更新时间:2019-11-13 14:04

最满意答案

rmmod 只能在refcount为零时卸载模块。

如果在连接用户进程时递增引用计数(并在断开连接时递减),那么你会没事的。

如果模块公开一个设备,或者作为一个文件系统安装,这应该自然处理 - 如果没有,我想它将取决于用户空间接口,但这从哪里开始寻找。

顺便说一句, lsmod将显示您的模块引用计数。 您可以检查在用户空间进程连接时它是否递增。

rmmod can only unload a module when the refcount is zero.

If the reference count is incremented when a user process is connected (and decremented when it disconnects), you'll be fine.

If the module exposes a device, or is mounted as a filesystem, this should be handled naturally - if not, I guess it'll depend on the userspace interface, but this where to start looking.

By the way, lsmod will show your module refcount. You can check whether it's incremented when the userspace process connects.

2012-02-15

相关问答

rmmod 只能在refcount为零时卸载模块。 如果在连接用户进程时递增引用计数(并在断开连接时递减),那么你会没事的。 如果模块公开一个设备,或者作为一个文件系统安装,这应该自然处理 - 如果没有,我想它将取决于用户空间接口,但这从哪里开始寻找。 顺便说一句, lsmod将显示您的模块引用计数。 您可以检查在用户空间进程连接时它是否递增。 rmmod can only unload a module when the refcount is zero. If the reference co

...

“Used by”列不仅显示引用模块的数量,还显示任何内核代码引用模块的次数。 对于文件系统和设备驱动程序,这通常在打开文件/设备时发生。 不跟踪这些引用的来源。 The "Used by" column shows not only the number of referencing modules, but the numer of times that any kernel code has taken a reference to the module. For file systems

...

我不确定,但是如果你在用户空间,那么切换到未使用的虚拟控制台,然后将键盘置于原始模式就足够了。 这将阻止通常切换回另一个虚拟控制台的组合键。 这不会禁用鼠标,但如果不是当前的VT,X应该忽略鼠标(只是确保gpm没有运行)。 如果启用了make-sysrq组合键,你还必须禁用它,因为有一个sysrq键可以使键盘退出原始模式,否则会解决这个问题。 编辑:如果您处于正常的任务上下文中,应该可以从内核空间执行所有这些操作。 我希望内核线程可以做到。 您可以从内核中打开文件和设备,这是不推荐的。 一个包含/

...

您可以使用call_usermodehelper函数。 请参阅LXR#1或LXR#2中如何使用它的示例。 UPD: argv[0] = "/bin/bash";

argv[1] = "-c";

argv[2] = "/usr/bin/free";

argv[3] = NULL;

envp[0] = "HOME=/";

envp[1] = "TERM=linux";

envp[2] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin";

envp[3] = NULL;

c

...

这个循环在哪个上下文中运行? 这是一个非常重要的问题。 如果init_module运行它,那么insmod进程永远不会结束,这是非常糟糕的。 如果某个系统调用运行它,那么系统调用将不会返回,它也将是坏的。 在这两种情况下,都没有办法杀死进程(甚至没有kill -9 )。 如果你在softIRQ处理程序(或者更糟的是,hardIRQ处理程序)中执行它,你将挂起系统。 如果你在专门用于此任务的内核线程中执行此操作,则有机会将其正确完成。 但是如果你不想完全占用CPU,你需要调用调度程序并让它运行其他任

...

您所描述的内容听起来就像您在printk的末尾没有包含换行符(“\ n”)。 由于您没有共享您的实际代码,因此您的insmod显然不是来自示例。 (insmod akmod.ko?为什么akmod?akmod是一个完全不同的东西。)调试这是一个完整的猜测。 What you are describing sounds like you did not include a newline ("\n") at the end of your printk. Since you didn't share

...

在su或sudo中将你的调用包装到模块中,并确保java进程以root身份运行 Wrap your call to modules in su or sudo and make sure that the java process in running as root

看看这些教程: http://www.tldp.org/HOWTO/Module-HOWTO/x839.html http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm 尝试添加: #define MODULE

#define LINUX

#define __KERNEL__

#include /* Needed for KERN_ALERT */

I have managed to work around t

...

使用INIT_LIST_HEAD(&birthday_list)而不是LIST_HEAD(birthday_list)有助于解决问题。 Using INIT_LIST_HEAD(&birthday_list) instead of LIST_HEAD(birthday_list) helps to solve the poblem.

从内核版本3.7开始,在内核配置文件中启用模块签名,您可以通过在内核源目录中运行make menuconfig并在Enable loadable kernel module菜单选项中取消选择Module Signature verification选项来禁用它。 在此之后,您将不得不重新编译内核。 Module signing is enabled within the kernel configuration file starting from kernel version 3.7, you

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值