public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Cc: linux-ext4@vger.kernel.org,
	Gabriel Krisman Bertazi <krisman@collabora.com>
Subject: Re: [PATCH 05/11] e2fsck: Fix entries with invalid encoded characters
Date: Fri, 6 Nov 2020 10:22:58 -0800	[thread overview]
Message-ID: <20201106182258.GB79496@sol.localdomain> (raw)
In-Reply-To: <20201105161642.87488-6-arnaud.ferraris@collabora.com>

On Thu, Nov 05, 2020 at 05:16:37PM +0100, Arnaud Ferraris wrote:
> diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
> index 8eecd958..968734e8 100644
> --- a/e2fsck/pass1.c
> +++ b/e2fsck/pass1.c

Theres a comment at the top of this file that could be updated to mention
inode_casefold_map.

> +static int encoded_check_name(e2fsck_t ctx,
> +			      struct ext2_dir_entry *dirent,
> +			      struct problem_context *pctx)
> +{
> +	const struct ext2fs_nls_table *tbl = ctx->fs->encoding;
> +	int ret;
> +	int len = ext2fs_dirent_name_len(dirent);
> +	char *pos, *end;
> +
> +	ret = ext2fs_check_encoded_name(tbl, dirent->name, len, &pos);
> +	if (ret < 0) {
> +		fatal_error(ctx, _("NLS is broken."));
> +	} else if(ret > 0) {
> +		ret = fix_problem(ctx, PR_2_BAD_NAME, pctx);
> +		if (ret) {
> +			end = &dirent->name[len];
> +			for (; *pos && pos != end; pos++)
> +				*pos = '.';
> +		}
> +	}
> +
> +	return (ret || check_name(ctx, dirent, pctx));
> +}

Maybe this should use a new problem code instead of reusing PR_2_BAD_NAME?

> @@ -998,11 +1028,18 @@ static int check_dir_block(ext2_filsys fs,
>  	size_t	max_block_size;
>  	int	hash_flags = 0;
>  	static char *eop_read_dirblock = NULL;
> +	int cf_dir = 0;
>  
>  	cd = (struct check_dir_struct *) priv_data;
>  	ibuf = buf = cd->buf;
>  	ctx = cd->ctx;
>  
> +	/* We only want filename encoding verification on strict
> +	 * mode. */
> +	if (ext2fs_test_inode_bitmap2(ctx->inode_casefold_map, ino) &&
> +	    (ctx->fs->super->s_encoding_flags & EXT4_ENC_STRICT_MODE_FL))
> +		cf_dir = 1;
> +
>  	if (ctx->flags & E2F_FLAG_RUN_RETURN)
>  		return DIRENT_ABORT;
>  
> @@ -1483,7 +1520,11 @@ skip_checksum:
>  		if (check_filetype(ctx, dirent, ino, &cd->pctx))
>  			dir_modified++;
>  
> -		if (dir_encpolicy_id == NO_ENCRYPTION_POLICY) {
> +		if (cf_dir) {
> +			/* casefolded directory */
> +			if (encoded_check_name(ctx, dirent, &cd->pctx))
> +				dir_modified++;
> +		} else if (dir_encpolicy_id == NO_ENCRYPTION_POLICY) {
>  			/* Unencrypted directory */
>  			if (check_name(ctx, dirent, &cd->pctx))
>  				dir_modified++;

It might be a good idea to rearrange this logic to be ready for directories that
are both encrypted and casefolded, where checking the encoded names won't be
possible:

	if (dir_encpolicy_id != NO_ENCRYPTION_POLICY) {
		/* handle encrypted dir */
	} else if (cf_dir) {
		/* handle casefolded dir */
	} else {
		/* handle regular dir */
	}

  reply	other threads:[~2020-11-06 18:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 16:16 [PATCH 00/11] e2fsprogs: improve case-insensitive fs support Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 01/11] tune2fs: Allow enabling casefold feature after fs creation Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 02/11] tune2fs: Fix casefold+encrypt error message Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 03/11] ext2fs: Add method to validate casefolded strings Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 04/11] ext2fs: Implement faster CI comparison of strings Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 05/11] e2fsck: Fix entries with invalid encoded characters Arnaud Ferraris
2020-11-06 18:22   ` Eric Biggers [this message]
2020-11-05 16:16 ` [PATCH 06/11] e2fsck: Support casefold directories when rehashing Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 07/11] dict: Support comparison with context Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 08/11] e2fsck: Detect duplicated casefolded direntries for rehash Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 09/11] e2fsck: Add option to force encoded filename verification Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 10/11] e2fsck.8.in: Document check_encoding extended option Arnaud Ferraris
2020-11-05 16:16 ` [PATCH 11/11] tests: f_bad_fname: Test fixes of invalid filenames and duplicates Arnaud Ferraris
2020-11-06 18:18 ` [PATCH 00/11] e2fsprogs: improve case-insensitive fs support Eric Biggers
2020-11-20 12:22   ` Arnaud Ferraris

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=20201106182258.GB79496@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=arnaud.ferraris@collabora.com \
    --cc=krisman@collabora.com \
    --cc=linux-ext4@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