Commit ec0caa97 authored by Eric Biggers's avatar Eric Biggers
Browse files

fscrypt: introduce fscrypt_prepare_readdir()



The last remaining use of fscrypt_get_encryption_info() from filesystems
is for readdir (->iterate_shared()).  Every other call is now in
fs/crypto/ as part of some other higher-level operation.

We need to add a new argument to fscrypt_get_encryption_info() to
indicate whether the encryption policy is allowed to be unrecognized or
not.  Doing this is easier if we can work with high-level operations
rather than direct filesystem use of fscrypt_get_encryption_info().

So add a function fscrypt_prepare_readdir() which wraps the call to
fscrypt_get_encryption_info() for the readdir use case.

Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
Link: https://lore.kernel.org/r/20201203022041.230976-6-ebiggers@kernel.org


Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent 91d0d892
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,12 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
}
}
EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);
EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);


int __fscrypt_prepare_readdir(struct inode *dir)
{
	return fscrypt_get_encryption_info(dir);
}
EXPORT_SYMBOL_GPL(__fscrypt_prepare_readdir);

/**
/**
 * fscrypt_prepare_setflags() - prepare to change flags with FS_IOC_SETFLAGS
 * fscrypt_prepare_setflags() - prepare to change flags with FS_IOC_SETFLAGS
 * @inode: the inode on which flags are being changed
 * @inode: the inode on which flags are being changed
+3 −5
Original line number Original line Diff line number Diff line
@@ -118,11 +118,9 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
	struct buffer_head *bh = NULL;
	struct buffer_head *bh = NULL;
	struct fscrypt_str fstr = FSTR_INIT(NULL, 0);
	struct fscrypt_str fstr = FSTR_INIT(NULL, 0);


	if (IS_ENCRYPTED(inode)) {
	err = fscrypt_prepare_readdir(inode);
		err = fscrypt_get_encryption_info(inode);
	if (err)
	if (err)
		return err;
		return err;
	}


	if (is_dx_dir(inode)) {
	if (is_dx_dir(inode)) {
		err = ext4_dx_readdir(file, ctx);
		err = ext4_dx_readdir(file, ctx);
+1 −1
Original line number Original line Diff line number Diff line
@@ -1004,7 +1004,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
					   EXT4_DIR_REC_LEN(0));
					   EXT4_DIR_REC_LEN(0));
	/* Check if the directory is encrypted */
	/* Check if the directory is encrypted */
	if (IS_ENCRYPTED(dir)) {
	if (IS_ENCRYPTED(dir)) {
		err = fscrypt_get_encryption_info(dir);
		err = fscrypt_prepare_readdir(dir);
		if (err < 0) {
		if (err < 0) {
			brelse(bh);
			brelse(bh);
			return err;
			return err;
+1 −1
Original line number Original line Diff line number Diff line
@@ -1022,7 +1022,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
	int err = 0;
	int err = 0;


	if (IS_ENCRYPTED(inode)) {
	if (IS_ENCRYPTED(inode)) {
		err = fscrypt_get_encryption_info(inode);
		err = fscrypt_prepare_readdir(inode);
		if (err)
		if (err)
			goto out;
			goto out;


+1 −1
Original line number Original line Diff line number Diff line
@@ -514,7 +514,7 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
		return 0;
		return 0;


	if (encrypted) {
	if (encrypted) {
		err = fscrypt_get_encryption_info(dir);
		err = fscrypt_prepare_readdir(dir);
		if (err)
		if (err)
			return err;
			return err;


Loading