Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1470431pxb; Fri, 6 Nov 2020 10:23:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXaBakO4Bsbdd8DmH39u5bQa+sdX5asha1t2jovVbm/QpnY/SyN90FDheONw/YjkPCbhyA X-Received: by 2002:a17:906:2b8b:: with SMTP id m11mr3393475ejg.457.1604687010892; Fri, 06 Nov 2020 10:23:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604687010; cv=none; d=google.com; s=arc-20160816; b=qEQP2LkRKxnROAXMeczJ7BgQ3Xyyk+05th7lGo1uKa08HnkLNezamv0exMq50aczK8 Ac3Y9vlvFzG6xJLc1HoPy3HR3o1xAtgrJBhcM1I+k5CbRdGwfwTbL4RENQ3WXWox0QnC jTHypNfgSjeZyu+sj3xipCCwSjHh9T2ed6wkB7mzBTnnBIj3P86dtnnroDQTskxnNZTu hnTBE2e/KzMtfFaelVCs0v50r0mvPXn6CK3UMyzoQal/a3YxoIAWY3YtRK1w1bllKKLH P5M47ijeNfkhFp1faIDmxCpnU/HjzXPU1OFq5O2Tt1c8fZtzL5Sor5pQro9/87ObInxD O3Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lZ4p2eXZ3GEmyHV4rVM++8p0y4UvNMY6bMf1qDZsKws=; b=m9SK3FMyPJ3ljJCTHPXkkdc5Wk/RmkFoNv2fP3dcVsW1nP0bfkqDnZGTw5OxUL7Q3l uEqC+3rQRFtIBpjhy2BE0UkIcUH/1CR5+n9H4/kl4D7KOFnI5aO3X6Ta5xwYZc/CR48A xEVMoaPGny/Kf13pPwMpUwYQ+svGVGCoY+n5+cHxr3EmFTW1I6vownSykJ4TI93eFSti GmDiBpJgjZFk0eqPiGjew/4lWhBkNM5/pKPw1hbKJTvHIixY26Ls/eSxthsC1yfbfT6D Wnj627Wel7tRvkChTCITNyoo/0RO0UrG1b4HjC2Nwa4jOh1o2ynt05VjDTVvOrgsagH4 OIIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0NX2TlHx; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si1630978edn.398.2020.11.06.10.23.06; Fri, 06 Nov 2020 10:23:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0NX2TlHx; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727311AbgKFSXB (ORCPT + 99 others); Fri, 6 Nov 2020 13:23:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:42416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726320AbgKFSXB (ORCPT ); Fri, 6 Nov 2020 13:23:01 -0500 Received: from sol.localdomain (172-10-235-113.lightspeed.sntcca.sbcglobal.net [172.10.235.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1C8E5208FE; Fri, 6 Nov 2020 18:23:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604686980; bh=+Ts7gJxIlSSxSAGj04VSLAnxs4apD4F9ITw6jQ22PEY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0NX2TlHxflTVmPTo23eodQqGodMTxkJunZcQACwq0IMOpi0gAK7EDM2dae732zpuK 5ZIR5rEcWwkExgp4j9QnnDKVxObPrswAdR9Xz4V7lmCZT8wZjWVe9yelUmdVxOViFF e6hBgS3IYsm8hPWyrhBJhqIJJmnD8imQGIM/9Oow= Date: Fri, 6 Nov 2020 10:22:58 -0800 From: Eric Biggers To: Arnaud Ferraris Cc: linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Subject: Re: [PATCH 05/11] e2fsck: Fix entries with invalid encoded characters Message-ID: <20201106182258.GB79496@sol.localdomain> References: <20201105161642.87488-1-arnaud.ferraris@collabora.com> <20201105161642.87488-6-arnaud.ferraris@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201105161642.87488-6-arnaud.ferraris@collabora.com> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 */ }