bcachefs: Return -ENOKEY/EINVAL when mount decryption fails
authorChris Webb <chris@arachsys.com>
Thu, 4 Nov 2021 21:03:16 +0000 (21:03 +0000)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:16 +0000 (17:09 -0400)
commit7be9ab637fb9c5283c5d1b3f41d81bc2c01ad548
tree68ef782de4f20d6f76e1ac62f7ffddb41552a58c
parent076c783cd31f0d46782f9365fd79725d1248712d
bcachefs: Return -ENOKEY/EINVAL when mount decryption fails

bch2_fs_encryption_init() correctly passes back -ENOKEY from request_key()
when no unlock key is found, or -EINVAL if superblock decryption fails
because of an invalid key. However, these get absorbed into a generic NULL
return from bch2_fs_alloc() and later returned to user space as -ENOMEM,
leading to a misleading error from mount(1):

  mount(2) system call failed: Out of memory.

Return explicit error pointers out of bch2_fs_alloc() and handle them in
both callers, so the user instead sees

  mount(2) system call failed: Required key not available.

when attempting to mount a filesystem which is still locked.

Signed-off-by: Chris Webb <chris@arachsys.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/super.c