• Eric Biggers's avatar
    f2fs: don't use casefolded comparison for "." and ".." · b5639bb4
    Eric Biggers authored
    Tryng to rename a directory that has all following properties fails with
    EINVAL and triggers the 'WARN_ON_ONCE(!fscrypt_has_encryption_key(dir))'
    in f2fs_match_ci_name():
    
        - The directory is casefolded
        - The directory is encrypted
        - The directory's encryption key is not yet set up
        - The parent directory is *not* encrypted
    
    The problem is incorrect handling of the lookup of ".." to get the
    parent reference to update.  fscrypt_setup_filename() treats ".." (and
    ".") specially, as it's never encrypted.  It's passed through as-is, and
    setting up the directory's key is not attempted.  As the name isn't a
    no-key name, f2fs treats it as a "normal" name and attempts a casefolded
    comparison.  That breaks the assumption of the WARN_ON_ONCE() in
    f2fs_match_ci_name() which assumes that for encrypted directories,
    casefolded comparisons only happen when the directory's key is set up.
    
    We could just remove this WARN_ON_ONCE().  However, since casefolding is
    always a no-op on "." and ".." anyway, let's instead just not casefold
    these names.  This results in the standard bytewise comparison.
    
    Fixes: 7ad08a58 ("f2fs: Handle casefolding with Encryption")
    Cc: <stable@vger.kernel.org> # v5.11+
    Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
    Reviewed-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    b5639bb4
dir.c 28.6 KB