diff mbox series

[1/3] mkfs: check dirent names when reading protofile

Message ID 167768673411.4130726.18042131075742150245.stgit@magnolia (mailing list archive)
State New, archived
Headers show
Series xfsprogs: random fixes for 6.2 | expand

Commit Message

Darrick J. Wong March 1, 2023, 4:05 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

The protofile parser in mkfs does not check directory entry names when
populating the filesystem.  The libxfs directory code doesn't check them
either, since they depend on the Linux VFS to sanitize incoming names.
If someone puts a slash in the first (name) column in the protofile,
this results in a successful format and xfs_repair -n immediately
complains.

Screen the names that are being read from the protofile.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 mkfs/proto.c |    6 ++++++
 1 file changed, 6 insertions(+)

Comments

Carlos Maiolino March 3, 2023, 10:45 a.m. UTC | #1
On Wed, Mar 01, 2023 at 08:05:34AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> The protofile parser in mkfs does not check directory entry names when
> populating the filesystem.  The libxfs directory code doesn't check them
> either, since they depend on the Linux VFS to sanitize incoming names.
> If someone puts a slash in the first (name) column in the protofile,
> this results in a successful format and xfs_repair -n immediately
> complains.
> 
> Screen the names that are being read from the protofile.

Looks good
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  mkfs/proto.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> 
> diff --git a/mkfs/proto.c b/mkfs/proto.c
> index 68ecdbf3632..7e3fc1b8134 100644
> --- a/mkfs/proto.c
> +++ b/mkfs/proto.c
> @@ -326,6 +326,12 @@ newdirent(
>  	int	error;
>  	int	rsv;
> 
> +	if (!libxfs_dir2_namecheck(name->name, name->len)) {
> +		fprintf(stderr, _("%.*s: invalid directory entry name\n"),
> +				name->len, name->name);
> +		exit(1);
> +	}
> +
>  	rsv = XFS_DIRENTER_SPACE_RES(mp, name->len);
> 
>  	error = -libxfs_dir_createname(tp, pip, name, inum, rsv);
>
diff mbox series

Patch

diff --git a/mkfs/proto.c b/mkfs/proto.c
index 68ecdbf3632..7e3fc1b8134 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -326,6 +326,12 @@  newdirent(
 	int	error;
 	int	rsv;
 
+	if (!libxfs_dir2_namecheck(name->name, name->len)) {
+		fprintf(stderr, _("%.*s: invalid directory entry name\n"),
+				name->len, name->name);
+		exit(1);
+	}
+
 	rsv = XFS_DIRENTER_SPACE_RES(mp, name->len);
 
 	error = -libxfs_dir_createname(tp, pip, name, inum, rsv);