landlock-lsm / go-landlock

A Go library for the Linux Landlock sandboxing feature
MIT License
105 stars 7 forks source link

Add Landlock V2 support. #21

Closed gnoack closed 2 years ago

gnoack commented 2 years ago

This adds preliminary support for the upcoming Landlock ABI V2.

In addition to the existing file system access rights, it is now possible to move or link files across different directories with the new 'refer' access right. (For details, see Landlock documentation.)

Changes in the library:

The 'refer' access right for a path may only be specified handledAccessFS also contains it (i.e. by using the landlock.V2 config).

Upgrade path:

Callers using the landlock.V1.BestEffort().RestrictPaths(...) form can switch to use landlock.V2.BestEffort().RestrictPaths(...) with the same parameters instead. This change is compatible with before.

If you additionally desire to link or move files between directories, make sure that both directories have the "refer" access right, by calling .WithRefer() on their landlock.PathOpt objects. For example:

err := landlock.V2.RestrictPaths( landlock.RWDirs("/src", "/dest").WithRefer(), )

NOTE: Requiring the "refer" access right is incompatible with kernels before 5.19. If you want to use Landlock with earlier kernels, do not ask for that permission.

In particular, using "best effort mode" in combination with the refer right will downgrade to "doing nothing" on kernels below 5.19, as linking and moving files would otherwise not work:

err := landlock.V2.BestEffort().RestrictPaths( landlock.RWDirs("/src", "/dest").WithRefer(), )

Resolves #20.

gnoack commented 2 years ago

Ah, not ready for a pull request yet (oops I am not using github as much...)