函数源码

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source File:kernel\trace\bpf_trace.c Create Date:2022-07-27 13:45:16
首页 Copyright©Brick

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
       u32, size)
{
    /*
     * Ensure we're in user context which is safe for the helper to
     * run. This helper has no business in a kthread.
     *
     * access_ok() should prevent writing to non-user memory, but in
     * some situations (nommu, temporary switch, etc) access_ok() does
     * not provide enough validation, hence the check on KERNEL_DS.
     *
     * nmi_uaccess_okay() ensures the probe is not run in an interim
     * state, when the task or mm are switched. This is specifically
     * required to prevent the use of temporary mm.
     */
 
    if (unlikely(in_interrupt() ||
             current->flags & (PF_KTHREAD | PF_EXITING)))
        return -EPERM;
    if (unlikely(uaccess_kernel()))
        return -EPERM;
    if (unlikely(!nmi_uaccess_okay()))
        return -EPERM;
 
    return probe_user_write(unsafe_ptr, src, size);
}