linux-stable/fs/crypto
Eric Biggers 3b7c17a814 fscrypt: remove kernel-internal constants from UAPI header
commit 3ceb6543e9 upstream.

There isn't really any valid reason to use __FSCRYPT_MODE_MAX or
FSCRYPT_POLICY_FLAGS_VALID in a userspace program.  These constants are
only meant to be used by the kernel internally, and they are defined in
the UAPI header next to the mode numbers and flags only so that kernel
developers don't forget to update them when adding new modes or flags.

In https://lkml.kernel.org/r/20201005074133.1958633-2-satyat@google.com
there was an example of someone wanting to use __FSCRYPT_MODE_MAX in a
user program, and it was wrong because the program would have broken if
__FSCRYPT_MODE_MAX were ever increased.  So having this definition
available is harmful.  FSCRYPT_POLICY_FLAGS_VALID has the same problem.

So, remove these definitions from the UAPI header.  Replace
FSCRYPT_POLICY_FLAGS_VALID with just listing the valid flags explicitly
in the one kernel function that needs it.  Move __FSCRYPT_MODE_MAX to
fscrypt_private.h, remove the double underscores (which were only
present to discourage use by userspace), and add a BUILD_BUG_ON() and
comments to (hopefully) ensure it is kept in sync.

Keep the old name FS_POLICY_FLAGS_VALID, since it's been around for
longer and there's a greater chance that removing it would break source
compatibility with some program.  Indeed, mtd-utils is using it in
an #ifdef, and removing it would introduce compiler warnings (about
FS_POLICY_FLAGS_PAD_* being redefined) into the mtd-utils build.
However, reduce its value to 0x07 so that it only includes the flags
with old names (the ones present before Linux 5.4), and try to make it
clear that it's now "frozen" and no new flags should be added to it.

Fixes: 2336d0deb2 ("fscrypt: use FSCRYPT_ prefix for uapi constants")
Cc: <stable@vger.kernel.org> # v5.4+
Link: https://lore.kernel.org/r/20201024005132.495952-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-12-26 16:02:43 +01:00
..
bio.c fscrypt: add inline encryption support 2020-07-08 10:29:30 -07:00
crypto.c fscrypt: adjust logging for in-creation inodes 2020-09-22 06:48:38 -07:00
fname.c fscrypt: export fscrypt_d_revalidate() 2020-09-28 14:44:51 -07:00
fscrypt_private.h fscrypt: remove kernel-internal constants from UAPI header 2020-12-26 16:02:43 +01:00
hkdf.c fscrypt: use crypto_shash_tfm_digest() 2020-05-08 15:32:14 +10:00
hooks.c fscrypt: rename DCACHE_ENCRYPTED_NAME to DCACHE_NOKEY_NAME 2020-09-23 21:29:49 -07:00
inline_crypt.c fscrypt: fix inline encryption not used on new files 2020-11-11 20:59:07 -08:00
Kconfig fscrypt: switch fscrypt_do_sha256() to use the SHA-256 library 2020-07-21 16:02:13 -07:00
keyring.c fscrypt: remove kernel-internal constants from UAPI header 2020-12-26 16:02:43 +01:00
keysetup.c fscrypt: remove kernel-internal constants from UAPI header 2020-12-26 16:02:43 +01:00
keysetup_v1.c fscrypt: stop pretending that key setup is nofs-safe 2020-09-22 06:48:42 -07:00
Makefile fscrypt: add inline encryption support 2020-07-08 10:29:30 -07:00
policy.c fscrypt: remove kernel-internal constants from UAPI header 2020-12-26 16:02:43 +01:00