Skip to content

syscall: add Landlock support for execve() on Linux - #77630

Closed
gnoack wants to merge 3 commits into
golang:masterfrom
gnoack:landlock-exec
Closed

syscall: add Landlock support for execve() on Linux#77630
gnoack wants to merge 3 commits into
golang:masterfrom
gnoack:landlock-exec

Conversation

@gnoack

@gnoack gnoack commented Feb 15, 2026

Copy link
Copy Markdown
Contributor
  • Extend SysProcAttr on Linux to optionally store the ruleset FD and
    flag arguments for landlock_restrict_self(2).
  • Extend forkAndExecInChild1() to invoke the system call.
  • Add a flag for the prctl(PR_SET_NO_NEW_PRIVS) call as well,
    which is a prerequisite for unprivileged Landlock enforcement.
  • Define the necessary system call number constant unexported as
    _SYS_landlock_restrict_self.
  • The test case exercises the logic and demonstrates that it works
    (provided that the host Linux system has the Landlock LSM enabled).

As it is customary in forkAndExecInChild1(), system calls need to be
invoked with RawSyscall(), and their system call numbers are defined
in the same package. (Depending on internal/syscall/unix would create
an import loop.)

The Landlock API is described in
https://docs.kernel.org/userspace-api/landlock.html

Updates landlock-lsm/go-landlock#45
Fixes #68595

@gnoack

gnoack commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

For a rationale on why I updated these generated files that way, please see #68595 (comment) -- the previously suggested approach to put these constants in internal/syscall/unix was not feasible, and I am under the impression that re-generation of the full files in syscall is not intended at this point either?

I'm happy to implement it either way, please let me know what you prefer.

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: f4cd8f1) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: ed40a01) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gnoack
gnoack force-pushed the landlock-exec branch 2 times, most recently from 95c53bb to 6269c26 Compare February 16, 2026 12:59
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 6269c26) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 2:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 0f8ed8d) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 5:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 83e230e) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Austin Clements:

Patch Set 7:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 7:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 7b6b6b1) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 8:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 8:

(5 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

gnoack added 2 commits August 14, 2026 16:39
* In forkAndExecInChild1() on Linux, when SysProcAttr.NoNewPrivs is
  set, call prctl(PR_SET_NO_NEW_PRIVS).
* Define the necessary constant unexported as _PR_SET_NO_NEW_PRIVS.

When the no_new_privs flag is set, execve() does not grant additional
permissions through execve() (e.g., through the set-user-ID bit).

The no_new_privs flag is a prerequisite for enabling a Landlock policy
in an unprivileged (non-CAP_SYS_ADMIN) thread. The flag is documented
in PR_SET_NO_NEW_PRIVS(2const).

The name of the SysProcAttr.NoNewPrivs field is chosen to mirror the
naming in the Linux API.

Updates landlock-lsm/go-landlock#45
Updates golang#68595
* Extend SysProcAttr on Linux to optionally store the ruleset FD and
  flag arguments for landlock_restrict_self(2).
* Extend forkAndExecInChild1() to invoke the system call.
* The test case exercises the logic and demonstrates that it works
  (provided that the host Linux system has the Landlock LSM enabled).
* Define the necessary unexported _SYS_landlock_restrict_self constant.

As it is customary in forkAndExecInChild1(), system calls need to be
invoked with RawSyscall(), and their system call numbers are defined
in the same package. (Depending on internal/syscall/unix would create
an import loop.)

The Landlock API is described in
https://docs.kernel.org/userspace-api/landlock.html

Updates landlock-lsm/go-landlock#45
Fixes golang#68595
Proposal golang#68595 adds support for Landlock and PR_SET_NO_NEW_PRIVS and
introduces new syscall.SysProcAttr attributes which need to be listed
as additions to the stdlib interface.

Updates golang#68595
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 0ad8f08) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/745940.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Günther Noack:

Patch Set 8:

(5 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 9: Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 9:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-08-14T21:12:52Z","revision":"787bdb258c9865ffed178d271ebac02b6edd5de8"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 9: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_5206>)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 9:

This CL has passed the run


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 9: LUCI-TryBot-Result+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 9: Auto-Submit+1 Code-Review+2

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Dmitri Shuralyov:

Patch Set 9: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/745940.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Aug 17, 2026
* Extend SysProcAttr on Linux to optionally store the ruleset FD and
  flag arguments for landlock_restrict_self(2).
* Extend forkAndExecInChild1() to invoke the system call.
* Add a flag for the prctl(PR_SET_NO_NEW_PRIVS) call as well,
  which is a prerequisite for unprivileged Landlock enforcement.
* Define the necessary system call number constant unexported as
  _SYS_landlock_restrict_self.
* The test case exercises the logic and demonstrates that it works
  (provided that the host Linux system has the Landlock LSM enabled).

As it is customary in forkAndExecInChild1(), system calls need to be
invoked with RawSyscall(), and their system call numbers are defined
in the same package.  (Depending on internal/syscall/unix would create
an import loop.)

The Landlock API is described in
https://docs.kernel.org/userspace-api/landlock.html

Updates landlock-lsm/go-landlock#45
Fixes #68595

Change-Id: I5d0b141821bc1bcc0bfd1dd74f61751839c136e2
GitHub-Last-Rev: 0ad8f08
GitHub-Pull-Request: #77630
Reviewed-on: https://go-review.googlesource.com/c/go/+/745940
Reviewed-by: Günther Noack <gnoack@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
@gopherbot

Copy link
Copy Markdown
Contributor

This PR is being closed because golang.org/cl/745940 has been merged.

@gopherbot gopherbot closed this Aug 17, 2026
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.

syscall: support process sandboxing using Landlock on Linux

2 participants