• KP Singh's avatar
    bpf: Add tests for task_local_storage · 9cde3bee
    KP Singh authored
    The test exercises the syscall based map operations by creating a pidfd
    for the current process.
    
    For verifying kernel / LSM functionality, the test implements a simple
    MAC policy which denies an executable from unlinking itself. The LSM
    program bprm_committed_creds sets a task_local_storage with a pointer to
    the inode. This is then used to detect if the task is trying to unlink
    itself in the inode_unlink LSM hook.
    
    The test copies /bin/rm to /tmp and executes it in a child thread with
    the intention of deleting itself. A successful test should prevent the
    the running executable from deleting itself.
    
    The bpf programs are also updated to call bpf_spin_{lock, unlock} to
    trigger the verfier checks for spin locks.
    
    The temporary file is cleaned up later in the test.
    Signed-off-by: default avatarKP Singh <kpsingh@google.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
    Link: https://lore.kernel.org/bpf/20201106103747.2780972-9-kpsingh@chromium.org
    9cde3bee
local_storage.c 3.98 KB