This pull request contains updates for UBI and UBIFS:

UBI:
 	- Use in-tree fault injection framework and add new injection types
 	- Fix for a memory leak in the block driver
 
 UBIFS:
 	- kernel-doc fixes
 	- Various minor fixes
 -----BEGIN PGP SIGNATURE-----
 
 iQJKBAABCAA0FiEEdgfidid8lnn52cLTZvlZhesYu8EFAmWi8k0WHHJpY2hhcmRA
 c2lnbWEtc3Rhci5hdAAKCRBm+VmF6xi7wVMEEAClpCwGQ1zjViuDR+ly1etpd2VJ
 SVH687jQ5bj92joMbJuX1n3iucDKu22KNR6tuePtEWousKEjiP5MU5Vhj4qcEZJj
 ORwtLOhchF7EHokJ16O2zBTBjznQuSmy0TG8vB/4hKj1a9FHLYPoDpZ595i2ATIA
 sh4+jfTRiOviX1SWe3qP9Hwx/WBXJpNluNNosabaEkTPe6CEAqnw92Hsm8PC8WY0
 0F9zKPbRTiu/Mt8PoF0YHo9pNsX0TikJMPj+QuBSOt3tK5PmPFttL6ce5Zal+wi3
 Df+8Qqw2QPchMDesaeZHtknZkZWbxtWPk+1U7EaLUwb6lw7cyI9SPWtQFYS4Ot6r
 ieUW5mQt2arC6Yjj1u+pFLIvLJOYgg0kiPySvRiA4EKkAyTMBjQzeyf0XCVrgW2s
 UeBiQTz5LkL4soAo/aWDyny81RXJjtuMpn/+WAq4o36LZkG4aiGXh+ue5l5d9Mq5
 Fh/MNyRA9le5STebrqqH7TBtiOwBG+ZJ9yqYffzya+756od6wsnemGfaZ/pPzzSe
 sp9MEYzrz4hhRvDHegKcIbxb+OUVFNJ1t5gdIUsZAqWARxcfYD9xeqyHVVhvFDjf
 UzQhZXfKgdnwp4zWHtSBRkDKCEMvxG8Nw3Rnp9ayZwxiQBBalRV6MV33g5RXRIis
 Xp+fCRu3gjlhBzlU6w==
 =5I24
 -----END PGP SIGNATURE-----

Merge tag 'ubifs-for-linus-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs

Pull UBI and UBIFS updates from Richard Weinberger:
 "UBI:
   - Use in-tree fault injection framework and add new injection types
   - Fix for a memory leak in the block driver

  UBIFS:
   - kernel-doc fixes
   - Various minor fixes"

* tag 'ubifs-for-linus-6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs:
  ubi: block: fix memleak in ubiblock_create()
  ubifs: fix kernel-doc warnings
  mtd: Add several functions to the fail_function list
  ubi: Reserve sufficient buffer length for the input mask
  ubi: Add six fault injection type for testing
  ubi: Split io_failures into write_failure and erase_failure
  ubi: Use the fault injection framework to enhance the fault injection capability
  ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path
  ubifs: Check @c->dirty_[n|p]n_cnt and @c->nroot state under @c->lp_mutex
  ubifs: describe function parameters
  ubifs: auth.c: fix kernel-doc function prototype warning
  ubifs: use crypto_shash_tfm_digest() in ubifs_hmac_wkm()
This commit is contained in:
Linus Torvalds 2024-01-17 10:27:13 -08:00
commit 0c6bc37255
12 changed files with 558 additions and 107 deletions

View file

@ -30,6 +30,7 @@
#include <linux/debugfs.h>
#include <linux/nvmem-provider.h>
#include <linux/root_dev.h>
#include <linux/error-injection.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
@ -1412,6 +1413,7 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
return ret;
}
EXPORT_SYMBOL_GPL(mtd_erase);
ALLOW_ERROR_INJECTION(mtd_erase, ERRNO);
/*
* This stuff for eXecute-In-Place. phys is optional and may be set to NULL.
@ -1511,6 +1513,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
return ret;
}
EXPORT_SYMBOL_GPL(mtd_read);
ALLOW_ERROR_INJECTION(mtd_read, ERRNO);
int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
const u_char *buf)
@ -1527,6 +1530,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
return ret;
}
EXPORT_SYMBOL_GPL(mtd_write);
ALLOW_ERROR_INJECTION(mtd_write, ERRNO);
/*
* In blackbox flight recorder like scenarios we want to make successful writes
@ -2347,6 +2351,7 @@ int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs)
return 0;
}
EXPORT_SYMBOL_GPL(mtd_block_markbad);
ALLOW_ERROR_INJECTION(mtd_block_markbad, ERRNO);
/*
* default_mtd_writev - the default writev method

View file

@ -104,4 +104,13 @@ config MTD_UBI_BLOCK
If in doubt, say "N".
config MTD_UBI_FAULT_INJECTION
bool "Fault injection capability of UBI device"
default n
depends on FAULT_INJECTION_DEBUG_FS
help
This option enables fault-injection support for UBI devices for
testing purposes.
If in doubt, say "N".
endif # MTD_UBI

View file

@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
list_del(&dev->list);
idr_remove(&ubiblock_minor_idr, gd->first_minor);
out_cleanup_disk:
put_disk(dev->gd);
put_disk(gd);
out_free_tags:
blk_mq_free_tag_set(&dev->tag_set);
out_free_dev:

View file

@ -10,7 +10,37 @@
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/fault-inject.h>
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
static DECLARE_FAULT_ATTR(fault_eccerr_attr);
static DECLARE_FAULT_ATTR(fault_bitflips_attr);
static DECLARE_FAULT_ATTR(fault_read_failure_attr);
static DECLARE_FAULT_ATTR(fault_write_failure_attr);
static DECLARE_FAULT_ATTR(fault_erase_failure_attr);
static DECLARE_FAULT_ATTR(fault_power_cut_attr);
static DECLARE_FAULT_ATTR(fault_io_ff_attr);
static DECLARE_FAULT_ATTR(fault_io_ff_bitflips_attr);
static DECLARE_FAULT_ATTR(fault_bad_hdr_attr);
static DECLARE_FAULT_ATTR(fault_bad_hdr_ebadmsg_attr);
#define FAIL_ACTION(name, fault_attr) \
bool should_fail_##name(void) \
{ \
return should_fail(&fault_attr, 1); \
}
FAIL_ACTION(eccerr, fault_eccerr_attr)
FAIL_ACTION(bitflips, fault_bitflips_attr)
FAIL_ACTION(read_failure, fault_read_failure_attr)
FAIL_ACTION(write_failure, fault_write_failure_attr)
FAIL_ACTION(erase_failure, fault_erase_failure_attr)
FAIL_ACTION(power_cut, fault_power_cut_attr)
FAIL_ACTION(io_ff, fault_io_ff_attr)
FAIL_ACTION(io_ff_bitflips, fault_io_ff_bitflips_attr)
FAIL_ACTION(bad_hdr, fault_bad_hdr_attr)
FAIL_ACTION(bad_hdr_ebadmsg, fault_bad_hdr_ebadmsg_attr)
#endif
/**
* ubi_dump_flash - dump a region of flash.
@ -212,6 +242,52 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req)
*/
static struct dentry *dfs_rootdir;
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
static void dfs_create_fault_entry(struct dentry *parent)
{
struct dentry *dir;
dir = debugfs_create_dir("fault_inject", parent);
if (IS_ERR_OR_NULL(dir)) {
int err = dir ? PTR_ERR(dir) : -ENODEV;
pr_warn("UBI error: cannot create \"fault_inject\" debugfs directory, error %d\n",
err);
return;
}
fault_create_debugfs_attr("emulate_eccerr", dir,
&fault_eccerr_attr);
fault_create_debugfs_attr("emulate_read_failure", dir,
&fault_read_failure_attr);
fault_create_debugfs_attr("emulate_bitflips", dir,
&fault_bitflips_attr);
fault_create_debugfs_attr("emulate_write_failure", dir,
&fault_write_failure_attr);
fault_create_debugfs_attr("emulate_erase_failure", dir,
&fault_erase_failure_attr);
fault_create_debugfs_attr("emulate_power_cut", dir,
&fault_power_cut_attr);
fault_create_debugfs_attr("emulate_io_ff", dir,
&fault_io_ff_attr);
fault_create_debugfs_attr("emulate_io_ff_bitflips", dir,
&fault_io_ff_bitflips_attr);
fault_create_debugfs_attr("emulate_bad_hdr", dir,
&fault_bad_hdr_attr);
fault_create_debugfs_attr("emulate_bad_hdr_ebadmsg", dir,
&fault_bad_hdr_ebadmsg_attr);
}
#endif
/**
* ubi_debugfs_init - create UBI debugfs directory.
*
@ -232,6 +308,10 @@ int ubi_debugfs_init(void)
return err;
}
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
dfs_create_fault_entry(dfs_rootdir);
#endif
return 0;
}
@ -252,7 +332,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
struct dentry *dent = file->f_path.dentry;
struct ubi_device *ubi;
struct ubi_debug_info *d;
char buf[8];
char buf[16];
int val;
ubi = ubi_get_device(ubi_num);
@ -272,7 +352,12 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
val = d->emulate_bitflips;
else if (dent == d->dfs_emulate_io_failures)
val = d->emulate_io_failures;
else if (dent == d->dfs_emulate_power_cut) {
else if (dent == d->dfs_emulate_failures) {
snprintf(buf, sizeof(buf), "0x%04x\n", d->emulate_failures);
count = simple_read_from_buffer(user_buf, count, ppos,
buf, strlen(buf));
goto out;
} else if (dent == d->dfs_emulate_power_cut) {
snprintf(buf, sizeof(buf), "%u\n", d->emulate_power_cut);
count = simple_read_from_buffer(user_buf, count, ppos,
buf, strlen(buf));
@ -287,8 +372,7 @@ static ssize_t dfs_file_read(struct file *file, char __user *user_buf,
count = simple_read_from_buffer(user_buf, count, ppos,
buf, strlen(buf));
goto out;
}
else {
} else {
count = -EINVAL;
goto out;
}
@ -316,7 +400,7 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
struct ubi_device *ubi;
struct ubi_debug_info *d;
size_t buf_size;
char buf[8] = {0};
char buf[16] = {0};
int val;
ubi = ubi_get_device(ubi_num);
@ -330,7 +414,11 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
goto out;
}
if (dent == d->dfs_power_cut_min) {
if (dent == d->dfs_emulate_failures) {
if (kstrtouint(buf, 0, &d->emulate_failures) != 0)
count = -EINVAL;
goto out;
} else if (dent == d->dfs_power_cut_min) {
if (kstrtouint(buf, 0, &d->power_cut_min) != 0)
count = -EINVAL;
goto out;
@ -559,6 +647,12 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir,
(void *)ubi_num, &eraseblk_count_fops);
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
d->dfs_emulate_failures = debugfs_create_file("emulate_failures",
mode, d->dfs_dir,
(void *)ubi_num,
&dfs_fops);
#endif
return 0;
}
@ -600,7 +694,5 @@ int ubi_dbg_power_cut(struct ubi_device *ubi, int caller)
if (ubi->dbg.power_cut_counter)
return 0;
ubi_msg(ubi, "XXXXXXXXXXXXXXX emulating a power cut XXXXXXXXXXXXXXXX");
ubi_ro_mode(ubi);
return 1;
}

View file

@ -52,6 +52,306 @@ void ubi_debugfs_exit(void);
int ubi_debugfs_init_dev(struct ubi_device *ubi);
void ubi_debugfs_exit_dev(struct ubi_device *ubi);
/**
* The following function is a legacy implementation of UBI fault-injection
* hook. When using more powerful fault injection capabilities, the legacy
* fault injection interface should be retained.
*/
int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
static inline int ubi_dbg_bitflip(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_bitflips)
return !get_random_u32_below(200);
return 0;
}
static inline int ubi_dbg_write_failure(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_io_failures)
return !get_random_u32_below(500);
return 0;
}
static inline int ubi_dbg_erase_failure(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_io_failures)
return !get_random_u32_below(400);
return 0;
}
/**
* MASK_XXX: Mask for emulate_failures in ubi_debug_info.The mask is used to
* precisely control the type and process of fault injection.
*/
/* Emulate a power cut when writing EC/VID header */
#define MASK_POWER_CUT_EC (1 << 0)
#define MASK_POWER_CUT_VID (1 << 1)
/* Emulate a power cut when writing data*/
#define MASK_POWER_CUT_DATA (1 << 2)
/* Emulate bit-flips */
#define MASK_BITFLIPS (1 << 3)
/* Emulate ecc error */
#define MASK_ECCERR (1 << 4)
/* Emulates -EIO during data read */
#define MASK_READ_FAILURE (1 << 5)
#define MASK_READ_FAILURE_EC (1 << 6)
#define MASK_READ_FAILURE_VID (1 << 7)
/* Emulates -EIO during data write */
#define MASK_WRITE_FAILURE (1 << 8)
/* Emulates -EIO during erase a PEB*/
#define MASK_ERASE_FAILURE (1 << 9)
/* Return UBI_IO_FF when reading EC/VID header */
#define MASK_IO_FF_EC (1 << 10)
#define MASK_IO_FF_VID (1 << 11)
/* Return UBI_IO_FF_BITFLIPS when reading EC/VID header */
#define MASK_IO_FF_BITFLIPS_EC (1 << 12)
#define MASK_IO_FF_BITFLIPS_VID (1 << 13)
/* Return UBI_IO_BAD_HDR when reading EC/VID header */
#define MASK_BAD_HDR_EC (1 << 14)
#define MASK_BAD_HDR_VID (1 << 15)
/* Return UBI_IO_BAD_HDR_EBADMSG when reading EC/VID header */
#define MASK_BAD_HDR_EBADMSG_EC (1 << 16)
#define MASK_BAD_HDR_EBADMSG_VID (1 << 17)
#ifdef CONFIG_MTD_UBI_FAULT_INJECTION
extern bool should_fail_eccerr(void);
extern bool should_fail_bitflips(void);
extern bool should_fail_read_failure(void);
extern bool should_fail_write_failure(void);
extern bool should_fail_erase_failure(void);
extern bool should_fail_power_cut(void);
extern bool should_fail_io_ff(void);
extern bool should_fail_io_ff_bitflips(void);
extern bool should_fail_bad_hdr(void);
extern bool should_fail_bad_hdr_ebadmsg(void);
static inline bool ubi_dbg_fail_bitflip(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_failures & MASK_BITFLIPS)
return should_fail_bitflips();
return false;
}
static inline bool ubi_dbg_fail_write(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_failures & MASK_WRITE_FAILURE)
return should_fail_write_failure();
return false;
}
static inline bool ubi_dbg_fail_erase(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_failures & MASK_ERASE_FAILURE)
return should_fail_erase_failure();
return false;
}
static inline bool ubi_dbg_fail_power_cut(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_power_cut();
return false;
}
static inline bool ubi_dbg_fail_read(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_read_failure();
return false;
}
static inline bool ubi_dbg_fail_eccerr(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_failures & MASK_ECCERR)
return should_fail_eccerr();
return false;
}
static inline bool ubi_dbg_fail_ff(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_io_ff();
return false;
}
static inline bool ubi_dbg_fail_ff_bitflips(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_io_ff_bitflips();
return false;
}
static inline bool ubi_dbg_fail_bad_hdr(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_bad_hdr();
return false;
}
static inline bool ubi_dbg_fail_bad_hdr_ebadmsg(const struct ubi_device *ubi,
unsigned int caller)
{
if (ubi->dbg.emulate_failures & caller)
return should_fail_bad_hdr_ebadmsg();
return false;
}
#else /* CONFIG_MTD_UBI_FAULT_INJECTION */
#define ubi_dbg_fail_bitflip(u) false
#define ubi_dbg_fail_write(u) false
#define ubi_dbg_fail_erase(u) false
#define ubi_dbg_fail_power_cut(u, c) false
#define ubi_dbg_fail_read(u, c) false
#define ubi_dbg_fail_eccerr(u) false
#define ubi_dbg_fail_ff(u, c) false
#define ubi_dbg_fail_ff_bitflips(u, v) false
#define ubi_dbg_fail_bad_hdr(u, c) false
#define ubi_dbg_fail_bad_hdr_ebadmsg(u, c) false
#endif
/**
* ubi_dbg_is_power_cut - if it is time to emulate power cut.
* @ubi: UBI device description object
*
* Returns true if power cut should be emulated, otherwise returns false.
*/
static inline bool ubi_dbg_is_power_cut(struct ubi_device *ubi,
unsigned int caller)
{
if (ubi_dbg_power_cut(ubi, caller))
return true;
return ubi_dbg_fail_power_cut(ubi, caller);
}
/**
* ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
* @ubi: UBI device description object
*
* Returns true if a bit-flip should be emulated, otherwise returns false.
*/
static inline bool ubi_dbg_is_bitflip(const struct ubi_device *ubi)
{
if (ubi_dbg_bitflip(ubi))
return true;
return ubi_dbg_fail_bitflip(ubi);
}
/**
* ubi_dbg_is_write_failure - if it is time to emulate a write failure.
* @ubi: UBI device description object
*
* Returns true if a write failure should be emulated, otherwise returns
* false.
*/
static inline bool ubi_dbg_is_write_failure(const struct ubi_device *ubi)
{
if (ubi_dbg_write_failure(ubi))
return true;
return ubi_dbg_fail_write(ubi);
}
/**
* ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
* @ubi: UBI device description object
*
* Returns true if an erase failure should be emulated, otherwise returns
* false.
*/
static inline bool ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
{
if (ubi_dbg_erase_failure(ubi))
return true;
return ubi_dbg_fail_erase(ubi);
}
/**
* ubi_dbg_is_eccerr - if it is time to emulate ECC error.
* @ubi: UBI device description object
*
* Returns true if a ECC error should be emulated, otherwise returns false.
*/
static inline bool ubi_dbg_is_eccerr(const struct ubi_device *ubi)
{
return ubi_dbg_fail_eccerr(ubi);
}
/**
* ubi_dbg_is_read_failure - if it is time to emulate a read failure.
* @ubi: UBI device description object
*
* Returns true if a read failure should be emulated, otherwise returns
* false.
*/
static inline bool ubi_dbg_is_read_failure(const struct ubi_device *ubi,
unsigned int caller)
{
return ubi_dbg_fail_read(ubi, caller);
}
/**
* ubi_dbg_is_ff - if it is time to emulate that read region is only 0xFF.
* @ubi: UBI device description object
*
* Returns true if read region should be emulated 0xFF, otherwise
* returns false.
*/
static inline bool ubi_dbg_is_ff(const struct ubi_device *ubi,
unsigned int caller)
{
return ubi_dbg_fail_ff(ubi, caller);
}
/**
* ubi_dbg_is_ff_bitflips - if it is time to emulate that read region is only 0xFF
* with error reported by the MTD driver
*
* @ubi: UBI device description object
*
* Returns true if read region should be emulated 0xFF and error
* reported by the MTD driver, otherwise returns false.
*/
static inline bool ubi_dbg_is_ff_bitflips(const struct ubi_device *ubi,
unsigned int caller)
{
return ubi_dbg_fail_ff_bitflips(ubi, caller);
}
/**
* ubi_dbg_is_bad_hdr - if it is time to emulate a bad header
* @ubi: UBI device description object
*
* Returns true if a bad header error should be emulated, otherwise
* returns false.
*/
static inline bool ubi_dbg_is_bad_hdr(const struct ubi_device *ubi,
unsigned int caller)
{
return ubi_dbg_fail_bad_hdr(ubi, caller);
}
/**
* ubi_dbg_is_bad_hdr_ebadmsg - if it is time to emulate a bad header with
* ECC error.
*
* @ubi: UBI device description object
*
* Returns true if a bad header with ECC error should be emulated, otherwise
* returns false.
*/
static inline bool ubi_dbg_is_bad_hdr_ebadmsg(const struct ubi_device *ubi,
unsigned int caller)
{
return ubi_dbg_fail_bad_hdr_ebadmsg(ubi, caller);
}
/**
* ubi_dbg_is_bgt_disabled - if the background thread is disabled.
* @ubi: UBI device description object
@ -64,47 +364,6 @@ static inline int ubi_dbg_is_bgt_disabled(const struct ubi_device *ubi)
return ubi->dbg.disable_bgt;
}
/**
* ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
* @ubi: UBI device description object
*
* Returns non-zero if a bit-flip should be emulated, otherwise returns zero.
*/
static inline int ubi_dbg_is_bitflip(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_bitflips)
return !get_random_u32_below(200);
return 0;
}
/**
* ubi_dbg_is_write_failure - if it is time to emulate a write failure.
* @ubi: UBI device description object
*
* Returns non-zero if a write failure should be emulated, otherwise returns
* zero.
*/
static inline int ubi_dbg_is_write_failure(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_io_failures)
return !get_random_u32_below(500);
return 0;
}
/**
* ubi_dbg_is_erase_failure - if its time to emulate an erase failure.
* @ubi: UBI device description object
*
* Returns non-zero if an erase failure should be emulated, otherwise returns
* zero.
*/
static inline int ubi_dbg_is_erase_failure(const struct ubi_device *ubi)
{
if (ubi->dbg.emulate_io_failures)
return !get_random_u32_below(400);
return 0;
}
static inline int ubi_dbg_chk_io(const struct ubi_device *ubi)
{
return ubi->dbg.chk_io;
@ -125,5 +384,4 @@ static inline void ubi_enable_dbg_chk_fastmap(struct ubi_device *ubi)
ubi->dbg.chk_fastmap = 1;
}
int ubi_dbg_power_cut(struct ubi_device *ubi, int caller);
#endif /* !__UBI_DEBUG_H__ */

View file

@ -195,7 +195,19 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
if (ubi_dbg_is_bitflip(ubi)) {
dbg_gen("bit-flip (emulated)");
err = UBI_IO_BITFLIPS;
return UBI_IO_BITFLIPS;
}
if (ubi_dbg_is_read_failure(ubi, MASK_READ_FAILURE)) {
ubi_warn(ubi, "cannot read %d bytes from PEB %d:%d (emulated)",
len, pnum, offset);
return -EIO;
}
if (ubi_dbg_is_eccerr(ubi)) {
ubi_warn(ubi, "ECC error (emulated) while reading %d bytes from PEB %d:%d, read %zd bytes",
len, pnum, offset, read);
return -EBADMSG;
}
}
@ -782,7 +794,36 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
* If there was %-EBADMSG, but the header CRC is still OK, report about
* a bit-flip to force scrubbing on this PEB.
*/
return read_err ? UBI_IO_BITFLIPS : 0;
if (read_err)
return UBI_IO_BITFLIPS;
if (ubi_dbg_is_read_failure(ubi, MASK_READ_FAILURE_EC)) {
ubi_warn(ubi, "cannot read EC header from PEB %d (emulated)",
pnum);
return -EIO;
}
if (ubi_dbg_is_ff(ubi, MASK_IO_FF_EC)) {
ubi_warn(ubi, "bit-all-ff (emulated)");
return UBI_IO_FF;
}
if (ubi_dbg_is_ff_bitflips(ubi, MASK_IO_FF_BITFLIPS_EC)) {
ubi_warn(ubi, "bit-all-ff with error reported by MTD driver (emulated)");
return UBI_IO_FF_BITFLIPS;
}
if (ubi_dbg_is_bad_hdr(ubi, MASK_BAD_HDR_EC)) {
ubi_warn(ubi, "bad_hdr (emulated)");
return UBI_IO_BAD_HDR;
}
if (ubi_dbg_is_bad_hdr_ebadmsg(ubi, MASK_BAD_HDR_EBADMSG_EC)) {
ubi_warn(ubi, "bad_hdr with ECC error (emulated)");
return UBI_IO_BAD_HDR_EBADMSG;
}
return 0;
}
/**
@ -821,8 +862,11 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
if (err)
return err;
if (ubi_dbg_power_cut(ubi, POWER_CUT_EC_WRITE))
if (ubi_dbg_is_power_cut(ubi, MASK_POWER_CUT_EC)) {
ubi_warn(ubi, "emulating a power cut when writing EC header");
ubi_ro_mode(ubi);
return -EROFS;
}
err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
return err;
@ -1029,7 +1073,36 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
return -EINVAL;
}
return read_err ? UBI_IO_BITFLIPS : 0;
if (read_err)
return UBI_IO_BITFLIPS;
if (ubi_dbg_is_read_failure(ubi, MASK_READ_FAILURE_VID)) {
ubi_warn(ubi, "cannot read VID header from PEB %d (emulated)",
pnum);
return -EIO;
}
if (ubi_dbg_is_ff(ubi, MASK_IO_FF_VID)) {
ubi_warn(ubi, "bit-all-ff (emulated)");
return UBI_IO_FF;
}
if (ubi_dbg_is_ff_bitflips(ubi, MASK_IO_FF_BITFLIPS_VID)) {
ubi_warn(ubi, "bit-all-ff with error reported by MTD driver (emulated)");
return UBI_IO_FF_BITFLIPS;
}
if (ubi_dbg_is_bad_hdr(ubi, MASK_BAD_HDR_VID)) {
ubi_warn(ubi, "bad_hdr (emulated)");
return UBI_IO_BAD_HDR;
}
if (ubi_dbg_is_bad_hdr_ebadmsg(ubi, MASK_BAD_HDR_EBADMSG_VID)) {
ubi_warn(ubi, "bad_hdr with ECC error (emulated)");
return UBI_IO_BAD_HDR_EBADMSG;
}
return 0;
}
/**
@ -1071,8 +1144,11 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
if (err)
return err;
if (ubi_dbg_power_cut(ubi, POWER_CUT_VID_WRITE))
if (ubi_dbg_is_power_cut(ubi, MASK_POWER_CUT_VID)) {
ubi_warn(ubi, "emulating a power cut when writing VID header");
ubi_ro_mode(ubi);
return -EROFS;
}
err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
ubi->vid_hdr_alsize);

View file

@ -145,17 +145,6 @@ enum {
UBI_BAD_FASTMAP,
};
/*
* Flags for emulate_power_cut in ubi_debug_info
*
* POWER_CUT_EC_WRITE: Emulate a power cut when writing an EC header
* POWER_CUT_VID_WRITE: Emulate a power cut when writing a VID header
*/
enum {
POWER_CUT_EC_WRITE = 0x01,
POWER_CUT_VID_WRITE = 0x02,
};
/**
* struct ubi_vid_io_buf - VID buffer used to read/write VID info to/from the
* flash.
@ -404,6 +393,7 @@ struct ubi_volume_desc {
* @power_cut_counter: count down for writes left until emulated power cut
* @power_cut_min: minimum number of writes before emulating a power cut
* @power_cut_max: maximum number of writes until emulating a power cut
* @emulate_failures: emulate failures for testing purposes
* @dfs_dir_name: name of debugfs directory containing files of this UBI device
* @dfs_dir: direntry object of the UBI device debugfs directory
* @dfs_chk_gen: debugfs knob to enable UBI general extra checks
@ -415,6 +405,7 @@ struct ubi_volume_desc {
* @dfs_emulate_power_cut: debugfs knob to emulate power cuts
* @dfs_power_cut_min: debugfs knob for minimum writes before power cut
* @dfs_power_cut_max: debugfs knob for maximum writes until power cut
* @dfs_emulate_failures: debugfs entry to control the fault injection type
*/
struct ubi_debug_info {
unsigned int chk_gen:1;
@ -427,6 +418,7 @@ struct ubi_debug_info {
unsigned int power_cut_counter;
unsigned int power_cut_min;
unsigned int power_cut_max;
unsigned int emulate_failures;
char dfs_dir_name[UBI_DFS_DIR_LEN + 1];
struct dentry *dfs_dir;
struct dentry *dfs_chk_gen;
@ -438,6 +430,7 @@ struct ubi_debug_info {
struct dentry *dfs_emulate_power_cut;
struct dentry *dfs_power_cut_min;
struct dentry *dfs_power_cut_max;
struct dentry *dfs_emulate_failures;
};
/**
@ -1130,6 +1123,19 @@ static inline struct ubi_vid_hdr *ubi_get_vid_hdr(struct ubi_vid_io_buf *vidb)
return vidb->hdr;
}
/**
* ubi_ro_mode - switch to read-only mode.
* @ubi: UBI device description object
*/
static inline void ubi_ro_mode(struct ubi_device *ubi)
{
if (!ubi->ro_mode) {
ubi->ro_mode = 1;
ubi_warn(ubi, "switch to read-only mode");
dump_stack();
}
}
/*
* This function is equivalent to 'ubi_io_read()', but @offset is relative to
* the beginning of the logical eraseblock, not to the beginning of the
@ -1151,20 +1157,13 @@ static inline int ubi_io_write_data(struct ubi_device *ubi, const void *buf,
int pnum, int offset, int len)
{
ubi_assert(offset >= 0);
return ubi_io_write(ubi, buf, pnum, offset + ubi->leb_start, len);
}
/**
* ubi_ro_mode - switch to read-only mode.
* @ubi: UBI device description object
*/
static inline void ubi_ro_mode(struct ubi_device *ubi)
{
if (!ubi->ro_mode) {
ubi->ro_mode = 1;
ubi_warn(ubi, "switch to read-only mode");
dump_stack();
if (ubi_dbg_power_cut(ubi, MASK_POWER_CUT_DATA)) {
ubi_warn(ubi, "XXXXX emulating a power cut when writing data XXXXX");
ubi_ro_mode(ubi);
return -EROFS;
}
return ubi_io_write(ubi, buf, pnum, offset + ubi->leb_start, len);
}
/**

View file

@ -18,7 +18,7 @@
#include "ubifs.h"
/**
* ubifs_node_calc_hash - calculate the hash of a UBIFS node
* __ubifs_node_calc_hash - calculate the hash of a UBIFS node
* @c: UBIFS file-system description object
* @node: the node to calculate a hash for
* @hash: the returned hash
@ -507,28 +507,13 @@ int __ubifs_shash_copy_state(const struct ubifs_info *c, struct shash_desc *src,
*/
int ubifs_hmac_wkm(struct ubifs_info *c, u8 *hmac)
{
SHASH_DESC_ON_STACK(shash, c->hmac_tfm);
int err;
const char well_known_message[] = "UBIFS";
if (!ubifs_authenticated(c))
return 0;
shash->tfm = c->hmac_tfm;
err = crypto_shash_init(shash);
if (err)
return err;
err = crypto_shash_update(shash, well_known_message,
sizeof(well_known_message) - 1);
if (err < 0)
return err;
err = crypto_shash_final(shash, hmac);
if (err)
return err;
return 0;
return crypto_shash_tfm_digest(c->hmac_tfm, well_known_message,
sizeof(well_known_message) - 1, hmac);
}
/*

View file

@ -69,6 +69,14 @@ static int nothing_to_commit(struct ubifs_info *c)
if (c->zroot.znode && ubifs_zn_dirty(c->zroot.znode))
return 0;
/*
* Increasing @c->dirty_pn_cnt/@c->dirty_nn_cnt and marking
* nnodes/pnodes as dirty in run_gc() could race with following
* checking, which leads inconsistent states between @c->nroot
* and @c->dirty_pn_cnt/@c->dirty_nn_cnt, holding @c->lp_mutex
* to avoid that.
*/
mutex_lock(&c->lp_mutex);
/*
* Even though the TNC is clean, the LPT tree may have dirty nodes. For
* example, this may happen if the budgeting subsystem invoked GC to
@ -76,12 +84,15 @@ static int nothing_to_commit(struct ubifs_info *c)
* free space. In this case GC would just change the lprops of this
* LEB (by turning all space into free space) and unmap it.
*/
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags)) {
mutex_unlock(&c->lp_mutex);
return 0;
}
ubifs_assert(c, atomic_long_read(&c->dirty_zn_cnt) == 0);
ubifs_assert(c, c->dirty_pn_cnt == 0);
ubifs_assert(c, c->dirty_nn_cnt == 0);
mutex_unlock(&c->lp_mutex);
return 1;
}

View file

@ -1234,6 +1234,8 @@ static int ubifs_symlink(struct mnt_idmap *idmap, struct inode *dir,
dir_ui->ui_size = dir->i_size;
mutex_unlock(&dir_ui->ui_mutex);
out_inode:
/* Free inode->i_link before inode is marked as bad. */
fscrypt_free_inode(inode);
make_bad_inode(inode);
iput(inode);
out_fname:

View file

@ -318,8 +318,9 @@ static int write_begin_slow(struct address_space *mapping,
* This is a helper function for 'ubifs_write_begin()' which allocates budget
* for the operation. The budget is allocated differently depending on whether
* this is appending, whether the page is dirty or not, and so on. This
* function leaves the @ui->ui_mutex locked in case of appending. Returns zero
* in case of success and %-ENOSPC in case of failure.
* function leaves the @ui->ui_mutex locked in case of appending.
*
* Returns: %0 in case of success and %-ENOSPC in case of failure.
*/
static int allocate_budget(struct ubifs_info *c, struct page *page,
struct ubifs_inode *ui, int appending)
@ -600,7 +601,7 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping,
* @bu: bulk-read information
* @n: next zbranch slot
*
* This function returns %0 on success and a negative error code on failure.
* Returns: %0 on success and a negative error code on failure.
*/
static int populate_page(struct ubifs_info *c, struct page *page,
struct bu_info *bu, int *n)
@ -711,7 +712,7 @@ static int populate_page(struct ubifs_info *c, struct page *page,
* @bu: bulk-read information
* @page1: first page to read
*
* This function returns %1 if the bulk-read is done, otherwise %0 is returned.
* Returns: %1 if the bulk-read is done, otherwise %0 is returned.
*/
static int ubifs_do_bulk_read(struct ubifs_info *c, struct bu_info *bu,
struct page *page1)
@ -821,7 +822,9 @@ static int ubifs_do_bulk_read(struct ubifs_info *c, struct bu_info *bu,
* Some flash media are capable of reading sequentially at faster rates. UBIFS
* bulk-read facility is designed to take advantage of that, by reading in one
* go consecutive data nodes that are also located consecutively in the same
* LEB. This function returns %1 if a bulk-read is done and %0 otherwise.
* LEB.
*
* Returns: %1 if a bulk-read is done and %0 otherwise.
*/
static int ubifs_bulk_read(struct page *page)
{
@ -1109,7 +1112,9 @@ static void do_attr_changes(struct inode *inode, const struct iattr *attr)
* @attr: inode attribute changes description
*
* This function implements VFS '->setattr()' call when the inode is truncated
* to a smaller size. Returns zero in case of success and a negative error code
* to a smaller size.
*
* Returns: %0 in case of success and a negative error code
* in case of failure.
*/
static int do_truncation(struct ubifs_info *c, struct inode *inode,
@ -1215,7 +1220,9 @@ static int do_truncation(struct ubifs_info *c, struct inode *inode,
* @attr: inode attribute changes description
*
* This function implements VFS '->setattr()' call for all cases except
* truncations to smaller size. Returns zero in case of success and a negative
* truncations to smaller size.
*
* Returns: %0 in case of success and a negative
* error code in case of failure.
*/
static int do_setattr(struct ubifs_info *c, struct inode *inode,
@ -1360,6 +1367,8 @@ int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
* This helper function checks if the inode mtime/ctime should be updated or
* not. If current values of the time-stamps are within the UBIFS inode time
* granularity, they are not updated. This is an optimization.
*
* Returns: %1 if time update is needed, %0 if not
*/
static inline int mctime_update_needed(const struct inode *inode,
const struct timespec64 *now)
@ -1375,11 +1384,12 @@ static inline int mctime_update_needed(const struct inode *inode,
/**
* ubifs_update_time - update time of inode.
* @inode: inode to update
* @time: timespec structure to hold the current time value
* @flags: time updating control flag determines updating
* which time fields of @inode
*
* This function updates time of the inode.
*
* Returns: %0 for success or a negative error code otherwise.
*/
int ubifs_update_time(struct inode *inode, int flags)
{
@ -1413,7 +1423,9 @@ int ubifs_update_time(struct inode *inode, int flags)
* @inode: inode to update
*
* This function updates mtime and ctime of the inode if it is not equivalent to
* current time. Returns zero in case of success and a negative error code in
* current time.
*
* Returns: %0 in case of success and a negative error code in
* case of failure.
*/
static int update_mctime(struct inode *inode)

View file

@ -365,6 +365,7 @@ static void destroy_replay_list(struct ubifs_info *c)
* @lnum: node logical eraseblock number
* @offs: node offset
* @len: node length
* @hash: node hash
* @key: node key
* @sqnum: sequence number
* @deletion: non-zero if this is a deletion
@ -417,6 +418,7 @@ static int insert_node(struct ubifs_info *c, int lnum, int offs, int len,
* @lnum: node logical eraseblock number
* @offs: node offset
* @len: node length
* @hash: node hash
* @key: node key
* @name: directory entry name
* @nlen: directory entry name length