Skip to contentSkip to conversation

xfs: rename MAXPATHLEN to XFS_SYMLINK_MAXLEN

PATCH In review Darrick J. Wong 2 participants 4 messages Jul 7, 2017 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: rename MAXPATHLEN to XFS_SYMLINK_MAXLEN

XFS has a maximum symlink target length of 1024 bytes; this is a holdover from the Irix days. Unfortunately, the constant establishing this is 'MAXPATHLEN' and is /not/ the same as the Linux MAXPATHLEN, which is 4096.

The kernel enforces its 1024 byte MAXPATHLEN on symlink targets, but xfsprogs picks up the (Linux) system 4096 byte MAXPATHLEN, which means that xfs_repair doesn't complain about oversized symlinks.

Since this is an on-disk format constraint, put the define in the XFS namespace and move everything over to use the new name.

---
 fs/xfs/libxfs/xfs_format.h         |    1 +
 fs/xfs/libxfs/xfs_symlink_remote.c |    2 +-
 fs/xfs/libxfs/xfs_trans_resv.c     |    4 ++--
 fs/xfs/xfs_iops.c                  |    2 +-
 fs/xfs/xfs_linux.h                 |    1 -
 fs/xfs/xfs_symlink.c               |    6 +++---
 6 files changed, 8 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_format.h +1 -0
index e204a94..23229f0 100644
@@ -1211,6 +1211,7 @@ struct xfs_dsymlink_hdr {
 
 #define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
 
+#define XFS_SYMLINK_MAXLEN	1024
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 3 extents back from
fs/xfs/libxfs/xfs_symlink_remote.c +1 -1
index 2e2c671..c484877 100644
@@ -114,7 +114,7 @@ xfs_symlink_verify(
 	if (bp->b_bn != be64_to_cpu(dsl->sl_blkno))
 		return false;
 	if (be32_to_cpu(dsl->sl_offset) +
-				be32_to_cpu(dsl->sl_bytes) >= MAXPATHLEN)
+				be32_to_cpu(dsl->sl_bytes) >= XFS_SYMLINK_MAXLEN)
 		return false;
 	if (dsl->sl_owner == 0)
 		return false;
fs/xfs/libxfs/xfs_trans_resv.c +2 -2
index b456cca..6bd916b 100644
@@ -477,14 +477,14 @@ xfs_calc_mkdir_reservation(
 /*
  * Making a new symplink is the same as creating a new file, but
  * with the added blocks for remote symlink data which can be up to 1kB in
- * length (MAXPATHLEN).
+ * length (XFS_SYMLINK_MAXLEN).
  */
 STATIC uint
 xfs_calc_symlink_reservation(
 	struct xfs_mount	*mp)
 {
 	return xfs_calc_create_reservation(mp) +
-	       xfs_calc_buf_res(1, MAXPATHLEN);
+	       xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN);
 }
 
 /*
fs/xfs/xfs_iops.c +1 -1
index 077e2b2..469c9fa 100644
@@ -460,7 +460,7 @@ xfs_vn_get_link(
 	if (!dentry)
 		return ERR_PTR(-ECHILD);
 
-	link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
+	link = kmalloc(XFS_SYMLINK_MAXLEN+1, GFP_KERNEL);
 	if (!link)
 		goto out_err;
 
fs/xfs/xfs_linux.h +0 -1
index ecdae42..44abaec 100644
@@ -143,7 +143,6 @@ typedef __u32			xfs_nlink_t;
 #define __return_address __builtin_return_address(0)
 
 #define XFS_PROJID_DEFAULT	0
-#define MAXPATHLEN	1024
 
 #define MIN(a,b)	(min(a,b))
 #define MAX(a,b)	(max(a,b))
fs/xfs/xfs_symlink.c +3 -3
index 49380485..12cd9cf7 100644
@@ -143,7 +143,7 @@ xfs_readlink(
 	if (!pathlen)
 		goto out;
 
-	if (pathlen < 0 || pathlen > MAXPATHLEN) {
+	if (pathlen < 0 || pathlen > XFS_SYMLINK_MAXLEN) {
 		xfs_alert(mp, "%s: inode (%llu) bad symlink length (%lld)",
 			 __func__, (unsigned long long) ip->i_ino,
 			 (long long) pathlen);
@@ -202,7 +202,7 @@ xfs_symlink(
 	 * Check component lengths of the target path name.
 	 */
 	pathlen = strlen(target_path);
-	if (pathlen >= MAXPATHLEN)      /* total string too long */
+	if (pathlen >= XFS_SYMLINK_MAXLEN)      /* total string too long */
 		return -ENAMETOOLONG;
 
 	udqp = gdqp = NULL;
@@ -559,7 +559,7 @@ xfs_inactive_symlink(
 		return 0;
 	}
 
-	if (pathlen < 0 || pathlen > MAXPATHLEN) {
+	if (pathlen < 0 || pathlen > XFS_SYMLINK_MAXLEN) {
 		xfs_alert(mp, "%s: inode (0x%llx) bad symlink length (%d)",
 			 __func__, (unsigned long long)ip->i_ino, pathlen);
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
#1 lore raw

PATCH 1/1 libxfs: rename MAXPATHLEN to XFS_SYMLINK_MAXLEN

XFS has a maximum symlink target length of 1024 bytes; this is a holdover from the Irix days. Unfortunately, the constant establishing this was 'MAXPATHLEN', and is /not/ the same as the Linux MAXPATHLEN, which is 4096.

The kernel enforces its 1024 byte MAXPATHLEN on symlink targets, but xfsprogs picks up the (Linux) system 4096 byte MAXPATHLEN, which means that xfs_repair doesn't complain about oversized symlinks.

Since this is an on-disk format constraint, put the define in the XFS namespace. As a side effect of the rename, xfs_repair wil detect oversized symlinks and clean them off the system.

---
 libxfs/xfs_format.h         |    1 +
 libxfs/xfs_symlink_remote.c |    2 +-
 libxfs/xfs_trans_resv.c     |    4 ++--
 repair/dinode.c             |    6 +++---
 repair/xfs_repair.c         |    2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)
libxfs/xfs_format.h +1 -0
index a53f035..79a72bb 100644
@@ -1211,6 +1211,7 @@ struct xfs_dsymlink_hdr {
 
 #define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
 
+#define XFS_SYMLINK_MAXLEN	1024
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 3 extents back from
libxfs/xfs_symlink_remote.c +1 -1
index 04c7446..d638530 100644
@@ -110,7 +110,7 @@ xfs_symlink_verify(
 	if (bp->b_bn != be64_to_cpu(dsl->sl_blkno))
 		return false;
 	if (be32_to_cpu(dsl->sl_offset) +
-				be32_to_cpu(dsl->sl_bytes) >= MAXPATHLEN)
+				be32_to_cpu(dsl->sl_bytes) >= XFS_SYMLINK_MAXLEN)
 		return false;
 	if (dsl->sl_owner == 0)
 		return false;
libxfs/xfs_trans_resv.c +2 -2
index 5152a5b..d35a45f 100644
@@ -476,14 +476,14 @@ xfs_calc_mkdir_reservation(
 /*
  * Making a new symplink is the same as creating a new file, but
  * with the added blocks for remote symlink data which can be up to 1kB in
- * length (MAXPATHLEN).
+ * length (XFS_SYMLINK_MAXLEN).
  */
 STATIC uint
 xfs_calc_symlink_reservation(
 	struct xfs_mount	*mp)
 {
 	return xfs_calc_create_reservation(mp) +
-	       xfs_calc_buf_res(1, MAXPATHLEN);
+	       xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN);
 }
 
 /*
repair/dinode.c +3 -3
index da87217..f005335 100644
@@ -1259,7 +1259,7 @@ null_check(char *name, int length)
 {
 	int i;
 
-	ASSERT(length < MAXPATHLEN);
+	ASSERT(length < XFS_SYMLINK_MAXLEN);
 
 	for (i = 0; i < length; i++, name++)  {
 		if (*name == '\0')
@@ -1371,7 +1371,7 @@ process_symlink(
 	blkmap_t 	*blkmap)
 {
 	char			*symlink;
-	char			data[MAXPATHLEN];
+	char			data[XFS_SYMLINK_MAXLEN];
 
 	/*
 	 * check size against kernel symlink limits.  we know
@@ -1379,7 +1379,7 @@ process_symlink(
 	 * the inode is structurally ok so we don't have to check
 	 * for that
 	 */
-	if (be64_to_cpu(dino->di_size) >= MAXPATHLEN)  {
+	if (be64_to_cpu(dino->di_size) >= XFS_SYMLINK_MAXLEN)  {
 	       do_warn(_("symlink in inode %" PRIu64 " too long (%llu chars)\n"),
 		       lino, (unsigned long long) be64_to_cpu(dino->di_size));
 		return(1);
repair/xfs_repair.c +1 -1
index ab60c0f..b2dd91b 100644
@@ -761,7 +761,7 @@ main(int argc, char **argv)
 	glob_agcount = mp->m_sb.sb_agcount;
 
 	chunks_pblock = mp->m_sb.sb_inopblock / XFS_INODES_PER_CHUNK;
-	max_symlink_blocks = libxfs_symlink_blocks(mp, MAXPATHLEN);
+	max_symlink_blocks = libxfs_symlink_blocks(mp, XFS_SYMLINK_MAXLEN);
 	inodes_per_cluster = MAX(mp->m_sb.sb_inopblock,
 			mp->m_inode_cluster_size >> mp->m_sb.sb_inodelog);
 
Reviewed-by on v1 1/1
#2 lore raw

Re: [PATCH] libxfs: rename MAXPATHLEN to XFS_SYMLINK_MAXLEN

Quoted 9 lines · Darrick J. Wong

XFS has a maximum symlink target length of 1024 bytes; this is a holdover from the Irix days. Unfortunately, the constant establishing this was 'MAXPATHLEN', and is /not/ the same as the Linux MAXPATHLEN, which is 4096.

The kernel enforces its 1024 byte MAXPATHLEN on symlink targets, but xfsprogs picks up the (Linux) system 4096 byte MAXPATHLEN, which means that xfs_repair doesn't complain about oversized symlinks.

Quoted 6 lines

Since this is an on-disk format constraint, put the define in the XFS namespace. As a side effect of the rename, xfs_repair wil detect oversized symlinks and clean them off the system.

---

Quoted 101 lines
 libxfs/xfs_format.h         |    1 +
 libxfs/xfs_symlink_remote.c |    2 +-
 libxfs/xfs_trans_resv.c     |    4 ++--
 repair/dinode.c             |    6 +++---
 repair/xfs_repair.c         |    2 +-
 5 files changed, 8 insertions(+), 7 deletions(-)
libxfs/xfs_format.h +1 -0
index a53f035..79a72bb 100644
@@ -1211,6 +1211,7 @@ struct xfs_dsymlink_hdr {
 
 #define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
 
+#define XFS_SYMLINK_MAXLEN	1024
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 3 extents back from
libxfs/xfs_symlink_remote.c +1 -1
index 04c7446..d638530 100644
@@ -110,7 +110,7 @@ xfs_symlink_verify(
 	if (bp->b_bn != be64_to_cpu(dsl->sl_blkno))
 		return false;
 	if (be32_to_cpu(dsl->sl_offset) +
-				be32_to_cpu(dsl->sl_bytes) >= MAXPATHLEN)
+				be32_to_cpu(dsl->sl_bytes) >= XFS_SYMLINK_MAXLEN)
 		return false;
 	if (dsl->sl_owner == 0)
 		return false;
libxfs/xfs_trans_resv.c +2 -2
index 5152a5b..d35a45f 100644
@@ -476,14 +476,14 @@ xfs_calc_mkdir_reservation(
 /*
  * Making a new symplink is the same as creating a new file, but
  * with the added blocks for remote symlink data which can be up to 1kB in
- * length (MAXPATHLEN).
+ * length (XFS_SYMLINK_MAXLEN).
  */
 STATIC uint
 xfs_calc_symlink_reservation(
 	struct xfs_mount	*mp)
 {
 	return xfs_calc_create_reservation(mp) +
-	       xfs_calc_buf_res(1, MAXPATHLEN);
+	       xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN);
 }
 
 /*
repair/dinode.c +3 -3
index da87217..f005335 100644
@@ -1259,7 +1259,7 @@ null_check(char *name, int length)
 {
 	int i;
 
-	ASSERT(length < MAXPATHLEN);
+	ASSERT(length < XFS_SYMLINK_MAXLEN);
 
 	for (i = 0; i < length; i++, name++)  {
 		if (*name == '\0')
@@ -1371,7 +1371,7 @@ process_symlink(
 	blkmap_t 	*blkmap)
 {
 	char			*symlink;
-	char			data[MAXPATHLEN];
+	char			data[XFS_SYMLINK_MAXLEN];
 
 	/*
 	 * check size against kernel symlink limits.  we know
@@ -1379,7 +1379,7 @@ process_symlink(
 	 * the inode is structurally ok so we don't have to check
 	 * for that
 	 */
-	if (be64_to_cpu(dino->di_size) >= MAXPATHLEN)  {
+	if (be64_to_cpu(dino->di_size) >= XFS_SYMLINK_MAXLEN)  {
 	       do_warn(_("symlink in inode %" PRIu64 " too long (%llu chars)\n"),
 		       lino, (unsigned long long) be64_to_cpu(dino->di_size));
 		return(1);
repair/xfs_repair.c +1 -2
index ab60c0f..b2dd91b 100644
@@ -761,7 +761,7 @@ main(int argc, char **argv)
 	glob_agcount = mp->m_sb.sb_agcount;
 
 	chunks_pblock = mp->m_sb.sb_inopblock / XFS_INODES_PER_CHUNK;
-	max_symlink_blocks = libxfs_symlink_blocks(mp, MAXPATHLEN);
+	max_symlink_blocks = libxfs_symlink_blocks(mp, XFS_SYMLINK_MAXLEN);
 	inodes_per_cluster = MAX(mp->m_sb.sb_inopblock,
 			mp->m_inode_cluster_size >> mp->m_sb.sb_inodelog);
 
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Reviewed-by on v1 1/1
#3 lore raw
In reply to Darrick J. Wong
Quoted 9 lines · Darrick J. Wong

XFS has a maximum symlink target length of 1024 bytes; this is a holdover from the Irix days. Unfortunately, the constant establishing this is 'MAXPATHLEN' and is /not/ the same as the Linux MAXPATHLEN, which is 4096.

The kernel enforces its 1024 byte MAXPATHLEN on symlink targets, but xfsprogs picks up the (Linux) system 4096 byte MAXPATHLEN, which means that xfs_repair doesn't complain about oversized symlinks.

Quoted 5 lines

Since this is an on-disk format constraint, put the define in the XFS namespace and move everything over to use the new name.

---

Quoted 114 lines
 fs/xfs/libxfs/xfs_format.h         |    1 +
 fs/xfs/libxfs/xfs_symlink_remote.c |    2 +-
 fs/xfs/libxfs/xfs_trans_resv.c     |    4 ++--
 fs/xfs/xfs_iops.c                  |    2 +-
 fs/xfs/xfs_linux.h                 |    1 -
 fs/xfs/xfs_symlink.c               |    6 +++---
 6 files changed, 8 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_format.h +1 -0
index e204a94..23229f0 100644
@@ -1211,6 +1211,7 @@ struct xfs_dsymlink_hdr {
 
 #define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
 
+#define XFS_SYMLINK_MAXLEN	1024
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 3 extents back from
fs/xfs/libxfs/xfs_symlink_remote.c +1 -1
index 2e2c671..c484877 100644
@@ -114,7 +114,7 @@ xfs_symlink_verify(
 	if (bp->b_bn != be64_to_cpu(dsl->sl_blkno))
 		return false;
 	if (be32_to_cpu(dsl->sl_offset) +
-				be32_to_cpu(dsl->sl_bytes) >= MAXPATHLEN)
+				be32_to_cpu(dsl->sl_bytes) >= XFS_SYMLINK_MAXLEN)
 		return false;
 	if (dsl->sl_owner == 0)
 		return false;
fs/xfs/libxfs/xfs_trans_resv.c +2 -2
index b456cca..6bd916b 100644
@@ -477,14 +477,14 @@ xfs_calc_mkdir_reservation(
 /*
  * Making a new symplink is the same as creating a new file, but
  * with the added blocks for remote symlink data which can be up to 1kB in
- * length (MAXPATHLEN).
+ * length (XFS_SYMLINK_MAXLEN).
  */
 STATIC uint
 xfs_calc_symlink_reservation(
 	struct xfs_mount	*mp)
 {
 	return xfs_calc_create_reservation(mp) +
-	       xfs_calc_buf_res(1, MAXPATHLEN);
+	       xfs_calc_buf_res(1, XFS_SYMLINK_MAXLEN);
 }
 
 /*
fs/xfs/xfs_iops.c +1 -1
index 077e2b2..469c9fa 100644
@@ -460,7 +460,7 @@ xfs_vn_get_link(
 	if (!dentry)
 		return ERR_PTR(-ECHILD);
 
-	link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
+	link = kmalloc(XFS_SYMLINK_MAXLEN+1, GFP_KERNEL);
 	if (!link)
 		goto out_err;
 
fs/xfs/xfs_linux.h +0 -1
index ecdae42..44abaec 100644
@@ -143,7 +143,6 @@ typedef __u32			xfs_nlink_t;
 #define __return_address __builtin_return_address(0)
 
 #define XFS_PROJID_DEFAULT	0
-#define MAXPATHLEN	1024
 
 #define MIN(a,b)	(min(a,b))
 #define MAX(a,b)	(max(a,b))
fs/xfs/xfs_symlink.c +3 -4
index 49380485..12cd9cf7 100644
@@ -143,7 +143,7 @@ xfs_readlink(
 	if (!pathlen)
 		goto out;
 
-	if (pathlen < 0 || pathlen > MAXPATHLEN) {
+	if (pathlen < 0 || pathlen > XFS_SYMLINK_MAXLEN) {
 		xfs_alert(mp, "%s: inode (%llu) bad symlink length (%lld)",
 			 __func__, (unsigned long long) ip->i_ino,
 			 (long long) pathlen);
@@ -202,7 +202,7 @@ xfs_symlink(
 	 * Check component lengths of the target path name.
 	 */
 	pathlen = strlen(target_path);
-	if (pathlen >= MAXPATHLEN)      /* total string too long */
+	if (pathlen >= XFS_SYMLINK_MAXLEN)      /* total string too long */
 		return -ENAMETOOLONG;
 
 	udqp = gdqp = NULL;
@@ -559,7 +559,7 @@ xfs_inactive_symlink(
 		return 0;
 	}
 
-	if (pathlen < 0 || pathlen > MAXPATHLEN) {
+	if (pathlen < 0 || pathlen > XFS_SYMLINK_MAXLEN) {
 		xfs_alert(mp, "%s: inode (0x%llx) bad symlink length (%d)",
 			 __func__, (unsigned long long)ip->i_ino, pathlen);
 		xfs_iunlock(ip, XFS_ILOCK_EXCL);
--

To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html