diff mbox series

[v2] fscrypt: constify inode parameter to filename encryption functions

Message ID 20191215213947.9521-1-ebiggers@kernel.org (mailing list archive)
State Accepted
Headers show
Series [v2] fscrypt: constify inode parameter to filename encryption functions | expand

Commit Message

Eric Biggers Dec. 15, 2019, 9:39 p.m. UTC
From: Eric Biggers <ebiggers@google.com>

Constify the struct inode parameter to fscrypt_fname_disk_to_usr() and
the other filename encryption functions so that users don't have to pass
in a non-const inode when they are dealing with a const one, as in [1].

[1] https://lkml.kernel.org/linux-ext4/20191203051049.44573-6-drosen@google.com/

Cc: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---

v2: also update the !CONFIG_FS_ENCRYPTION version of
    fscrypt_fname_disk_to_usr().

 fs/crypto/fname.c           | 20 ++++++++++----------
 fs/crypto/fscrypt_private.h |  2 +-
 include/linux/fscrypt.h     |  8 +++++---
 3 files changed, 16 insertions(+), 14 deletions(-)

Comments

Eric Biggers Jan. 3, 2020, 4:59 p.m. UTC | #1
On Sun, Dec 15, 2019 at 01:39:47PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Constify the struct inode parameter to fscrypt_fname_disk_to_usr() and
> the other filename encryption functions so that users don't have to pass
> in a non-const inode when they are dealing with a const one, as in [1].
> 
> [1] https://lkml.kernel.org/linux-ext4/20191203051049.44573-6-drosen@google.com/
> 
> Cc: Daniel Rosenberg <drosen@google.com>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> 
> v2: also update the !CONFIG_FS_ENCRYPTION version of
>     fscrypt_fname_disk_to_usr().
> 
>  fs/crypto/fname.c           | 20 ++++++++++----------
>  fs/crypto/fscrypt_private.h |  2 +-
>  include/linux/fscrypt.h     |  8 +++++---
>  3 files changed, 16 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
> index 3da3707c10e3..c87b71aa2353 100644
> --- a/fs/crypto/fname.c
> +++ b/fs/crypto/fname.c
> @@ -34,12 +34,12 @@ static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
>   *
>   * Return: 0 on success, -errno on failure
>   */
> -int fname_encrypt(struct inode *inode, const struct qstr *iname,
> +int fname_encrypt(const struct inode *inode, const struct qstr *iname,
>  		  u8 *out, unsigned int olen)
>  {
>  	struct skcipher_request *req = NULL;
>  	DECLARE_CRYPTO_WAIT(wait);
> -	struct fscrypt_info *ci = inode->i_crypt_info;
> +	const struct fscrypt_info *ci = inode->i_crypt_info;
>  	struct crypto_skcipher *tfm = ci->ci_ctfm;
>  	union fscrypt_iv iv;
>  	struct scatterlist sg;
> @@ -85,14 +85,14 @@ int fname_encrypt(struct inode *inode, const struct qstr *iname,
>   *
>   * Return: 0 on success, -errno on failure
>   */
> -static int fname_decrypt(struct inode *inode,
> -				const struct fscrypt_str *iname,
> -				struct fscrypt_str *oname)
> +static int fname_decrypt(const struct inode *inode,
> +			 const struct fscrypt_str *iname,
> +			 struct fscrypt_str *oname)
>  {
>  	struct skcipher_request *req = NULL;
>  	DECLARE_CRYPTO_WAIT(wait);
>  	struct scatterlist src_sg, dst_sg;
> -	struct fscrypt_info *ci = inode->i_crypt_info;
> +	const struct fscrypt_info *ci = inode->i_crypt_info;
>  	struct crypto_skcipher *tfm = ci->ci_ctfm;
>  	union fscrypt_iv iv;
>  	int res;
> @@ -247,10 +247,10 @@ EXPORT_SYMBOL(fscrypt_fname_free_buffer);
>   *
>   * Return: 0 on success, -errno on failure
>   */
> -int fscrypt_fname_disk_to_usr(struct inode *inode,
> -			u32 hash, u32 minor_hash,
> -			const struct fscrypt_str *iname,
> -			struct fscrypt_str *oname)
> +int fscrypt_fname_disk_to_usr(const struct inode *inode,
> +			      u32 hash, u32 minor_hash,
> +			      const struct fscrypt_str *iname,
> +			      struct fscrypt_str *oname)
>  {
>  	const struct qstr qname = FSTR_TO_QSTR(iname);
>  	struct fscrypt_digested_name digested_name;
> diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
> index 23cef4d3793a..5792ecbd4d24 100644
> --- a/fs/crypto/fscrypt_private.h
> +++ b/fs/crypto/fscrypt_private.h
> @@ -260,7 +260,7 @@ void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
>  			 const struct fscrypt_info *ci);
>  
>  /* fname.c */
> -extern int fname_encrypt(struct inode *inode, const struct qstr *iname,
> +extern int fname_encrypt(const struct inode *inode, const struct qstr *iname,
>  			 u8 *out, unsigned int olen);
>  extern bool fscrypt_fname_encrypted_size(const struct inode *inode,
>  					 u32 orig_len, u32 max_len,
> diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
> index 1a7bffe78ed5..6eaa729544a3 100644
> --- a/include/linux/fscrypt.h
> +++ b/include/linux/fscrypt.h
> @@ -153,8 +153,10 @@ static inline void fscrypt_free_filename(struct fscrypt_name *fname)
>  extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
>  				struct fscrypt_str *);
>  extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
> -extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
> -			const struct fscrypt_str *, struct fscrypt_str *);
> +extern int fscrypt_fname_disk_to_usr(const struct inode *inode,
> +				     u32 hash, u32 minor_hash,
> +				     const struct fscrypt_str *iname,
> +				     struct fscrypt_str *oname);
>  
>  #define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE	32
>  
> @@ -438,7 +440,7 @@ static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
>  	return;
>  }
>  
> -static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
> +static inline int fscrypt_fname_disk_to_usr(const struct inode *inode,
>  					    u32 hash, u32 minor_hash,
>  					    const struct fscrypt_str *iname,
>  					    struct fscrypt_str *oname)
> -- 
> 2.24.1
> 

Applied to fscrypt.git#master for 5.6.

- Eric
diff mbox series

Patch

diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
index 3da3707c10e3..c87b71aa2353 100644
--- a/fs/crypto/fname.c
+++ b/fs/crypto/fname.c
@@ -34,12 +34,12 @@  static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
  *
  * Return: 0 on success, -errno on failure
  */
-int fname_encrypt(struct inode *inode, const struct qstr *iname,
+int fname_encrypt(const struct inode *inode, const struct qstr *iname,
 		  u8 *out, unsigned int olen)
 {
 	struct skcipher_request *req = NULL;
 	DECLARE_CRYPTO_WAIT(wait);
-	struct fscrypt_info *ci = inode->i_crypt_info;
+	const struct fscrypt_info *ci = inode->i_crypt_info;
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	union fscrypt_iv iv;
 	struct scatterlist sg;
@@ -85,14 +85,14 @@  int fname_encrypt(struct inode *inode, const struct qstr *iname,
  *
  * Return: 0 on success, -errno on failure
  */
-static int fname_decrypt(struct inode *inode,
-				const struct fscrypt_str *iname,
-				struct fscrypt_str *oname)
+static int fname_decrypt(const struct inode *inode,
+			 const struct fscrypt_str *iname,
+			 struct fscrypt_str *oname)
 {
 	struct skcipher_request *req = NULL;
 	DECLARE_CRYPTO_WAIT(wait);
 	struct scatterlist src_sg, dst_sg;
-	struct fscrypt_info *ci = inode->i_crypt_info;
+	const struct fscrypt_info *ci = inode->i_crypt_info;
 	struct crypto_skcipher *tfm = ci->ci_ctfm;
 	union fscrypt_iv iv;
 	int res;
@@ -247,10 +247,10 @@  EXPORT_SYMBOL(fscrypt_fname_free_buffer);
  *
  * Return: 0 on success, -errno on failure
  */
-int fscrypt_fname_disk_to_usr(struct inode *inode,
-			u32 hash, u32 minor_hash,
-			const struct fscrypt_str *iname,
-			struct fscrypt_str *oname)
+int fscrypt_fname_disk_to_usr(const struct inode *inode,
+			      u32 hash, u32 minor_hash,
+			      const struct fscrypt_str *iname,
+			      struct fscrypt_str *oname)
 {
 	const struct qstr qname = FSTR_TO_QSTR(iname);
 	struct fscrypt_digested_name digested_name;
diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
index 23cef4d3793a..5792ecbd4d24 100644
--- a/fs/crypto/fscrypt_private.h
+++ b/fs/crypto/fscrypt_private.h
@@ -260,7 +260,7 @@  void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
 			 const struct fscrypt_info *ci);
 
 /* fname.c */
-extern int fname_encrypt(struct inode *inode, const struct qstr *iname,
+extern int fname_encrypt(const struct inode *inode, const struct qstr *iname,
 			 u8 *out, unsigned int olen);
 extern bool fscrypt_fname_encrypted_size(const struct inode *inode,
 					 u32 orig_len, u32 max_len,
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index 1a7bffe78ed5..6eaa729544a3 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -153,8 +153,10 @@  static inline void fscrypt_free_filename(struct fscrypt_name *fname)
 extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
 				struct fscrypt_str *);
 extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
-extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
-			const struct fscrypt_str *, struct fscrypt_str *);
+extern int fscrypt_fname_disk_to_usr(const struct inode *inode,
+				     u32 hash, u32 minor_hash,
+				     const struct fscrypt_str *iname,
+				     struct fscrypt_str *oname);
 
 #define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE	32
 
@@ -438,7 +440,7 @@  static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
 	return;
 }
 
-static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
+static inline int fscrypt_fname_disk_to_usr(const struct inode *inode,
 					    u32 hash, u32 minor_hash,
 					    const struct fscrypt_str *iname,
 					    struct fscrypt_str *oname)