mirror of
https://github.com/torvalds/linux.git
synced 2026-06-06 13:37:36 +02:00
ANDROID: f2fs: fix bad merge resolutions
The encrypt+casefold support needed to be adjusted following refactoring of f2fs filename handing upstream. Also, the upstream change to f2fs_d_compare() needed to be moved to generic_ci_d_compare(). See http://aosp/1341990 and also the other branches like android-5.4-stable. Also, a call f2fs_set_bio_crypt_ctx() went missing. Fixes:8912845e4e("Merge42612e7763("Merge tag 'f2fs-for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs") into android-mainline") Change-Id: Icd92029bab74e161497a1f03201826a737955725 Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
parent
122a2dad22
commit
2b4c70da98
|
|
@ -919,6 +919,8 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
|
|||
if (!bio) {
|
||||
bio = __bio_alloc(fio, BIO_MAX_PAGES);
|
||||
__attach_io_flag(fio);
|
||||
f2fs_set_bio_crypt_ctx(bio, fio->page->mapping->host,
|
||||
fio->page->index, fio, GFP_NOIO);
|
||||
bio_set_op_attrs(bio, fio->op, fio->op_flags);
|
||||
|
||||
add_bio_entry(fio->sbi, bio, page, fio->temp);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
||||
* http://www.samsung.com/
|
||||
*/
|
||||
#include <asm/unaligned.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/f2fs_fs.h>
|
||||
#include <linux/sched/signal.h>
|
||||
|
|
@ -476,17 +477,39 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
|
|||
f2fs_put_page(page, 1);
|
||||
}
|
||||
|
||||
static void init_dent_inode(const struct f2fs_filename *fname,
|
||||
static void init_dent_inode(struct inode *dir, struct inode *inode,
|
||||
const struct f2fs_filename *fname,
|
||||
struct page *ipage)
|
||||
{
|
||||
struct f2fs_inode *ri;
|
||||
|
||||
if (!fname) /* tmpfile case? */
|
||||
return;
|
||||
|
||||
f2fs_wait_on_page_writeback(ipage, NODE, true, true);
|
||||
|
||||
/* copy name info. to this inode page */
|
||||
ri = F2FS_INODE(ipage);
|
||||
ri->i_namelen = cpu_to_le32(fname->disk_name.len);
|
||||
memcpy(ri->i_name, fname->disk_name.name, fname->disk_name.len);
|
||||
if (IS_ENCRYPTED(dir)) {
|
||||
file_set_enc_name(inode);
|
||||
/*
|
||||
* Roll-forward recovery doesn't have encryption keys available,
|
||||
* so it can't compute the dirhash for encrypted+casefolded
|
||||
* filenames. Append it to i_name if possible. Else, disable
|
||||
* roll-forward recovery of the dentry (i.e., make fsync'ing the
|
||||
* file force a checkpoint) by setting LOST_PINO.
|
||||
*/
|
||||
if (IS_CASEFOLDED(dir)) {
|
||||
if (fname->disk_name.len + sizeof(f2fs_hash_t) <=
|
||||
F2FS_NAME_LEN)
|
||||
put_unaligned(fname->hash, (f2fs_hash_t *)
|
||||
&ri->i_name[fname->disk_name.len]);
|
||||
else
|
||||
file_lost_pino(inode);
|
||||
}
|
||||
}
|
||||
set_page_dirty(ipage);
|
||||
}
|
||||
|
||||
|
|
@ -569,11 +592,7 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
|
|||
return page;
|
||||
}
|
||||
|
||||
if (fname) {
|
||||
init_dent_inode(fname, page);
|
||||
if (IS_ENCRYPTED(dir))
|
||||
file_set_enc_name(inode);
|
||||
}
|
||||
init_dent_inode(dir, inode, fname, page);
|
||||
|
||||
/*
|
||||
* This file should be checkpointed during fsync.
|
||||
|
|
|
|||
|
|
@ -540,9 +540,11 @@ struct f2fs_filename {
|
|||
#ifdef CONFIG_UNICODE
|
||||
/*
|
||||
* For casefolded directories: the casefolded name, but it's left NULL
|
||||
* if the original name is not valid Unicode or if the filesystem is
|
||||
* doing an internal operation where usr_fname is also NULL. In these
|
||||
* cases we fall back to treating the name as an opaque byte sequence.
|
||||
* if the original name is not valid Unicode, if the directory is both
|
||||
* casefolded and encrypted and its encryption key is unavailable, or if
|
||||
* the filesystem is doing an internal operation where usr_fname is also
|
||||
* NULL. In all these cases we fall back to treating the name as an
|
||||
* opaque byte sequence.
|
||||
*/
|
||||
struct fscrypt_str cf_name;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -111,7 +111,9 @@ void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname)
|
|||
* If the casefolded name is provided, hash it instead of the
|
||||
* on-disk name. If the casefolded name is *not* provided, that
|
||||
* should only be because the name wasn't valid Unicode, so fall
|
||||
* back to treating the name as an opaque byte sequence.
|
||||
* back to treating the name as an opaque byte sequence. Note
|
||||
* that to handle encrypted directories, the fallback must use
|
||||
* usr_fname (plaintext) rather than disk_name (ciphertext).
|
||||
*/
|
||||
WARN_ON_ONCE(!fname->usr_fname->name);
|
||||
if (fname->cf_name.name) {
|
||||
|
|
@ -121,6 +123,13 @@ void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname)
|
|||
name = fname->usr_fname->name;
|
||||
len = fname->usr_fname->len;
|
||||
}
|
||||
if (IS_ENCRYPTED(dir)) {
|
||||
struct qstr tmp = QSTR_INIT(name, len);
|
||||
|
||||
fname->hash =
|
||||
cpu_to_le32(fscrypt_fname_siphash(dir, &tmp));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
fname->hash = cpu_to_le32(TEA_hash_name(name, len));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright (c) 2012 Samsung Electronics Co., Ltd.
|
||||
* http://www.samsung.com/
|
||||
*/
|
||||
#include <asm/unaligned.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/f2fs_fs.h>
|
||||
#include "f2fs.h"
|
||||
|
|
@ -128,7 +129,16 @@ static int init_recovered_filename(const struct inode *dir,
|
|||
}
|
||||
|
||||
/* Compute the hash of the filename */
|
||||
if (IS_CASEFOLDED(dir)) {
|
||||
if (IS_ENCRYPTED(dir) && IS_CASEFOLDED(dir)) {
|
||||
/*
|
||||
* In this case the hash isn't computable without the key, so it
|
||||
* was saved on-disk.
|
||||
*/
|
||||
if (fname->disk_name.len + sizeof(f2fs_hash_t) > F2FS_NAME_LEN)
|
||||
return -EINVAL;
|
||||
fname->hash = get_unaligned((f2fs_hash_t *)
|
||||
&raw_inode->i_name[fname->disk_name.len]);
|
||||
} else if (IS_CASEFOLDED(dir)) {
|
||||
err = f2fs_init_casefolded_name(dir, fname);
|
||||
if (err)
|
||||
return err;
|
||||
|
|
|
|||
16
fs/libfs.c
16
fs/libfs.c
|
|
@ -1382,11 +1382,27 @@ int generic_ci_d_compare(const struct dentry *dentry, unsigned int len,
|
|||
const struct super_block *sb = dentry->d_sb;
|
||||
const struct unicode_map *um = sb->s_encoding;
|
||||
struct qstr entry = QSTR_INIT(str, len);
|
||||
char strbuf[DNAME_INLINE_LEN];
|
||||
int ret;
|
||||
|
||||
if (!inode || !needs_casefold(inode))
|
||||
goto fallback;
|
||||
|
||||
/*
|
||||
* If the dentry name is stored in-line, then it may be concurrently
|
||||
* modified by a rename. If this happens, the VFS will eventually retry
|
||||
* the lookup, so it doesn't matter what ->d_compare() returns.
|
||||
* However, it's unsafe to call utf8_strncasecmp() with an unstable
|
||||
* string. Therefore, we have to copy the name into a temporary buffer.
|
||||
*/
|
||||
if (len <= DNAME_INLINE_LEN - 1) {
|
||||
memcpy(strbuf, str, len);
|
||||
strbuf[len] = 0;
|
||||
entry.name = strbuf;
|
||||
/* prevent compiler from optimizing out the temporary buffer */
|
||||
barrier();
|
||||
}
|
||||
|
||||
ret = utf8_strncasecmp(um, name, &entry);
|
||||
if (ret >= 0)
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user