如何解决使用 call_usermodehelper API 从内核驱动程序调用 shell 脚本
我在 /system/bin/ 目录中有一个 shell 脚本(AutoStartSvc.sh),它具有可执行权限。 我想在从远程按一个键代码时从 IR 远程驱动程序触发这个 shell 脚本。我在远程驱动程序中使用“call_usermodehelper”API 来调用 shell 脚本来匹配 IR 密钥代码。
shell 脚本内容: ifconfig wlan0 192.168.23.1 up
IR 远程驱动程序更改:
int result=-1;
char* argv[] = {"/system/bin/sh","-c","/system/bin/DVBT2_WiFi_indoor_v11",NULL };
static char* envp[] = {"HOME=/","TERM=linux","PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin",NULL};
if(iscodematched() == 0) // checks the code match
{
free_irq(chip->irqno,chip);// call_usermodehelper won't work in interrupt mode so exit from the interrupt mode
printk("Key code matched. \n");
result = call_usermodehelper(argv[0],argv,envp,UMH_NO_WAIT);
printk("return value of call_usermodehelper: %d \n",result);
}
内核错误日志:
Key code matched.
[ 922.686115@2] type=1400 audit(1420080107.660:117): avc: denied { execute } for pid=7665 comm="kworker/u8:0" name="sh" dev="mmcblk0p12" ino=351 scontext=u:r:kernel:s0 tcontext=u:object_r:shell_exec:s0 tclass=file permissive=0
[ 922.667383@1] return value of call_usermodehelper: 0
我的试验: 这是 avc: denial 因为 android 的 sepolicy。为了解决这个问题,我在 android 源代码的 /system/sepolicy/kernel.te 中做了以下更改
#added this line:
allow kernel shell_exec:file { getattr open read execute execute_no_trans rx_file_perms };
#uncommented the following line
neverallow kernel { file_type fs_type -rootfs }:file { entrypoint execute_no_trans };
即使在 kernel.te 中进行了上述更改,也不会触发 shell 脚本没有服务拒绝但是这次没有服务拒绝消息消失。但是“call_usermodehelper”的返回值为零。 任何帮助表示赞赏。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。