• Benjamin Tissoires's avatar
    HID: bpf: prevent infinite recursions with hid_hw_raw_requests hooks · 75839101
    Benjamin Tissoires authored
    When we attach a sleepable hook to hid_hw_raw_requests, we can (and in
    many cases should) call ourself hid_bpf_raw_request(), to actually fetch
    data from the device itself.
    
    However, this means that we might enter an infinite loop between
    hid_hw_raw_requests hooks and hid_bpf_hw_request() call.
    
    To prevent that, if a hid_bpf_hw_request() call is emitted, we prevent
    any new call of this kfunc by storing the information in the context.
    This way we can always trace/monitor/filter the incoming bpf requests,
    while preventing those loops to happen.
    
    I don't think exposing "from_bpf" is very interesting because while
    writing such a bpf program, you need to match at least the report number
    and/or the source of the call. So a blind "if there is a
    hid_hw_raw_request() call, I'm emitting another one" makes no real
    sense.
    
    Link: https://patch.msgid.link/20240626-hid_hw_req_bpf-v2-5-cfd60fb6c79f@kernel.orgAcked-by: default avatarJiri Kosina <jkosina@suse.com>
    Signed-off-by: default avatarBenjamin Tissoires <bentiss@kernel.org>
    75839101
hid_bpf_dispatch.h 509 Bytes