Skip to content

Commit f57b620

Browse files
committed
Merge tag 'upstream-4.20-rc7' of git://git.infradead.org/linux-ubifs
Pull UBI/UBIFS fixes from Richard Weinberger: - Kconfig dependency fixes for our new auth feature - Fix for selecting the right compressor when creating a fs - Bugfix for a bug in UBIFS's O_TMPFILE implementation - Refcounting fixes for UBI * tag 'upstream-4.20-rc7' of git://git.infradead.org/linux-ubifs: ubifs: Handle re-linking of inodes correctly while recovery ubi: Do not drop UBI device reference before using ubi: Put MTD device after it is not used ubifs: Fix default compression selection in ubifs ubifs: Fix memory leak on error condition ubifs: auth: Add CONFIG_KEYS dependency ubifs: CONFIG_UBIFS_FS_AUTHENTICATION should depend on UBIFS_FS ubifs: replay: Fix high stack usage
2 parents 1d51b4b + e58725d commit f57b620

File tree

6 files changed

+89
-28
lines changed

6 files changed

+89
-28
lines changed

drivers/mtd/ubi/build.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,10 +1101,10 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
11011101
ubi_wl_close(ubi);
11021102
ubi_free_internal_volumes(ubi);
11031103
vfree(ubi->vtbl);
1104-
put_mtd_device(ubi->mtd);
11051104
vfree(ubi->peb_buf);
11061105
vfree(ubi->fm_buf);
11071106
ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index);
1107+
put_mtd_device(ubi->mtd);
11081108
put_device(&ubi->dev);
11091109
return 0;
11101110
}

drivers/mtd/ubi/kapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
227227
out_free:
228228
kfree(desc);
229229
out_put_ubi:
230-
ubi_put_device(ubi);
231230
ubi_err(ubi, "cannot open device %d, volume %d, error %d",
232231
ubi_num, vol_id, err);
232+
ubi_put_device(ubi);
233233
return ERR_PTR(err);
234234
}
235235
EXPORT_SYMBOL_GPL(ubi_open_volume);

fs/ubifs/Kconfig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ config UBIFS_FS
1212
help
1313
UBIFS is a file system for flash devices which works on top of UBI.
1414

15+
if UBIFS_FS
16+
1517
config UBIFS_FS_ADVANCED_COMPR
1618
bool "Advanced compression options"
17-
depends on UBIFS_FS
1819
help
1920
This option allows to explicitly choose which compressions, if any,
2021
are enabled in UBIFS. Removing compressors means inability to read
@@ -24,22 +25,19 @@ config UBIFS_FS_ADVANCED_COMPR
2425

2526
config UBIFS_FS_LZO
2627
bool "LZO compression support" if UBIFS_FS_ADVANCED_COMPR
27-
depends on UBIFS_FS
2828
default y
2929
help
3030
LZO compressor is generally faster than zlib but compresses worse.
3131
Say 'Y' if unsure.
3232

3333
config UBIFS_FS_ZLIB
3434
bool "ZLIB compression support" if UBIFS_FS_ADVANCED_COMPR
35-
depends on UBIFS_FS
3635
default y
3736
help
3837
Zlib compresses better than LZO but it is slower. Say 'Y' if unsure.
3938

4039
config UBIFS_ATIME_SUPPORT
41-
bool "Access time support" if UBIFS_FS
42-
depends on UBIFS_FS
40+
bool "Access time support"
4341
default n
4442
help
4543
Originally UBIFS did not support atime, because it looked like a bad idea due
@@ -54,7 +52,6 @@ config UBIFS_ATIME_SUPPORT
5452

5553
config UBIFS_FS_XATTR
5654
bool "UBIFS XATTR support"
57-
depends on UBIFS_FS
5855
default y
5956
help
6057
Saying Y here includes support for extended attributes (xattrs).
@@ -65,7 +62,7 @@ config UBIFS_FS_XATTR
6562

6663
config UBIFS_FS_ENCRYPTION
6764
bool "UBIFS Encryption"
68-
depends on UBIFS_FS && UBIFS_FS_XATTR && BLOCK
65+
depends on UBIFS_FS_XATTR && BLOCK
6966
select FS_ENCRYPTION
7067
default n
7168
help
@@ -76,7 +73,7 @@ config UBIFS_FS_ENCRYPTION
7673

7774
config UBIFS_FS_SECURITY
7875
bool "UBIFS Security Labels"
79-
depends on UBIFS_FS && UBIFS_FS_XATTR
76+
depends on UBIFS_FS_XATTR
8077
default y
8178
help
8279
Security labels provide an access control facility to support Linux
@@ -89,10 +86,13 @@ config UBIFS_FS_SECURITY
8986

9087
config UBIFS_FS_AUTHENTICATION
9188
bool "UBIFS authentication support"
89+
depends on KEYS
9290
select CRYPTO_HMAC
9391
help
9492
Enable authentication support for UBIFS. This feature offers protection
9593
against offline changes for both data and metadata of the filesystem.
9694
If you say yes here you should also select a hashing algorithm such as
9795
sha256, these are not selected automatically since there are many
9896
different options.
97+
98+
endif # UBIFS_FS

fs/ubifs/lpt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,12 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash)
16751675
if (!ubifs_authenticated(c))
16761676
return 0;
16771677

1678+
if (!c->nroot) {
1679+
err = ubifs_read_nnode(c, NULL, 0);
1680+
if (err)
1681+
return err;
1682+
}
1683+
16781684
desc = ubifs_hash_get_desc(c);
16791685
if (IS_ERR(desc))
16801686
return PTR_ERR(desc);
@@ -1685,12 +1691,6 @@ int ubifs_lpt_calc_hash(struct ubifs_info *c, u8 *hash)
16851691
goto out;
16861692
}
16871693

1688-
if (!c->nroot) {
1689-
err = ubifs_read_nnode(c, NULL, 0);
1690-
if (err)
1691-
return err;
1692-
}
1693-
16941694
cnode = (struct ubifs_cnode *)c->nroot;
16951695

16961696
while (cnode) {

fs/ubifs/replay.c

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,38 @@ static int trun_remove_range(struct ubifs_info *c, struct replay_entry *r)
212212
return ubifs_tnc_remove_range(c, &min_key, &max_key);
213213
}
214214

215+
/**
216+
* inode_still_linked - check whether inode in question will be re-linked.
217+
* @c: UBIFS file-system description object
218+
* @rino: replay entry to test
219+
*
220+
* O_TMPFILE files can be re-linked, this means link count goes from 0 to 1.
221+
* This case needs special care, otherwise all references to the inode will
222+
* be removed upon the first replay entry of an inode with link count 0
223+
* is found.
224+
*/
225+
static bool inode_still_linked(struct ubifs_info *c, struct replay_entry *rino)
226+
{
227+
struct replay_entry *r;
228+
229+
ubifs_assert(c, rino->deletion);
230+
ubifs_assert(c, key_type(c, &rino->key) == UBIFS_INO_KEY);
231+
232+
/*
233+
* Find the most recent entry for the inode behind @rino and check
234+
* whether it is a deletion.
235+
*/
236+
list_for_each_entry_reverse(r, &c->replay_list, list) {
237+
ubifs_assert(c, r->sqnum >= rino->sqnum);
238+
if (key_inum(c, &r->key) == key_inum(c, &rino->key))
239+
return r->deletion == 0;
240+
241+
}
242+
243+
ubifs_assert(c, 0);
244+
return false;
245+
}
246+
215247
/**
216248
* apply_replay_entry - apply a replay entry to the TNC.
217249
* @c: UBIFS file-system description object
@@ -239,6 +271,11 @@ static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r)
239271
{
240272
ino_t inum = key_inum(c, &r->key);
241273

274+
if (inode_still_linked(c, r)) {
275+
err = 0;
276+
break;
277+
}
278+
242279
err = ubifs_tnc_remove_ino(c, inum);
243280
break;
244281
}
@@ -533,6 +570,28 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud)
533570
return data == 0xFFFFFFFF;
534571
}
535572

573+
/* authenticate_sleb_hash and authenticate_sleb_hmac are split out for stack usage */
574+
static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_hash, u8 *hash)
575+
{
576+
SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
577+
578+
hash_desc->tfm = c->hash_tfm;
579+
hash_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
580+
581+
ubifs_shash_copy_state(c, log_hash, hash_desc);
582+
return crypto_shash_final(hash_desc, hash);
583+
}
584+
585+
static int authenticate_sleb_hmac(struct ubifs_info *c, u8 *hash, u8 *hmac)
586+
{
587+
SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm);
588+
589+
hmac_desc->tfm = c->hmac_tfm;
590+
hmac_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
591+
592+
return crypto_shash_digest(hmac_desc, hash, c->hash_len, hmac);
593+
}
594+
536595
/**
537596
* authenticate_sleb - authenticate one scan LEB
538597
* @c: UBIFS file-system description object
@@ -574,21 +633,12 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
574633

575634
if (snod->type == UBIFS_AUTH_NODE) {
576635
struct ubifs_auth_node *auth = snod->node;
577-
SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
578-
SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm);
579-
580-
hash_desc->tfm = c->hash_tfm;
581-
hash_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
582636

583-
ubifs_shash_copy_state(c, log_hash, hash_desc);
584-
err = crypto_shash_final(hash_desc, hash);
637+
err = authenticate_sleb_hash(c, log_hash, hash);
585638
if (err)
586639
goto out;
587640

588-
hmac_desc->tfm = c->hmac_tfm;
589-
hmac_desc->flags = CRYPTO_TFM_REQ_MAY_SLEEP;
590-
err = crypto_shash_digest(hmac_desc, hash, c->hash_len,
591-
hmac);
641+
err = authenticate_sleb_hmac(c, hash, hmac);
592642
if (err)
593643
goto out;
594644

fs/ubifs/sb.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
/* Default time granularity in nanoseconds */
6464
#define DEFAULT_TIME_GRAN 1000000000
6565

66+
static int get_default_compressor(struct ubifs_info *c)
67+
{
68+
if (ubifs_compr_present(c, UBIFS_COMPR_LZO))
69+
return UBIFS_COMPR_LZO;
70+
71+
if (ubifs_compr_present(c, UBIFS_COMPR_ZLIB))
72+
return UBIFS_COMPR_ZLIB;
73+
74+
return UBIFS_COMPR_NONE;
75+
}
76+
6677
/**
6778
* create_default_filesystem - format empty UBI volume.
6879
* @c: UBIFS file-system description object
@@ -207,7 +218,7 @@ static int create_default_filesystem(struct ubifs_info *c)
207218
if (c->mount_opts.override_compr)
208219
sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);
209220
else
210-
sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO);
221+
sup->default_compr = cpu_to_le16(get_default_compressor(c));
211222

212223
generate_random_uuid(sup->uuid);
213224

0 commit comments

Comments
 (0)