Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

security: Add landlock file restriction #486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nbouchinet-anssi
Copy link

@nbouchinet-anssi nbouchinet-anssi commented Aug 23, 2022

This patch adds a minimalist Landlock support to PAM which restricts the
SUID unix_chkpwd binary to a strict readonly access to /etc/shadow. The
goal here is to provide security in depth limiting access to the few
resources this program needs limiting uncontrolled privileged access to
the system.

The patch should evolve to support finer restrictions on other PAM
modules/binaries.

@ldv-alt
Copy link
Member

ldv-alt commented Aug 23, 2022

This binary uses getspnam_r interface to obtain the shadow entry, this doesn't necessarily imply access to /etc/shadow.
Would it be possible to enforce a read-only access to the whole filesystem?

@ldv-alt
Copy link
Member

ldv-alt commented Aug 23, 2022

By the way, your patch results to a code that doesn't even compile, this is not a good sign at all.

@l0kod
Copy link

l0kod commented Aug 24, 2022

I guess it misses a check for the header files (e.g. Suricata).

libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
libpam/include/security/pam_sandbox.h Outdated Show resolved Hide resolved
modules/pam_unix/unix_chkpwd.c Outdated Show resolved Hide resolved
modules/pam_unix/unix_chkpwd.c Outdated Show resolved Hide resolved
@nbouchinet-anssi
Copy link
Author

nbouchinet-anssi commented Aug 24, 2022

By the way, your patch results to a code that doesn't even compile, this is not a good sign at all.

Hi, Thanks for the reply, sorry I indeed missed to add checks for the header files

@t8m
Copy link
Member

t8m commented Aug 24, 2022

Hi, Thanks for the reply, sorry I indeed missed to add checks for the header files

It should be also optional as presence of the headers should not automatically mean that the support should be compiled in.

@l0kod
Copy link

l0kod commented Aug 24, 2022

It should be also optional as presence of the headers should not automatically mean that the support should be compiled in.

I'd suggest to enable sandboxing whenever possible to protect users. This could be an enabled-by-default configuration though, but I'm not sure this complexity is worth it because Landlock support must not break anything anyway.

@nbouchinet-anssi
Copy link
Author

This binary uses getspnam_r interface to obtain the shadow entry, this doesn't necessarily imply access to /etc/shadow. Would it be possible to enforce a read-only access to the whole filesystem?

Sorry I didn't saw this interface before the PR, I'll read more about getspnam_r to see if a more fine tuned ruleset is feasible as it will be more restrictive than a read-only access to the whole filesystem.

configure.ac Outdated Show resolved Hide resolved
libpam/include/security/pam_landlock.h Outdated Show resolved Hide resolved
libpam/include/security/pam_landlock.h Outdated Show resolved Hide resolved
libpam/include/security/pam_landlock.h Outdated Show resolved Hide resolved
@nbouchinet-anssi
Copy link
Author

Hi, I will not be available for the next 3 weeks.

@nbouchinet-anssi
Copy link
Author

nbouchinet-anssi commented Jan 3, 2023

Hi, sorry it took far more than 3 weeks for me to reply.

I've change the Landlock rule to enforce a read-only access to the whole filesystem as suggested by @ldv-alt .

The _pam_landlock_restrict_to_file_read() function has thus been removed and could be sent in a later patch permitting a more fine grained Landlock configuration, unused macros has also been removed.

Copy link

@l0kod l0kod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but I didn't test it.

libpam/include/security/pam_landlock.h Outdated Show resolved Hide resolved
libpam/include/security/pam_landlock.h Show resolved Hide resolved
modules/pam_unix/unix_chkpwd.c Outdated Show resolved Hide resolved
modules/pam_unix/unix_chkpwd.c Outdated Show resolved Hide resolved
This patch adds a minimalist Landlock support to PAM which restricts the
SUID unix_chkpwd binary to a readonly access to the whole filesystem.
The goal here is to provide security in depth limiting access to the few
resources this program needs limiting uncontrolled privileged access to
the system.

The patch should evolve to support finer restrictions on other PAM
modules/binaries.

* libpam/include/security/pam_sandbox.h: Add a minimalist Landlock file
  restriction function.

* modules/pam_unix/unix_chkpwd.c: Add a read-only access restriction
  to the filesystem using Landlock.

Signed-off-by: Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants