Skip to content

pam_fscrypt probably locks too much memoryΒ #405

@EX0l0N

Description

@EX0l0N

On my tablet which runs mobian (so basically debian) I have some folders I want to unlock at login.
Therefore I use pam_fscrypt.

For a long time this did not work, so I had to run fscrypt unlock manually after login. That worked, so the setup is correct so far.

Running pam_fscrypt with debug parameter revealed that it fails to lock memory for AUTHTOK in one place and as a result fails to fetch the token in another.

Here's the output of journalctl -b | fgrep fscrypt

Feb 28 18:09:04 juno kernel: Key type .fscrypt registered
Feb 28 18:09:04 juno kernel: Key type fscrypt-provisioning registered
Feb 28 18:09:10 juno pam_fscrypt[921]: OpenSession(map[debug:true]) starting
Feb 28 18:09:10 juno pam_fscrypt[921]: invoked for system user "_greetd" (105), doing nothing
Feb 28 18:09:10 juno pam_fscrypt[921]: OpenSession(map[debug:true]) succeeded
Feb 28 18:09:24 juno pam_fscrypt[921]: CloseSession(map[debug:true]) starting
Feb 28 18:09:24 juno pam_fscrypt[921]: invoked for system user "_greetd" (105), doing nothing
Feb 28 18:09:24 juno pam_fscrypt[921]: CloseSession(map[debug:true]) succeeded
Feb 28 18:09:25 juno pam_fscrypt[1239]: OpenSession(map[debug:true]) starting
Feb 28 18:09:25 juno pam_fscrypt[1239]: Session count for UID=1000 updated to 1
Feb 28 18:09:25 juno pam_fscrypt[1239]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:09:25 juno pam_fscrypt[1239]: Setting euid=1000 egid=1000 groups=[1000 20 27 29 44 46 100 101 104 108 119 995]
Feb 28 18:09:25 juno pam_fscrypt[1239]: Current privs (real, effective): uid=(0,1000) gid=(0,1000) groups=[20 27 29 44 46 100 101 104 108 119 995 1000]
Feb 28 18:09:25 juno pam_fscrypt[1239]: Reading config from "/etc/fscrypt.conf"
Feb 28 18:09:25 juno pam_fscrypt[1239]: creating context for user "exo"
Feb 28 18:09:25 juno pam_fscrypt[1239]: found ext4 filesystem "/" (/dev/sda3)
Feb 28 18:09:25 juno pam_fscrypt[1239]: listing protectors in "/.fscrypt/protectors"
Feb 28 18:09:25 juno pam_fscrypt[1239]: found 1 protectors
Feb 28 18:09:25 juno pam_fscrypt[1239]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:25 juno pam_fscrypt[1239]: Getting protector 737a0be29d62e6c0 from option
Feb 28 18:09:25 juno pam_fscrypt[1239]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:25 juno pam_fscrypt[1239]: listing policies in "/.fscrypt/policies"
Feb 28 18:09:25 juno pam_fscrypt[1239]: found 0 policies
Feb 28 18:09:25 juno pam_fscrypt[1239]: following protector link /data/.fscrypt/protectors/737a0be29d62e6c0.link
Feb 28 18:09:25 juno pam_fscrypt[1239]: resolved filesystem link using UUID "9fd450df-ba4e-41a0-9051-c3991b162928"
Feb 28 18:09:25 juno pam_fscrypt[1239]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:25 juno pam_fscrypt[1239]: listing policies in "/data/.fscrypt/policies"
Feb 28 18:09:25 juno pam_fscrypt[1239]: found 1 policies
Feb 28 18:09:25 juno pam_fscrypt[1239]: successfully read metadata from "/data/.fscrypt/policies/fcbfd26b9703ff8d6b7603168098d6e1"
Feb 28 18:09:25 juno pam_fscrypt[1239]: got data for fcbfd26b9703ff8d6b7603168098d6e1 from "/data"
Feb 28 18:09:25 juno pam_fscrypt[1239]: Detected support for filesystem keyring
Feb 28 18:09:25 juno pam_fscrypt[1239]: FS_IOC_GET_ENCRYPTION_KEY_STATUS("/data", fcbfd26b9703ff8d6b7603168098d6e1) = errno 0, status=1, status_flags=0x0
Feb 28 18:09:25 juno pam_fscrypt[1239]: unlocking 1 policies protected with AUTHTOK
Feb 28 18:09:25 juno pam_fscrypt[1239]: Setting euid=0 egid=0 groups=[]
Feb 28 18:09:25 juno pam_fscrypt[1239]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:09:25 juno pam_fscrypt[1239]: OpenSession(map[debug:true]) failed: unlocking protector 737a0be29d62e6c0: could not lock key in memory
Feb 28 18:09:37 juno pam_fscrypt[2131]: OpenSession(map[debug:true]) starting
Feb 28 18:09:37 juno pam_fscrypt[2131]: Session count for UID=1000 updated to 2
Feb 28 18:09:37 juno pam_fscrypt[2131]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:09:37 juno pam_fscrypt[2131]: Setting euid=1000 egid=1000 groups=[1000 20 27 29 44 46 100 101 104 108 119 995]
Feb 28 18:09:37 juno pam_fscrypt[2131]: Current privs (real, effective): uid=(0,1000) gid=(0,1000) groups=[20 27 29 44 46 100 101 104 108 119 995 1000]
Feb 28 18:09:37 juno pam_fscrypt[2131]: Reading config from "/etc/fscrypt.conf"
Feb 28 18:09:37 juno pam_fscrypt[2131]: creating context for user "exo"
Feb 28 18:09:37 juno pam_fscrypt[2131]: stat /sys/kernel/debug/tracing: permission denied
Feb 28 18:09:37 juno pam_fscrypt[2131]: ignoring mountpoint "/sys/kernel/debug/tracing" because it is not a directory
Feb 28 18:09:37 juno pam_fscrypt[2131]: stat /run/user/1000/gvfs: permission denied
Feb 28 18:09:37 juno pam_fscrypt[2131]: ignoring mountpoint "/run/user/1000/gvfs" because it is not a directory
Feb 28 18:09:37 juno pam_fscrypt[2131]: stat /run/user/1000/doc: permission denied
Feb 28 18:09:37 juno pam_fscrypt[2131]: ignoring mountpoint "/run/user/1000/doc" because it is not a directory
Feb 28 18:09:37 juno pam_fscrypt[2131]: found ext4 filesystem "/" (/dev/sda3)
Feb 28 18:09:37 juno pam_fscrypt[2131]: listing protectors in "/.fscrypt/protectors"
Feb 28 18:09:37 juno pam_fscrypt[2131]: found 1 protectors
Feb 28 18:09:37 juno pam_fscrypt[2131]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:37 juno pam_fscrypt[2131]: Getting protector 737a0be29d62e6c0 from option
Feb 28 18:09:37 juno pam_fscrypt[2131]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:37 juno pam_fscrypt[2131]: listing policies in "/.fscrypt/policies"
Feb 28 18:09:37 juno pam_fscrypt[2131]: found 0 policies
Feb 28 18:09:37 juno pam_fscrypt[2131]: following protector link /data/.fscrypt/protectors/737a0be29d62e6c0.link
Feb 28 18:09:37 juno pam_fscrypt[2131]: resolved filesystem link using UUID "9fd450df-ba4e-41a0-9051-c3991b162928"
Feb 28 18:09:37 juno pam_fscrypt[2131]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:09:37 juno pam_fscrypt[2131]: listing policies in "/data/.fscrypt/policies"
Feb 28 18:09:37 juno pam_fscrypt[2131]: found 1 policies
Feb 28 18:09:37 juno pam_fscrypt[2131]: successfully read metadata from "/data/.fscrypt/policies/fcbfd26b9703ff8d6b7603168098d6e1"
Feb 28 18:09:37 juno pam_fscrypt[2131]: got data for fcbfd26b9703ff8d6b7603168098d6e1 from "/data"
Feb 28 18:09:37 juno pam_fscrypt[2131]: Detected support for filesystem keyring
Feb 28 18:09:37 juno pam_fscrypt[2131]: FS_IOC_GET_ENCRYPTION_KEY_STATUS("/data", fcbfd26b9703ff8d6b7603168098d6e1) = errno 0, status=1, status_flags=0x0
Feb 28 18:09:37 juno pam_fscrypt[2131]: unlocking 1 policies protected with AUTHTOK
Feb 28 18:09:37 juno pam_fscrypt[2131]: Setting euid=0 egid=0 groups=[]
Feb 28 18:09:37 juno pam_fscrypt[2131]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:09:37 juno pam_fscrypt[2131]: OpenSession(map[debug:true]) failed: unlocking protector 737a0be29d62e6c0: AUTHTOK data missing: No module specific data is present

When I raise the limit in /etc/security/limits.conf to unlimited (I don't really care here), it works.

This is debug info from a successful run:

Feb 28 18:25:49 juno kernel: Key type .fscrypt registered
Feb 28 18:25:49 juno kernel: Key type fscrypt-provisioning registered
Feb 28 18:25:54 juno pam_fscrypt[917]: OpenSession(map[debug:true]) starting
Feb 28 18:25:54 juno pam_fscrypt[917]: invoked for system user "_greetd" (105), doing nothing
Feb 28 18:25:54 juno pam_fscrypt[917]: OpenSession(map[debug:true]) succeeded
Feb 28 18:26:09 juno pam_fscrypt[917]: CloseSession(map[debug:true]) starting
Feb 28 18:26:09 juno pam_fscrypt[917]: invoked for system user "_greetd" (105), doing nothing
Feb 28 18:26:09 juno pam_fscrypt[917]: CloseSession(map[debug:true]) succeeded
Feb 28 18:26:09 juno pam_fscrypt[1238]: OpenSession(map[debug:true]) starting
Feb 28 18:26:09 juno pam_fscrypt[1238]: Session count for UID=1000 updated to 1
Feb 28 18:26:09 juno pam_fscrypt[1238]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:26:09 juno pam_fscrypt[1238]: Setting euid=1000 egid=1000 groups=[1000 20 27 29 44 46 100 101 104 108 119 995]
Feb 28 18:26:09 juno pam_fscrypt[1238]: Current privs (real, effective): uid=(0,1000) gid=(0,1000) groups=[20 27 29 44 46 100 101 104 108 119 995 1000]
Feb 28 18:26:09 juno pam_fscrypt[1238]: Reading config from "/etc/fscrypt.conf"
Feb 28 18:26:09 juno pam_fscrypt[1238]: creating context for user "exo"
Feb 28 18:26:09 juno pam_fscrypt[1238]: found ext4 filesystem "/" (/dev/sda3)
Feb 28 18:26:09 juno pam_fscrypt[1238]: listing protectors in "/.fscrypt/protectors"
Feb 28 18:26:09 juno pam_fscrypt[1238]: found 1 protectors
Feb 28 18:26:09 juno pam_fscrypt[1238]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:09 juno pam_fscrypt[1238]: Getting protector 737a0be29d62e6c0 from option
Feb 28 18:26:09 juno pam_fscrypt[1238]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:09 juno pam_fscrypt[1238]: listing policies in "/.fscrypt/policies"
Feb 28 18:26:09 juno pam_fscrypt[1238]: found 0 policies
Feb 28 18:26:09 juno pam_fscrypt[1238]: following protector link /data/.fscrypt/protectors/737a0be29d62e6c0.link
Feb 28 18:26:09 juno pam_fscrypt[1238]: resolved filesystem link using UUID "9fd450df-ba4e-41a0-9051-c3991b162928"
Feb 28 18:26:09 juno pam_fscrypt[1238]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:09 juno pam_fscrypt[1238]: listing policies in "/data/.fscrypt/policies"
Feb 28 18:26:09 juno pam_fscrypt[1238]: found 1 policies
Feb 28 18:26:09 juno pam_fscrypt[1238]: successfully read metadata from "/data/.fscrypt/policies/fcbfd26b9703ff8d6b7603168098d6e1"
Feb 28 18:26:09 juno pam_fscrypt[1238]: got data for fcbfd26b9703ff8d6b7603168098d6e1 from "/data"
Feb 28 18:26:09 juno pam_fscrypt[1238]: Detected support for filesystem keyring
Feb 28 18:26:09 juno pam_fscrypt[1238]: FS_IOC_GET_ENCRYPTION_KEY_STATUS("/data", fcbfd26b9703ff8d6b7603168098d6e1) = errno 0, status=1, status_flags=0x0
Feb 28 18:26:09 juno pam_fscrypt[1238]: unlocking 1 policies protected with AUTHTOK
Feb 28 18:26:09 juno pam_fscrypt[1238]: running passphrase hash for protector 737a0be29d62e6c0
Feb 28 18:26:13 juno pam_fscrypt[1238]: valid wrapping key for protector 737a0be29d62e6c0
Feb 28 18:26:13 juno pam_fscrypt[1238]: FS_IOC_ADD_ENCRYPTION_KEY("/data", fcbfd26b9703ff8d6b7603168098d6e1, <raw>) = errno 0
Feb 28 18:26:13 juno pam_fscrypt[1238]: policy fcbfd26b9703ff8d6b7603168098d6e1 provisioned by exo
Feb 28 18:26:13 juno pam_fscrypt[1238]: Setting euid=0 egid=0 groups=[]
Feb 28 18:26:13 juno pam_fscrypt[1238]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:26:13 juno pam_fscrypt[1238]: OpenSession(map[debug:true]) succeeded
Feb 28 18:26:19 juno kernel: fscrypt: AES-256-CTS-CBC using implementation "cts-cbc-aes-aesni"
Feb 28 18:26:19 juno kernel: fscrypt: AES-256-XTS using implementation "xts-aes-aesni"
Feb 28 18:26:27 juno pam_fscrypt[2259]: OpenSession(map[debug:true]) starting
Feb 28 18:26:27 juno pam_fscrypt[2259]: Session count for UID=1000 updated to 2
Feb 28 18:26:27 juno pam_fscrypt[2259]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:26:27 juno pam_fscrypt[2259]: Setting euid=1000 egid=1000 groups=[1000 20 27 29 44 46 100 101 104 108 119 995]
Feb 28 18:26:27 juno pam_fscrypt[2259]: Current privs (real, effective): uid=(0,1000) gid=(0,1000) groups=[20 27 29 44 46 100 101 104 108 119 995 1000]
Feb 28 18:26:27 juno pam_fscrypt[2259]: Reading config from "/etc/fscrypt.conf"
Feb 28 18:26:27 juno pam_fscrypt[2259]: creating context for user "exo"
Feb 28 18:26:27 juno pam_fscrypt[2259]: stat /sys/kernel/debug/tracing: permission denied
Feb 28 18:26:27 juno pam_fscrypt[2259]: ignoring mountpoint "/sys/kernel/debug/tracing" because it is not a directory
Feb 28 18:26:27 juno pam_fscrypt[2259]: stat /run/user/1000/gvfs: permission denied
Feb 28 18:26:27 juno pam_fscrypt[2259]: ignoring mountpoint "/run/user/1000/gvfs" because it is not a directory
Feb 28 18:26:27 juno pam_fscrypt[2259]: stat /run/user/1000/doc: permission denied
Feb 28 18:26:27 juno pam_fscrypt[2259]: ignoring mountpoint "/run/user/1000/doc" because it is not a directory
Feb 28 18:26:27 juno pam_fscrypt[2259]: found ext4 filesystem "/" (/dev/sda3)
Feb 28 18:26:27 juno pam_fscrypt[2259]: listing protectors in "/.fscrypt/protectors"
Feb 28 18:26:27 juno pam_fscrypt[2259]: found 1 protectors
Feb 28 18:26:27 juno pam_fscrypt[2259]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:27 juno pam_fscrypt[2259]: Getting protector 737a0be29d62e6c0 from option
Feb 28 18:26:27 juno pam_fscrypt[2259]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:27 juno pam_fscrypt[2259]: listing policies in "/.fscrypt/policies"
Feb 28 18:26:27 juno pam_fscrypt[2259]: found 0 policies
Feb 28 18:26:27 juno pam_fscrypt[2259]: following protector link /data/.fscrypt/protectors/737a0be29d62e6c0.link
Feb 28 18:26:27 juno pam_fscrypt[2259]: resolved filesystem link using UUID "9fd450df-ba4e-41a0-9051-c3991b162928"
Feb 28 18:26:27 juno pam_fscrypt[2259]: successfully read metadata from "/.fscrypt/protectors/737a0be29d62e6c0"
Feb 28 18:26:27 juno pam_fscrypt[2259]: listing policies in "/data/.fscrypt/policies"
Feb 28 18:26:27 juno pam_fscrypt[2259]: found 1 policies
Feb 28 18:26:27 juno pam_fscrypt[2259]: successfully read metadata from "/data/.fscrypt/policies/fcbfd26b9703ff8d6b7603168098d6e1"
Feb 28 18:26:27 juno pam_fscrypt[2259]: got data for fcbfd26b9703ff8d6b7603168098d6e1 from "/data"
Feb 28 18:26:27 juno pam_fscrypt[2259]: Detected support for filesystem keyring
Feb 28 18:26:27 juno pam_fscrypt[2259]: FS_IOC_GET_ENCRYPTION_KEY_STATUS("/data", fcbfd26b9703ff8d6b7603168098d6e1) = errno 0, status=2, status_flags=0x1
Feb 28 18:26:27 juno pam_fscrypt[2259]: policy fcbfd26b9703ff8d6b7603168098d6e1 already provisioned by exo
Feb 28 18:26:27 juno pam_fscrypt[2259]: no policies to unlock
Feb 28 18:26:27 juno pam_fscrypt[2259]: Setting euid=0 egid=0 groups=[]
Feb 28 18:26:27 juno pam_fscrypt[2259]: Current privs (real, effective): uid=(0,0) gid=(0,0) groups=[]
Feb 28 18:26:27 juno pam_fscrypt[2259]: OpenSession(map[debug:true]) succeeded

Here are the default hard- and softlimits for max locked memory (read as "if I don't set it to unlimited")

$ ulimit -Hl
984700
$ ulimit -Sl
984700

If I understood that correctly this is per process and in kilobytes. To exceed that one would need to lock ~961Mib?

I think that's unreasonable for pam_fscrypt to do in every plausible circumstance.

$ dpkg -l "*fscrypt*"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=============================================
ii  fscrypt        0.3.4-2      amd64        Tool for managing Linux filesystem encryption
ii  libpam-fscrypt 0.3.4-2      amd64        PAM module for Linux filesystem encryption

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions