Skip to content

Commit b53c4d5

Browse files
committed
Merge tag 'upstream-4.12-rc1' of git://git.infradead.org/linux-ubifs
Pull UBI/UBIFS updates from Richard Weinberger: - new config option CONFIG_UBIFS_FS_SECURITY - minor improvements - random fixes * tag 'upstream-4.12-rc1' of git://git.infradead.org/linux-ubifs: ubi: Add debugfs file for tracking PEB state ubifs: Fix a typo in comment of ioctl2ubifs & ubifs2ioctl ubifs: Remove unnecessary assignment ubifs: Fix cut and paste error on sb type comparisons ubi: fastmap: Fix slab corruption ubifs: Add CONFIG_UBIFS_FS_SECURITY to disable/enable security labels ubi: Make mtd parameter readable ubi: Fix section mismatch
2 parents ec05901 + 7bccd12 commit b53c4d5

File tree

9 files changed

+195
-18
lines changed

9 files changed

+195
-18
lines changed

drivers/mtd/ubi/build.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ struct mtd_dev_param {
7474
};
7575

7676
/* Numbers of elements set in the @mtd_dev_param array */
77-
static int __initdata mtd_devs;
77+
static int mtd_devs;
7878

7979
/* MTD devices specification parameters */
80-
static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
80+
static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];
8181
#ifdef CONFIG_MTD_UBI_FASTMAP
8282
/* UBI module parameter to enable fastmap automatically on non-fastmap images */
8383
static bool fm_autoconvert;
@@ -1294,7 +1294,7 @@ module_exit(ubi_exit);
12941294
* This function returns positive resulting integer in case of success and a
12951295
* negative error code in case of failure.
12961296
*/
1297-
static int __init bytes_str_to_int(const char *str)
1297+
static int bytes_str_to_int(const char *str)
12981298
{
12991299
char *endp;
13001300
unsigned long result;
@@ -1332,7 +1332,7 @@ static int __init bytes_str_to_int(const char *str)
13321332
* This function returns zero in case of success and a negative error code in
13331333
* case of error.
13341334
*/
1335-
static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1335+
static int ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
13361336
{
13371337
int i, len;
13381338
struct mtd_dev_param *p;
@@ -1413,7 +1413,7 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
14131413
return 0;
14141414
}
14151415

1416-
module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1416+
module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 0400);
14171417
MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024[,ubi_num]]].\n"
14181418
"Multiple \"mtd\" parameters may be specified.\n"
14191419
"MTD devices may be specified by their number, name, or path to the MTD character device node.\n"

drivers/mtd/ubi/debug.c

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/debugfs.h>
2323
#include <linux/uaccess.h>
2424
#include <linux/module.h>
25+
#include <linux/seq_file.h>
2526

2627

2728
/**
@@ -386,7 +387,9 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
386387
return count;
387388
}
388389

389-
/* File operations for all UBI debugfs files */
390+
/* File operations for all UBI debugfs files except
391+
* detailed_erase_block_info
392+
*/
390393
static const struct file_operations dfs_fops = {
391394
.read = dfs_file_read,
392395
.write = dfs_file_write,
@@ -395,6 +398,121 @@ static const struct file_operations dfs_fops = {
395398
.owner = THIS_MODULE,
396399
};
397400

401+
/* As long as the position is less then that total number of erase blocks,
402+
* we still have more to print.
403+
*/
404+
static void *eraseblk_count_seq_start(struct seq_file *s, loff_t *pos)
405+
{
406+
struct ubi_device *ubi = s->private;
407+
408+
if (*pos == 0)
409+
return SEQ_START_TOKEN;
410+
411+
if (*pos < ubi->peb_count)
412+
return pos;
413+
414+
return NULL;
415+
}
416+
417+
/* Since we are using the position as the iterator, we just need to check if we
418+
* are done and increment the position.
419+
*/
420+
static void *eraseblk_count_seq_next(struct seq_file *s, void *v, loff_t *pos)
421+
{
422+
struct ubi_device *ubi = s->private;
423+
424+
if (v == SEQ_START_TOKEN)
425+
return pos;
426+
(*pos)++;
427+
428+
if (*pos < ubi->peb_count)
429+
return pos;
430+
431+
return NULL;
432+
}
433+
434+
static void eraseblk_count_seq_stop(struct seq_file *s, void *v)
435+
{
436+
}
437+
438+
static int eraseblk_count_seq_show(struct seq_file *s, void *iter)
439+
{
440+
struct ubi_device *ubi = s->private;
441+
struct ubi_wl_entry *wl;
442+
int *block_number = iter;
443+
int erase_count = -1;
444+
int err;
445+
446+
/* If this is the start, print a header */
447+
if (iter == SEQ_START_TOKEN) {
448+
seq_puts(s,
449+
"physical_block_number\terase_count\tblock_status\tread_status\n");
450+
return 0;
451+
}
452+
453+
err = ubi_io_is_bad(ubi, *block_number);
454+
if (err)
455+
return err;
456+
457+
spin_lock(&ubi->wl_lock);
458+
459+
wl = ubi->lookuptbl[*block_number];
460+
if (wl)
461+
erase_count = wl->ec;
462+
463+
spin_unlock(&ubi->wl_lock);
464+
465+
if (erase_count < 0)
466+
return 0;
467+
468+
seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count);
469+
470+
return 0;
471+
}
472+
473+
static const struct seq_operations eraseblk_count_seq_ops = {
474+
.start = eraseblk_count_seq_start,
475+
.next = eraseblk_count_seq_next,
476+
.stop = eraseblk_count_seq_stop,
477+
.show = eraseblk_count_seq_show
478+
};
479+
480+
static int eraseblk_count_open(struct inode *inode, struct file *f)
481+
{
482+
struct seq_file *s;
483+
int err;
484+
485+
err = seq_open(f, &eraseblk_count_seq_ops);
486+
if (err)
487+
return err;
488+
489+
s = f->private_data;
490+
s->private = ubi_get_device((unsigned long)inode->i_private);
491+
492+
if (!s->private)
493+
return -ENODEV;
494+
else
495+
return 0;
496+
}
497+
498+
static int eraseblk_count_release(struct inode *inode, struct file *f)
499+
{
500+
struct seq_file *s = f->private_data;
501+
struct ubi_device *ubi = s->private;
502+
503+
ubi_put_device(ubi);
504+
505+
return seq_release(inode, f);
506+
}
507+
508+
static const struct file_operations eraseblk_count_fops = {
509+
.owner = THIS_MODULE,
510+
.open = eraseblk_count_open,
511+
.read = seq_read,
512+
.llseek = seq_lseek,
513+
.release = eraseblk_count_release,
514+
};
515+
398516
/**
399517
* ubi_debugfs_init_dev - initialize debugfs for an UBI device.
400518
* @ubi: UBI device description object
@@ -491,6 +609,12 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
491609
goto out_remove;
492610
d->dfs_power_cut_max = dent;
493611

612+
fname = "detailed_erase_block_info";
613+
dent = debugfs_create_file(fname, S_IRUSR, d->dfs_dir, (void *)ubi_num,
614+
&eraseblk_count_fops);
615+
if (IS_ERR_OR_NULL(dent))
616+
goto out_remove;
617+
494618
return 0;
495619

496620
out_remove:

drivers/mtd/ubi/fastmap.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,24 @@ static int find_fm_anchor(struct ubi_attach_info *ai)
828828
return ret;
829829
}
830830

831+
static struct ubi_ainf_peb *clone_aeb(struct ubi_attach_info *ai,
832+
struct ubi_ainf_peb *old)
833+
{
834+
struct ubi_ainf_peb *new;
835+
836+
new = ubi_alloc_aeb(ai, old->pnum, old->ec);
837+
if (!new)
838+
return NULL;
839+
840+
new->vol_id = old->vol_id;
841+
new->sqnum = old->sqnum;
842+
new->lnum = old->lnum;
843+
new->scrub = old->scrub;
844+
new->copy_flag = old->copy_flag;
845+
846+
return new;
847+
}
848+
831849
/**
832850
* ubi_scan_fastmap - scan the fastmap.
833851
* @ubi: UBI device object
@@ -847,7 +865,7 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
847865
struct ubi_vid_hdr *vh;
848866
struct ubi_ec_hdr *ech;
849867
struct ubi_fastmap_layout *fm;
850-
struct ubi_ainf_peb *tmp_aeb, *aeb;
868+
struct ubi_ainf_peb *aeb;
851869
int i, used_blocks, pnum, fm_anchor, ret = 0;
852870
size_t fm_size;
853871
__be32 crc, tmp_crc;
@@ -857,9 +875,16 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info *ai,
857875
if (fm_anchor < 0)
858876
return UBI_NO_FASTMAP;
859877

860-
/* Move all (possible) fastmap blocks into our new attach structure. */
861-
list_for_each_entry_safe(aeb, tmp_aeb, &scan_ai->fastmap, u.list)
862-
list_move_tail(&aeb->u.list, &ai->fastmap);
878+
/* Copy all (possible) fastmap blocks into our new attach structure. */
879+
list_for_each_entry(aeb, &scan_ai->fastmap, u.list) {
880+
struct ubi_ainf_peb *new;
881+
882+
new = clone_aeb(ai, aeb);
883+
if (!new)
884+
return -ENOMEM;
885+
886+
list_add(&new->u.list, &ai->fastmap);
887+
}
863888

864889
down_write(&ubi->fm_protect);
865890
memset(ubi->fm_buf, 0, ubi->fm_size);

fs/ubifs/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,16 @@ config UBIFS_FS_ENCRYPTION
6161
feature is similar to ecryptfs, but it is more memory
6262
efficient since it avoids caching the encrypted and
6363
decrypted pages in the page cache.
64+
65+
config UBIFS_FS_SECURITY
66+
bool "UBIFS Security Labels"
67+
depends on UBIFS_FS
68+
default y
69+
help
70+
Security labels provide an access control facility to support Linux
71+
Security Models (LSMs) accepted by AppArmor, SELinux, Smack and TOMOYO
72+
Linux. This option enables an extended attribute handler for file
73+
security labels in the ubifs filesystem, so that it requires enabling
74+
the extended attribute support in advance.
75+
76+
If you are not using a security module, say N.

fs/ubifs/debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,8 +2391,8 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
23912391
ubifs_dump_node(c, sa->node);
23922392
return -EINVAL;
23932393
}
2394-
if (sa->type != UBIFS_INO_NODE && sa->type != UBIFS_DENT_NODE &&
2395-
sa->type != UBIFS_XENT_NODE) {
2394+
if (sb->type != UBIFS_INO_NODE && sb->type != UBIFS_DENT_NODE &&
2395+
sb->type != UBIFS_XENT_NODE) {
23962396
ubifs_err(c, "bad node type %d", sb->type);
23972397
ubifs_dump_node(c, sb->node);
23982398
return -EINVAL;

fs/ubifs/ioctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void ubifs_set_inode_flags(struct inode *inode)
5353
* ioctl2ubifs - convert ioctl inode flags to UBIFS inode flags.
5454
* @ioctl_flags: flags to convert
5555
*
56-
* This function convert ioctl flags (@FS_COMPR_FL, etc) to UBIFS inode flags
56+
* This function converts ioctl flags (@FS_COMPR_FL, etc) to UBIFS inode flags
5757
* (@UBIFS_COMPR_FL, etc).
5858
*/
5959
static int ioctl2ubifs(int ioctl_flags)
@@ -78,8 +78,8 @@ static int ioctl2ubifs(int ioctl_flags)
7878
* ubifs2ioctl - convert UBIFS inode flags to ioctl inode flags.
7979
* @ubifs_flags: flags to convert
8080
*
81-
* This function convert UBIFS (@UBIFS_COMPR_FL, etc) to ioctl flags
82-
* (@FS_COMPR_FL, etc).
81+
* This function converts UBIFS inode flags (@UBIFS_COMPR_FL, etc) to ioctl
82+
* flags (@FS_COMPR_FL, etc).
8383
*/
8484
static int ubifs2ioctl(int ubifs_flags)
8585
{

fs/ubifs/recovery.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ static void clean_buf(const struct ubifs_info *c, void **buf, int lnum,
442442
{
443443
int empty_offs, pad_len;
444444

445-
lnum = lnum;
446445
dbg_rcvry("cleaning corruption at %d:%d", lnum, *offs);
447446

448447
ubifs_assert(!(*offs & 7));

fs/ubifs/ubifs.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,13 +1753,23 @@ int ubifs_check_dir_empty(struct inode *dir);
17531753
/* xattr.c */
17541754
extern const struct xattr_handler *ubifs_xattr_handlers[];
17551755
ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
1756-
int ubifs_init_security(struct inode *dentry, struct inode *inode,
1757-
const struct qstr *qstr);
17581756
int ubifs_xattr_set(struct inode *host, const char *name, const void *value,
17591757
size_t size, int flags);
17601758
ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf,
17611759
size_t size);
17621760

1761+
#ifdef CONFIG_UBIFS_FS_SECURITY
1762+
extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
1763+
const struct qstr *qstr);
1764+
#else
1765+
static inline int ubifs_init_security(struct inode *dentry,
1766+
struct inode *inode, const struct qstr *qstr)
1767+
{
1768+
return 0;
1769+
}
1770+
#endif
1771+
1772+
17631773
/* super.c */
17641774
struct inode *ubifs_iget(struct super_block *sb, unsigned long inum);
17651775

fs/ubifs/xattr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ static int ubifs_xattr_remove(struct inode *host, const char *name)
559559
return err;
560560
}
561561

562+
#ifdef CONFIG_UBIFS_FS_SECURITY
562563
static int init_xattrs(struct inode *inode, const struct xattr *xattr_array,
563564
void *fs_info)
564565
{
@@ -599,6 +600,7 @@ int ubifs_init_security(struct inode *dentry, struct inode *inode,
599600
}
600601
return err;
601602
}
603+
#endif
602604

603605
static int xattr_get(const struct xattr_handler *handler,
604606
struct dentry *dentry, struct inode *inode,
@@ -639,15 +641,19 @@ static const struct xattr_handler ubifs_trusted_xattr_handler = {
639641
.set = xattr_set,
640642
};
641643

644+
#ifdef CONFIG_UBIFS_FS_SECURITY
642645
static const struct xattr_handler ubifs_security_xattr_handler = {
643646
.prefix = XATTR_SECURITY_PREFIX,
644647
.get = xattr_get,
645648
.set = xattr_set,
646649
};
650+
#endif
647651

648652
const struct xattr_handler *ubifs_xattr_handlers[] = {
649653
&ubifs_user_xattr_handler,
650654
&ubifs_trusted_xattr_handler,
655+
#ifdef CONFIG_UBIFS_FS_SECURITY
651656
&ubifs_security_xattr_handler,
657+
#endif
652658
NULL
653659
};

0 commit comments

Comments
 (0)