LKM 运行 call_usermodehelper 来自 netfilter 钩子

LKM Running call_usermodehelper from netfilter hook

我正在尝试使用 call_usermodehelper 从 linux 5.10 中的 linux 内核模块执行 linux 终端命令,这是从 netfilter 挂钩中调用的,但据我所知,它是 运行ning 在 softirq 上下文中,我似乎无法以任何一种方式执行它。使用 'UMH_WAIT_EXEC' 我在发送我正在使用过滤器观察的 udp 数据包时得到 scheduling while atomic: nc/16886/0x00000101 ,如果我使用 'UMH_NO_WAIT' 我得到一个空引用。代码看起来像这样:

static unsigned int hfunc(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{          

        // --snipp--
    
        if (ntohs(udph->dest) == 1337) {
            
             char *argv[4];
             char *envp[4];
             argv[0] = "/bin/bash";
             argv[1] = "-c";
             argv[2] = "/bin/ls";
             argv[3] = NULL;

             envp[0] = "HOME=/";
             envp[1] = "TERM=linux";
             envp[2] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin";
             envp[3] = NULL;

             call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
   }
}

我如何 运行 从 netfilter 挂钩的软中断上下文中编写该程序?

我使用调度解决了这个问题。

static struct nf_hook_ops *nfho = NULL;

struct work_arg_struct {
    struct work_struct work;
    char *data;
};

static struct work_arg_struct my_work;

void bash_work_handler(struct work_struct *work){

    struct work_arg_struct *work_arg;
    work_arg = container_of(work, struct work_arg_struct, work);
    // --snip--

    call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
    return;
}
static unsigned int hfunc(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{   
  if (ntohs(udph->dest) == 1337) {
        // setup arguments
        schedule_work(&my_work.work);
             
   }
}

--snip--

static int __init module_init(void)
{
 //--snip--
 INIT_WORK(&my_work.work, bash_work_handler);
}