首页 > 解决方案 > pid_task() 导致内核恐慌,Linux 内核 5.4

问题描述

我正在尝试从内核空间向用户空间发送信号。我有以下代码,我看到内核恐慌。

[ 5230.132362] Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: prog_irq_handler+0x1d4/0x2cc [prog_mon]
[ 5230.146795] ---[ end Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in: prog_irq_handler+0x1d4/0x2cc 

在调试了一些之后,我发现恐慌的来源来自以下函数:

t = pid_task(find_pid_ns(id, &init_pid_ns), PIDTYPE_PID);

引用“t”的值似乎会导致异常,从而导致内核恐慌。

内核 5.4 wrt pid_task() 是否存在任何已知问题。任何帮助将不胜感激。

我的内核来自 yocto,它是:

分支 ti-linux-5.4.y

提交 6f3bf13d53820fc12432d7052744be2ee046fc92 (HEAD -> ti-linux-5.4.y) 合并:d2f658ed506d d5ef1ab82339 作者:LCPD 自动合并 lcpd_integration@list.ti.com 日期:2020 年 4 月 3 日星期五 10:50:48 -050

https://git.ti.com/cgit/ti-linux-kernel/ti-linux-kernel/

完整代码如下:

send_signal(int val, int id, int sig)
{
struct kernel_siginfo info;
struct task_struct *t;
int ret;

ret = 0;

if ((id > 0) && (sig > 0)) {
memset(&info, 0, sizeof(struct siginfo));
info.si_signo = sig;

/* Using SI_KERNEL here results in real_time data not getting delivered to the user space signal handler */
info.si_code = SI_QUEUE;

/* Real time signals may have 32 bits of data */
info.si_int = val;
info._sifields._rt._sigval.sival_int = val;
info.si_errno = 0;

rcu_read_lock();
t = pid_task(find_pid_ns(id, &init_pid_ns), PIDTYPE_PID);
if(t == NULL) {
printk(KERN_ERR "%s: Invalid user handler PID %d\n", module_name, id);
rcu_read_unlock();
return -ENODEV;
}
ret = send_sig_info(sig, &info, t);
rcu_read_unlock();

if (ret < 0)
printk(KERN_INFO "%s: Failed to signal with data %d to user space\n", module_name, val);
}

return ret
}

标签: linux-kernellinux-device-driver

解决方案


推荐阅读