Skip to content

audit: --no-trusted-code refuses a .vxlib of the package, and --audit lists it - #4624

Open
hiraditya wants to merge 1 commit into
fix/broken-vxlib-is-an-errorfrom
fix/no-trusted-code-refuses-vxlib
Open

hiraditya wants to merge 1 commit into
fix/broken-vxlib-is-an-errorfrom
fix/no-trusted-code-refuses-vxlib

Conversation

@hiraditya

Copy link
Copy Markdown
Collaborator

This PR sits on #4623 in a stack, and #4623 sits on #4619.

vxc reads a .vxlib in place of the .vx file beside it, and compiles the function bodies in it. The bodies are in the compiler's internal form, with no source positions and no mark for an unsafe block. So --no-trusted-code and --audit cannot read them, and a package could ship a .vxlib that got past both.

A list of trusted code inside the file would not help, because the author of the file writes the list.

What changed

  • --no-trusted-code pkg refuses each .vxlib of pkg with E5003:

    `--no-trusted-code pkg` refuses trusted code in the package `pkg`, and this is a `.vxlib` file. vxc cannot check the code in a `.vxlib`. To compile `pkg::evil` from its source, remove the file
    
  • A .vxlib is in pkg when its module name starts with pkg::, or when its file is in the folder of pkg.

  • --audit prints a line for each .vxlib that the program uses, and for the file that --link-interface names.

  • The loader now records the path of each .vxlib that it reads.

  • A parallel compile (-j) already gives each .vxlib to the normal compile, so the check covers it.

Tests

  • no_trusted_code_refuses_the_vxlib_files_of_its_package in src/hir/check/audit.rs.
  • tests/frontend/fail/no_trusted_code_refuses_a_vxlib_and_audit_names_it.vx, with a normal compile and with -j 2.
  • Each check was broken once on purpose, and the expected check failed.

The pre-commit hook passed on this commit, with #4619 and #4600 below it on main.

Decisions to check

  • One package folder can sit inside another, as outer/inner. Then --no-trusted-code outer refuses a .vxlib in inner. For a .vx file there, vxc: find the package of a module from the folder of its file #4612 gives only inner. So the .vxlib rule refuses more, never less.
  • --no-trusted-code does not refuse a --link-interface file, because that file has no package. --audit lists it.
  • The error reuses E5003 and adds no new code.

Fixes #4599

… lists it

vxc reads a .vxlib in place of the .vx file beside it, and compiles the
function bodies in it. The bodies are in the compiler's internal form,
with no source positions and no mark for an `unsafe` block. So the
checks for trusted code cannot read them, and a package could ship a
.vxlib that got past --no-trusted-code and --audit.

Now --no-trusted-code refuses each .vxlib of a package that it names,
with E5003. A .vxlib is in the package when its module name starts with
the package name, or when the file is in the package directory. --audit
prints a line for each .vxlib that the program uses, also for the file
that --link-interface names.

Fixes: #4599

This branch has not been deployed

No deployments
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