All of lore.kernel.org
 help / color / mirror / Atom feed
From: allison.henderson@oracle.com
To: linux-xfs@vger.kernel.org
Subject: [PATCH v5 09/25] xfsprogs: Add xfs_verify_pptr
Date: Thu, 10 Nov 2022 14:05:11 -0700	[thread overview]
Message-ID: <20221110210527.56628-10-allison.henderson@oracle.com> (raw)
In-Reply-To: <20221110210527.56628-1-allison.henderson@oracle.com>

From: Allison Henderson <allison.henderson@oracle.com>

Source kernel commit: b328f630fcee8dc96e0e3942355fd211f8e15a5d

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>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/xfs_attr.c      | 47 +++++++++++++++++++++++++++++++++++++++---
 libxfs/xfs_attr.h      |  3 ++-
 libxfs/xfs_da_format.h |  8 +++++++
 repair/attr_repair.c   | 19 ++++++++++-------
 4 files changed, 66 insertions(+), 11 deletions(-)

diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
index 04f8e349bcbc..d5f1f488b4ff 100644
--- a/libxfs/xfs_attr.c
+++ b/libxfs/xfs_attr.c
@@ -1575,9 +1575,33 @@ out_release:
 	return error;
 }
 
-/* Returns true if the attribute entry name is valid. */
-bool
-xfs_attr_namecheck(
+/*
+ * Verify parent pointer attribute is valid.
+ * Return true on success or false on failure
+ */
+STATIC bool
+xfs_verify_pptr(
+	struct xfs_mount			*mp,
+	const struct xfs_parent_name_rec	*rec)
+{
+	xfs_ino_t				p_ino;
+	xfs_dir2_dataptr_t			p_diroffset;
+
+	p_ino = be64_to_cpu(rec->p_ino);
+	p_diroffset = be32_to_cpu(rec->p_diroffset);
+
+	if (!xfs_verify_ino(mp, p_ino))
+		return false;
+
+	if (p_diroffset > XFS_DIR2_MAX_DATAPTR)
+		return false;
+
+	return true;
+}
+
+/* Returns true if the string attribute entry name is valid. */
+static bool
+xfs_str_attr_namecheck(
 	const void	*name,
 	size_t		length)
 {
@@ -1592,6 +1616,23 @@ xfs_attr_namecheck(
 	return !memchr(name, 0, length);
 }
 
+/* Returns true if the attribute entry name is valid. */
+bool
+xfs_attr_namecheck(
+	struct xfs_mount	*mp,
+	const void		*name,
+	size_t			length,
+	int			flags)
+{
+	if (flags & XFS_ATTR_PARENT) {
+		if (length != sizeof(struct xfs_parent_name_rec))
+			return false;
+		return xfs_verify_pptr(mp, (struct xfs_parent_name_rec *)name);
+	}
+
+	return xfs_str_attr_namecheck(name, length);
+}
+
 int __init
 xfs_attr_intent_init_cache(void)
 {
diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h
index 3e81f3f48560..b79dae788cfb 100644
--- a/libxfs/xfs_attr.h
+++ b/libxfs/xfs_attr.h
@@ -547,7 +547,8 @@ int xfs_attr_get(struct xfs_da_args *args);
 int xfs_attr_set(struct xfs_da_args *args);
 int xfs_attr_set_iter(struct xfs_attr_intent *attr);
 int xfs_attr_remove_iter(struct xfs_attr_intent *attr);
-bool xfs_attr_namecheck(const void *name, size_t length);
+bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length,
+			int flags);
 int xfs_attr_calc_size(struct xfs_da_args *args, int *local);
 void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres,
 			 unsigned int *total);
diff --git a/libxfs/xfs_da_format.h b/libxfs/xfs_da_format.h
index fbebb55b1621..786b942db9a5 100644
--- a/libxfs/xfs_da_format.h
+++ b/libxfs/xfs_da_format.h
@@ -731,6 +731,14 @@ xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
 	return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)];
 }
 
+static inline int
+xfs_attr3_leaf_flags(xfs_attr_leafblock_t *leafp, int idx)
+{
+	struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp);
+
+	return entries[idx].flags;
+}
+
 static inline xfs_attr_leaf_name_remote_t *
 xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx)
 {
diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index c3a6d50267e2..afe8073ca8e2 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -293,8 +293,9 @@ process_shortform_attr(
 		}
 
 		/* namecheck checks for null chars in attr names. */
-		if (!libxfs_attr_namecheck(currententry->nameval,
-					   currententry->namelen)) {
+		if (!libxfs_attr_namecheck(mp, currententry->nameval,
+					   currententry->namelen,
+					   currententry->flags)) {
 			do_warn(
 	_("entry contains illegal character in shortform attribute name\n"));
 			junkit = 1;
@@ -454,12 +455,14 @@ process_leaf_attr_local(
 	xfs_dablk_t		da_bno,
 	xfs_ino_t		ino)
 {
-	xfs_attr_leaf_name_local_t *local;
+	xfs_attr_leaf_name_local_t	*local;
+	int				flags;
 
 	local = xfs_attr3_leaf_name_local(leaf, i);
+	flags = xfs_attr3_leaf_flags(leaf, i);
 	if (local->namelen == 0 ||
-	    !libxfs_attr_namecheck(local->nameval,
-				   local->namelen)) {
+	    !libxfs_attr_namecheck(mp, local->nameval,
+				   local->namelen, flags)) {
 		do_warn(
 	_("attribute entry %d in attr block %u, inode %" PRIu64 " has bad name (namelen = %d)\n"),
 			i, da_bno, ino, local->namelen);
@@ -510,12 +513,14 @@ process_leaf_attr_remote(
 {
 	xfs_attr_leaf_name_remote_t *remotep;
 	char*			value;
+	int			flags;
 
 	remotep = xfs_attr3_leaf_name_remote(leaf, i);
+	flags = xfs_attr3_leaf_flags(leaf, i);
 
 	if (remotep->namelen == 0 ||
-	    !libxfs_attr_namecheck(remotep->name,
-				   remotep->namelen) ||
+	    !libxfs_attr_namecheck(mp, remotep->name,
+				   remotep->namelen, flags) ||
 	    be32_to_cpu(entry->hashval) !=
 			libxfs_da_hashname((unsigned char *)&remotep->name[0],
 					   remotep->namelen) ||
-- 
2.25.1


  parent reply	other threads:[~2022-11-10 21:05 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 21:05 [PATCH v5 00/25] xfsprogs: parent pointers for v5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 01/25] xfsprogs: Fix default superblock attr bits allison.henderson
2022-11-10 21:05 ` [PATCH v5 02/25] xfsprogs: Add new name to attri/d allison.henderson
2022-11-10 21:05 ` [PATCH v5 03/25] xfsprogs: Increase XFS_DEFER_OPS_NR_INODES to 5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 04/25] xfsprogs: get directory offset when adding directory name allison.henderson
2022-11-10 21:05 ` [PATCH v5 05/25] xfsprogs: get directory offset when removing " allison.henderson
2022-11-10 21:05 ` [PATCH v5 06/25] xfsprogs: get directory offset when replacing a " allison.henderson
2022-11-10 21:05 ` [PATCH v5 07/25] xfsprogs: add parent pointer support to attribute code allison.henderson
2022-11-10 21:05 ` [PATCH v5 08/25] xfsprogs: define parent pointer xattr format allison.henderson
2022-11-10 21:05 ` allison.henderson [this message]
2022-11-10 21:05 ` [PATCH v5 10/25] xfsprogs: Increase rename inode reservation allison.henderson
2022-11-10 21:05 ` [PATCH v5 11/25] xfsprogs: extend transaction reservations for parent attributes allison.henderson
2022-11-10 21:05 ` [PATCH v5 12/25] xfsprogs: add parent attributes to link allison.henderson
2022-11-10 21:05 ` [PATCH v5 13/25] xfsprogs: add parent attributes to symlink allison.henderson
2022-11-10 21:05 ` [PATCH v5 14/25] xfsprogs: parent pointer attribute creation allison.henderson
2022-11-10 21:05 ` [PATCH v5 15/25] xfsprogs: remove parent pointers in unlink allison.henderson
2022-11-10 21:05 ` [PATCH v5 16/25] xfsprogs: Add parent pointers to rename allison.henderson
2022-11-10 21:05 ` [PATCH v5 17/25] xfsprogs: Add the parent pointer support to the superblock version 5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 18/25] xfsprogs: Add parent pointer ioctl allison.henderson
2022-11-10 21:05 ` [PATCH v5 19/25] xfsprogs: fix unit conversion error in xfs_log_calc_max_attrsetm_res allison.henderson
2022-11-10 21:05 ` [PATCH v5 20/25] xfsprogs: drop compatibility minimum log size computations for reflink allison.henderson
2022-11-10 21:05 ` [PATCH v5 21/25] xfsprogs: Add parent pointer flag to cmd allison.henderson
2022-11-10 21:05 ` [PATCH v5 22/25] xfsprogs: Print pptrs in ATTRI items allison.henderson
2022-11-10 21:05 ` [PATCH v5 23/25] xfsprogs: implement the upper half of parent pointers allison.henderson
2022-11-10 21:05 ` [PATCH v5 24/25] xfsprogs: Add parent pointers during protofile creation allison.henderson
2022-11-10 21:05 ` [PATCH v5 25/25] 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=20221110210527.56628-10-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.