Skip to content

lua-lsm: add userns support for capable hook#19

Open
chenzongyao200127 wants to merge 1 commit into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm-capable-userns
Open

lua-lsm: add userns support for capable hook#19
chenzongyao200127 wants to merge 1 commit into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm-capable-userns

Conversation

@chenzongyao200127
Copy link
Copy Markdown
Collaborator

Lua-LSM currently exposes capable() as a credential and capability check, but does not pass the hook's user namespace to Lua. That makes policy unable to distinguish a capability check in the initial user namespace from the same capability check in a nested namespace.

Expose user namespace objects to Lua, pass the capable hook namespace and option flags to Lua policy, and allow the existing capable helpers to check capabilities against an explicit namespace.

Example Lua policy:

local capability = require("capability")

return {
    name = "capable-userns-policy",
    author = "Zongyao Chen",
    license = "GPL",

    capable = function(cred, ns, cap, opts)
        if cap == capability.CAP_SYS_ADMIN and not ns:is_initial() then
            return false, errno.EPERM
        end
        return true
    end,

    ptrace_access_check = function(child, mode)
        local child_ns = child:userns()
        if not capability.capable(child_ns, "sys_ptrace") then
            return false, errno.EPERM
        end
        return true
    end,
}

Validation:

  • ./scripts/checkpatch.pl --git origin/lua-lsm..lua-lsm-capable-userns
  • git diff --check origin/lua-lsm..lua-lsm-capable-userns

Signed-off-by: Zongyao Chen ZongYao.Chen@linux.alibaba.com

Expose user namespace objects to Lua policy.

Pass the capable hook namespace and options to Lua.

Allow helpers to check capabilities in an explicit userns.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant