mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 20:48:49 +08:00
fscrypt: move fscrypt_prepare_symlink() out-of-line
In preparation for moving the logic for "get the encryption policy inherited by new files in this directory" to a single place, make fscrypt_prepare_symlink() a regular function rather than an inline function that wraps __fscrypt_prepare_symlink(). This way, the new function fscrypt_policy_to_inherit() won't need to be exported to filesystems. Acked-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/20200917041136.178600-12-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
parent
c7f0207b61
commit
31114726b6
@ -166,12 +166,43 @@ int fscrypt_prepare_setflags(struct inode *inode,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
/**
|
||||||
unsigned int max_len,
|
* fscrypt_prepare_symlink() - prepare to create a possibly-encrypted symlink
|
||||||
struct fscrypt_str *disk_link)
|
* @dir: directory in which the symlink is being created
|
||||||
|
* @target: plaintext symlink target
|
||||||
|
* @len: length of @target excluding null terminator
|
||||||
|
* @max_len: space the filesystem has available to store the symlink target
|
||||||
|
* @disk_link: (out) the on-disk symlink target being prepared
|
||||||
|
*
|
||||||
|
* This function computes the size the symlink target will require on-disk,
|
||||||
|
* stores it in @disk_link->len, and validates it against @max_len. An
|
||||||
|
* encrypted symlink may be longer than the original.
|
||||||
|
*
|
||||||
|
* Additionally, @disk_link->name is set to @target if the symlink will be
|
||||||
|
* unencrypted, but left NULL if the symlink will be encrypted. For encrypted
|
||||||
|
* symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the
|
||||||
|
* on-disk target later. (The reason for the two-step process is that some
|
||||||
|
* filesystems need to know the size of the symlink target before creating the
|
||||||
|
* inode, e.g. to determine whether it will be a "fast" or "slow" symlink.)
|
||||||
|
*
|
||||||
|
* Return: 0 on success, -ENAMETOOLONG if the symlink target is too long,
|
||||||
|
* -ENOKEY if the encryption key is missing, or another -errno code if a problem
|
||||||
|
* occurred while setting up the encryption key.
|
||||||
|
*/
|
||||||
|
int fscrypt_prepare_symlink(struct inode *dir, const char *target,
|
||||||
|
unsigned int len, unsigned int max_len,
|
||||||
|
struct fscrypt_str *disk_link)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
if (!IS_ENCRYPTED(dir) && !fscrypt_get_dummy_context(dir->i_sb)) {
|
||||||
|
disk_link->name = (unsigned char *)target;
|
||||||
|
disk_link->len = len + 1;
|
||||||
|
if (disk_link->len > max_len)
|
||||||
|
return -ENAMETOOLONG;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To calculate the size of the encrypted symlink target we need to know
|
* To calculate the size of the encrypted symlink target we need to know
|
||||||
* the amount of NUL padding, which is determined by the flags set in
|
* the amount of NUL padding, which is determined by the flags set in
|
||||||
@ -207,7 +238,7 @@ int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
|||||||
disk_link->name = NULL;
|
disk_link->name = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__fscrypt_prepare_symlink);
|
EXPORT_SYMBOL_GPL(fscrypt_prepare_symlink);
|
||||||
|
|
||||||
int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
||||||
unsigned int len, struct fscrypt_str *disk_link)
|
unsigned int len, struct fscrypt_str *disk_link)
|
||||||
|
@ -225,9 +225,9 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
|
|||||||
struct fscrypt_name *fname);
|
struct fscrypt_name *fname);
|
||||||
int fscrypt_prepare_setflags(struct inode *inode,
|
int fscrypt_prepare_setflags(struct inode *inode,
|
||||||
unsigned int oldflags, unsigned int flags);
|
unsigned int oldflags, unsigned int flags);
|
||||||
int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
int fscrypt_prepare_symlink(struct inode *dir, const char *target,
|
||||||
unsigned int max_len,
|
unsigned int len, unsigned int max_len,
|
||||||
struct fscrypt_str *disk_link);
|
struct fscrypt_str *disk_link);
|
||||||
int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
||||||
unsigned int len, struct fscrypt_str *disk_link);
|
unsigned int len, struct fscrypt_str *disk_link);
|
||||||
const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
||||||
@ -520,15 +520,21 @@ static inline int fscrypt_prepare_setflags(struct inode *inode,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int __fscrypt_prepare_symlink(struct inode *dir,
|
static inline int fscrypt_prepare_symlink(struct inode *dir,
|
||||||
unsigned int len,
|
const char *target,
|
||||||
unsigned int max_len,
|
unsigned int len,
|
||||||
struct fscrypt_str *disk_link)
|
unsigned int max_len,
|
||||||
|
struct fscrypt_str *disk_link)
|
||||||
{
|
{
|
||||||
return -EOPNOTSUPP;
|
if (IS_ENCRYPTED(dir))
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
disk_link->name = (unsigned char *)target;
|
||||||
|
disk_link->len = len + 1;
|
||||||
|
if (disk_link->len > max_len)
|
||||||
|
return -ENAMETOOLONG;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline int __fscrypt_encrypt_symlink(struct inode *inode,
|
static inline int __fscrypt_encrypt_symlink(struct inode *inode,
|
||||||
const char *target,
|
const char *target,
|
||||||
unsigned int len,
|
unsigned int len,
|
||||||
@ -793,45 +799,6 @@ static inline int fscrypt_prepare_setattr(struct dentry *dentry,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* fscrypt_prepare_symlink() - prepare to create a possibly-encrypted symlink
|
|
||||||
* @dir: directory in which the symlink is being created
|
|
||||||
* @target: plaintext symlink target
|
|
||||||
* @len: length of @target excluding null terminator
|
|
||||||
* @max_len: space the filesystem has available to store the symlink target
|
|
||||||
* @disk_link: (out) the on-disk symlink target being prepared
|
|
||||||
*
|
|
||||||
* This function computes the size the symlink target will require on-disk,
|
|
||||||
* stores it in @disk_link->len, and validates it against @max_len. An
|
|
||||||
* encrypted symlink may be longer than the original.
|
|
||||||
*
|
|
||||||
* Additionally, @disk_link->name is set to @target if the symlink will be
|
|
||||||
* unencrypted, but left NULL if the symlink will be encrypted. For encrypted
|
|
||||||
* symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the
|
|
||||||
* on-disk target later. (The reason for the two-step process is that some
|
|
||||||
* filesystems need to know the size of the symlink target before creating the
|
|
||||||
* inode, e.g. to determine whether it will be a "fast" or "slow" symlink.)
|
|
||||||
*
|
|
||||||
* Return: 0 on success, -ENAMETOOLONG if the symlink target is too long,
|
|
||||||
* -ENOKEY if the encryption key is missing, or another -errno code if a problem
|
|
||||||
* occurred while setting up the encryption key.
|
|
||||||
*/
|
|
||||||
static inline int fscrypt_prepare_symlink(struct inode *dir,
|
|
||||||
const char *target,
|
|
||||||
unsigned int len,
|
|
||||||
unsigned int max_len,
|
|
||||||
struct fscrypt_str *disk_link)
|
|
||||||
{
|
|
||||||
if (IS_ENCRYPTED(dir) || fscrypt_get_dummy_context(dir->i_sb) != NULL)
|
|
||||||
return __fscrypt_prepare_symlink(dir, len, max_len, disk_link);
|
|
||||||
|
|
||||||
disk_link->name = (unsigned char *)target;
|
|
||||||
disk_link->len = len + 1;
|
|
||||||
if (disk_link->len > max_len)
|
|
||||||
return -ENAMETOOLONG;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fscrypt_encrypt_symlink() - encrypt the symlink target if needed
|
* fscrypt_encrypt_symlink() - encrypt the symlink target if needed
|
||||||
* @inode: symlink inode
|
* @inode: symlink inode
|
||||||
|
Loading…
Reference in New Issue
Block a user