Skip to content

lua-lsm: expose kernel file load ids#17

Closed
chenzongyao200127 wants to merge 2 commits into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm
Closed

lua-lsm: expose kernel file load ids#17
chenzongyao200127 wants to merge 2 commits into
openanolis:lua-lsmfrom
chenzongyao200127:lua-lsm

Conversation

@chenzongyao200127
Copy link
Copy Markdown
Collaborator

Summary

Expose kernel file/load ids to Lua policies and remove the redundant size
argument from post file data hooks.

The id arguments are now stable strings from the kernel helpers, so Lua policy
can compare readable values instead of enum numbers. The post hooks continue to
pass binary-safe Lua strings for the data buffer; policy can use the Lua length
operator when it needs the byte length.

Lua examples

return {
    name = "file-load-policy",
    author = "Zongyao Chen",
    license = "GPL",

    kernel_load_data = function(id, contents)
        if id == "kernel-module" and not contents then
            return false, errno.EPERM
        end
        return true
    end,

    kernel_post_load_data = function(data, id, description)
        if id ~= "kernel-module" then
            return true
        end

        if #data < 4 or data:sub(1, 4) ~= "\127ELF" then
            return false, errno.EPERM
        end

        return true
    end,

    kernel_read_file = function(file, id, contents)
        if id == "firmware" and not contents then
            return true
        end
        return true
    end,

    kernel_post_read_file = function(file, data, id)
        if id == "kernel-module" and #data >= 4 then
            return data:sub(1, 4) == "\127ELF"
        end
        return true
    end,
}

Testing

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

Lua-LSM left the id arguments for kernel_load_data(),
kernel_post_load_data(), kernel_read_file(), and kernel_post_read_file()
as nil placeholders.

Expose those ids as the stable strings returned by
kernel_load_data_id_str() and kernel_read_file_id_str(). Lua policies
can compare descriptive values such as "kernel-module" or
"security-policy" without depending on kernel enum numbers.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
kernel_post_load_data() and kernel_post_read_file() expose file data to
Lua as binary-safe strings. Lua policy can get the byte length with the
Lua length operator, so passing a separate size argument duplicates
information already carried by the string.

Drop the Lua-visible size argument from those hooks while keeping the
kernel hook signatures unchanged.

Signed-off-by: Zongyao Chen <ZongYao.Chen@linux.alibaba.com>
@chenzongyao200127
Copy link
Copy Markdown
Collaborator Author

Recreated this PR from the dedicated head branch : #18

@chenzongyao200127
Copy link
Copy Markdown
Collaborator Author

Recreated this PR from the dedicated head branch lua-lsm-file-load-ids: #18

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