[PATCH 1/5] xfs: load secure hash algorithm for parent pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <djwong@xxxxxxxxxx>

We're about to start replacing the diroffset field of parent pointers
with a collision-resistant hash of the directory entry name.  Start by
attaching the sha512 crypto implementation if parent pointers are
attached.

Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx>
---
 fs/xfs/Kconfig     |    1 +
 fs/xfs/xfs_linux.h |    1 +
 fs/xfs/xfs_mount.c |   13 +++++++++++++
 fs/xfs/xfs_mount.h |    3 +++
 fs/xfs/xfs_super.c |    3 +++
 5 files changed, 21 insertions(+)


diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig
index 4798a147fd9e..6422daaf8914 100644
--- a/fs/xfs/Kconfig
+++ b/fs/xfs/Kconfig
@@ -5,6 +5,7 @@ config XFS_FS
 	select EXPORTFS
 	select LIBCRC32C
 	select FS_IOMAP
+	select CRYPTO_SHA512
 	help
 	  XFS is a high performance journaling filesystem which originated
 	  on the SGI IRIX platform.  It is completely multi-threaded, can
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index c05f7e309c3e..3f93a742b896 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -62,6 +62,7 @@ typedef __u32			xfs_nlink_t;
 #include <linux/rhashtable.h>
 #include <linux/xattr.h>
 #include <linux/mnt_idmapping.h>
+#include <crypto/hash.h>
 
 #include <asm/page.h>
 #include <asm/div64.h>
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index fb87ffb48f7f..a5f3dce658e9 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -983,6 +983,19 @@ xfs_mountfs(
 			goto out_agresv;
 	}
 
+	if (xfs_has_parent(mp)) {
+		struct crypto_shash	*tfm;
+
+		tfm = crypto_alloc_shash("sha512", 0, 0);
+		if (IS_ERR(tfm)) {
+			error = PTR_ERR(tfm);
+			goto out_agresv;
+		}
+		xfs_info(mp, "parent pointer hash %s",
+				crypto_shash_driver_name(tfm));
+		mp->m_sha512 = tfm;
+	}
+
 	return 0;
 
  out_agresv:
diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index c08f55cc4f36..7c8e15e84cd6 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -244,6 +244,9 @@ typedef struct xfs_mount {
 #endif
 	/* Hook to feed file directory updates to an active online repair. */
 	struct xfs_hooks	m_dirent_update_hooks;
+
+	/* sha512 engine, if needed */
+	struct crypto_shash	*m_sha512;
 } xfs_mount_t;
 
 #define M_IGEO(mp)		(&(mp)->m_ino_geo)
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index 0432a4a096e8..610d72353f39 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -738,6 +738,8 @@ xfs_mount_free(
 {
 	kfree(mp->m_rtname);
 	kfree(mp->m_logname);
+	if (mp->m_sha512)
+		crypto_free_shash(mp->m_sha512);
 	kmem_free(mp);
 }
 
@@ -1961,6 +1963,7 @@ static int xfs_init_fs_context(
 	if (fc->sb_flags & SB_SYNCHRONOUS)
 		mp->m_features |= XFS_FEAT_WSYNC;
 
+	mp->m_sha512 = NULL;
 	fc->s_fs_info = mp;
 	fc->ops = &xfs_context_ops;
 




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux