linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v3 26/30] xfsprogs: Add xfs_verify_pptr
Date: Wed, 26 Sep 2018 03:23:29 -0700	[thread overview]
Message-ID: <1537957413-10630-27-git-send-email-allison.henderson@oracle.com> (raw)
In-Reply-To: <1537957413-10630-1-git-send-email-allison.henderson@oracle.com>

Attribute names of parent pointers are not strings.  So we
need to modify attr_namecheck to verify parent pointer
records when the XFS_ATTR_PARENT flag is set.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
---
 repair/attr_repair.c | 21 +++++++++++----------
 repair/da_util.c     | 43 +++++++++++++++++++++++++++++++++++++++++++
 repair/da_util.h     | 12 ++++++++++++
 3 files changed, 66 insertions(+), 10 deletions(-)

diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index 1d04500..df27fa4 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -292,13 +292,14 @@ process_shortform_attr(
 			}
 		}
 
-		/* namecheck checks for / and null terminated for file names.
-		 * attributes names currently follow the same rules.
-		*/
-		if (namecheck((char *)&currententry->nameval[0],
-						currententry->namelen))  {
+		/* namecheck checks for / and null terminated for file names,
+		 * or verifies parent pointer record in the case of a parent
+		 * pointer attribute.
+		 */
+		if (attr_namecheck(mp, (char *)&currententry->nameval[0],
+		       currententry->namelen, currententry->flags))  {
 			do_warn(
-	_("entry contains illegal character in shortform attribute name\n"));
+	_("entry contains illegal shortform attribute name\n"));
 			junkit = 1;
 		}
 
@@ -458,8 +459,8 @@ process_leaf_attr_local(
 	xfs_attr_leaf_name_local_t *local;
 
 	local = xfs_attr3_leaf_name_local(leaf, i);
-	if (local->namelen == 0 || namecheck((char *)&local->nameval[0],
-							local->namelen)) {
+	if (attr_namecheck(mp, (char *)&local->nameval[0],
+	       local->namelen, entry->flags)) {
 		do_warn(
 	_("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),
 			i, da_bno, ino, local->namelen);
@@ -513,8 +514,8 @@ process_leaf_attr_remote(
 
 	remotep = xfs_attr3_leaf_name_remote(leaf, i);
 
-	if (remotep->namelen == 0 || namecheck((char *)&remotep->name[0],
-						remotep->namelen) ||
+	if (attr_namecheck(mp, (char *)&remotep->name[0],
+				remotep->namelen, entry->flags) ||
 			be32_to_cpu(entry->hashval) !=
 				libxfs_da_hashname((unsigned char *)&remotep->name[0],
 						remotep->namelen) ||
diff --git a/repair/da_util.c b/repair/da_util.c
index 1450767..d94a31c 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -13,6 +13,49 @@
 #include "da_util.h"
 
 /*
+ * Verify parent pointer attribute is valid.
+ * Return 0 on success or 1 on failure
+ */
+int
+xfs_verify_pptr(struct xfs_mount *mp, struct xfs_parent_name_rec *rec)
+{
+	xfs_ino_t p_ino = (xfs_ino_t)be64_to_cpu(rec->p_ino);
+	xfs_dir2_dataptr_t p_diroffset =
+			(xfs_dir2_dataptr_t)be32_to_cpu(rec->p_diroffset);
+
+	if (!xfs_verify_ino(mp, p_ino))
+		return 1;
+
+	if (p_diroffset > XFS_DIR2_MAX_DATAPTR)
+		return 1;
+
+	return 0;
+}
+
+/*
+ * Check if an attribute name is valid
+ * Returns 0 on success and 1 on failure
+ */
+int
+attr_namecheck(struct xfs_mount *mp, char *name, int length, int flags)
+{
+	if (flags & XFS_ATTR_PARENT) {
+		if (length != sizeof(struct xfs_parent_name_rec))
+			return 1;
+		return xfs_verify_pptr(mp, (struct xfs_parent_name_rec *)name);
+	}
+
+	if (length == 0)
+		return 1;
+
+	/*
+	 * namecheck checks for / and null terminated for file names.
+	 * attributes names currently follow the same rules.
+	 */
+	return namecheck(name, length);
+}
+
+/*
  * takes a name and length (name need not be null-terminated)
  * and returns 1 if the name contains a '/' or a \0, returns 0
  * otherwise
diff --git a/repair/da_util.h b/repair/da_util.h
index d36dfd0..53ba843 100644
--- a/repair/da_util.h
+++ b/repair/da_util.h
@@ -25,6 +25,18 @@ typedef struct da_bt_cursor {
 } da_bt_cursor_t;
 
 int
+xfs_verify_pptr(
+	struct xfs_mount *mp,
+	struct xfs_parent_name_rec *rec);
+
+int
+attr_namecheck(
+	struct xfs_mount	*mp,
+	char			*name,
+	int			length,
+	int			flags);
+
+int
 namecheck(
 	char		*name,
 	int		length);
-- 
2.7.4

  parent reply	other threads:[~2018-09-26 16:38 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26 10:23 [PATCH v3 00/30] xfsprogs: parent pointers v2 Allison Henderson
2018-09-26 10:23 ` [PATCH v3 01/30] xfsprogs: Move xfs_attr.h to libxfs Allison Henderson
2018-09-26 10:23 ` [PATCH v3 02/30] xfsprogs: Add helper function xfs_attr_try_sf_addname Allison Henderson
2018-09-26 10:23 ` [PATCH v3 03/30] xfsprogs: Add attibute set and helper functions Allison Henderson
2018-09-26 10:23 ` [PATCH v3 04/30] xfsprogs: Add attibute remove " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 05/30] xfsprogs: Add trans toggle to attr routines Allison Henderson
2018-09-26 10:23 ` [PATCH v3 06/30] xfsprogs: Set up infastructure for deferred attribute operations Allison Henderson
2018-09-26 10:23 ` [PATCH v3 07/30] xfsprogs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Allison Henderson
2018-09-26 10:23 ` [PATCH v3 08/30] xfsprogs: Add xfs_has_attr and subroutines Allison Henderson
2018-09-26 10:23 ` [PATCH v3 09/30] xfsprogs: Add attr context to log item Allison Henderson
2018-09-26 10:23 ` [PATCH v3 10/30] xfsprogs: Roll delayed attr operations by returning EAGAIN Allison Henderson
2018-09-26 10:23 ` [PATCH v3 11/30] xfsprogs: Remove roll_trans boolean Allison Henderson
2018-09-26 10:23 ` [PATCH v3 12/30] xfsprogs: Remove all strlen calls in all xfs_attr_* functions for attr names Allison Henderson
2018-09-26 10:23 ` [PATCH v3 13/30] xfsprogs: get directory offset when adding directory name Allison Henderson
2018-09-26 10:23 ` [PATCH v3 14/30] xfsprogs: get directory offset when removing " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 15/30] xfsprogs: get directory offset when replacing a " Allison Henderson
2018-09-26 10:23 ` [PATCH v3 16/30] xfsprogs: add parent pointer support to attribute code Allison Henderson
2018-09-26 10:23 ` [PATCH v3 17/30] xfsprogs: define parent pointer xattr format Allison Henderson
2018-09-26 10:23 ` [PATCH v3 18/30] xfsprogs: extent transaction reservations for parent attributes Allison Henderson
2018-09-26 10:23 ` [PATCH v3 19/30] xfsprogs: parent pointer attribute creation Allison Henderson
2018-09-26 10:23 ` [PATCH v3 20/30] xfsprogs: Add the parent pointer support to the superblock version 5 Allison Henderson
2018-09-26 10:23 ` [PATCH v3 21/30] xfsprogs: Add helper function xfs_attr_list_context_init Allison Henderson
2018-09-26 10:23 ` [PATCH v3 22/30] xfsprogs: Add parent pointer ioctl Allison Henderson
2018-09-26 10:23 ` [PATCH v3 23/30] xfs_io: Add delayed attributes error tag Allison Henderson
2018-09-26 10:23 ` [PATCH v3 24/30] xfsprogs: Add parent pointer flag to cmd Allison Henderson
2018-09-26 10:23 ` [PATCH v3 25/30] xfsprogs: Add log item printing for ATTRI and ATTRD Allison Henderson
2018-09-26 10:23 ` Allison Henderson [this message]
2018-09-26 10:23 ` [PATCH v3 27/30] xfsprogs: Add parent pointers to recreated inodes Allison Henderson
2018-09-26 10:23 ` [PATCH v3 28/30] xfsprogs: Add parent pointers during protofile creation Allison Henderson
2018-09-26 10:23 ` [PATCH v3 29/30] xfsprogs: implement the upper half of parent pointers Allison Henderson
2018-09-26 10:23 ` [PATCH v3 30/30] xfsprogs: Add i, n and f flags to parent command Allison Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1537957413-10630-27-git-send-email-allison.henderson@oracle.com \
    --to=allison.henderson@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).