Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'upstream-4.13-rc1' of git://git.infradead.org/linux-ubifs

Pull UBIFS updates from Richard Weinberger:

- Updates and fixes for the file encryption mode

- Minor improvements

- Random fixes

* tag 'upstream-4.13-rc1' of git://git.infradead.org/linux-ubifs:
ubifs: Set double hash cookie also for RENAME_EXCHANGE
ubifs: Massage assert in ubifs_xattr_set() wrt. init_xattrs
ubifs: Don't leak kernel memory to the MTD
ubifs: Change gfp flags in page allocation for bulk read
ubifs: Fix oops when remounting with no_bulk_read.
ubifs: Fail commit if TNC is obviously inconsistent
ubifs: allow userspace to map mounts to volumes
ubifs: Wire-up statx() support
ubifs: Remove dead code from ubifs_get_link()
ubifs: Massage debug prints wrt. fscrypt
ubifs: Add assert to dent_key_init()
ubifs: Fix unlink code wrt. double hash lookups
ubifs: Fix data node size for truncating uncompressed nodes
ubifs: Don't encrypt special files on creation
ubifs: Fix memory leak in RENAME_WHITEOUT error path in do_rename
ubifs: Fix inode data budget in ubifs_mknod
ubifs: Correctly evict xattr inodes
ubifs: Unexport ubifs_inode_slab
ubifs: don't bother checking for encryption key in ->mmap()
ubifs: require key for truncate(2) of encrypted file

+223 -90
+6 -1
fs/ubifs/crypto.c
··· 9 9 static int ubifs_crypt_set_context(struct inode *inode, const void *ctx, 10 10 size_t len, void *fs_data) 11 11 { 12 + /* 13 + * Creating an encryption context is done unlocked since we 14 + * operate on a new inode which is not visible to other users 15 + * at this point. So, no need to check whether inode is locked. 16 + */ 12 17 return ubifs_xattr_set(inode, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT, 13 - ctx, len, 0); 18 + ctx, len, 0, false); 14 19 } 15 20 16 21 static bool ubifs_crypt_empty_dir(struct inode *inode)
+22 -10
fs/ubifs/dir.c
··· 143 143 case S_IFBLK: 144 144 case S_IFCHR: 145 145 inode->i_op = &ubifs_file_inode_operations; 146 + encrypted = false; 146 147 break; 147 148 default: 148 149 BUG(); ··· 1062 1061 int sz_change; 1063 1062 int err, devlen = 0; 1064 1063 struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1, 1065 - .new_ino_d = ALIGN(devlen, 8), 1066 1064 .dirtied_ino = 1 }; 1067 1065 struct fscrypt_name nm; 1068 1066 ··· 1079 1079 devlen = ubifs_encode_dev(dev, rdev); 1080 1080 } 1081 1081 1082 + req.new_ino_d = ALIGN(devlen, 8); 1082 1083 err = ubifs_budget_space(c, &req); 1083 1084 if (err) { 1084 1085 kfree(dev); ··· 1397 1396 1398 1397 dev = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS); 1399 1398 if (!dev) { 1400 - ubifs_release_budget(c, &req); 1401 - ubifs_release_budget(c, &ino_req); 1402 - return -ENOMEM; 1399 + err = -ENOMEM; 1400 + goto out_release; 1403 1401 } 1404 1402 1405 1403 err = do_tmpfile(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE, &whiteout); 1406 1404 if (err) { 1407 - ubifs_release_budget(c, &req); 1408 - ubifs_release_budget(c, &ino_req); 1409 1405 kfree(dev); 1410 - return err; 1406 + goto out_release; 1411 1407 } 1412 1408 1413 1409 whiteout->i_state |= I_LINKABLE; ··· 1492 1494 1493 1495 err = ubifs_budget_space(c, &wht_req); 1494 1496 if (err) { 1495 - ubifs_release_budget(c, &req); 1496 - ubifs_release_budget(c, &ino_req); 1497 1497 kfree(whiteout_ui->data); 1498 1498 whiteout_ui->data_len = 0; 1499 1499 iput(whiteout); 1500 - return err; 1500 + goto out_release; 1501 1501 } 1502 1502 1503 1503 inc_nlink(whiteout); ··· 1550 1554 iput(whiteout); 1551 1555 } 1552 1556 unlock_4_inodes(old_dir, new_dir, new_inode, whiteout); 1557 + out_release: 1553 1558 ubifs_release_budget(c, &ino_req); 1554 1559 ubifs_release_budget(c, &req); 1555 1560 fscrypt_free_filename(&old_nm); ··· 1644 1647 struct ubifs_inode *ui = ubifs_inode(inode); 1645 1648 1646 1649 mutex_lock(&ui->ui_mutex); 1650 + 1651 + if (ui->flags & UBIFS_APPEND_FL) 1652 + stat->attributes |= STATX_ATTR_APPEND; 1653 + if (ui->flags & UBIFS_COMPR_FL) 1654 + stat->attributes |= STATX_ATTR_COMPRESSED; 1655 + if (ui->flags & UBIFS_CRYPT_FL) 1656 + stat->attributes |= STATX_ATTR_ENCRYPTED; 1657 + if (ui->flags & UBIFS_IMMUTABLE_FL) 1658 + stat->attributes |= STATX_ATTR_IMMUTABLE; 1659 + 1660 + stat->attributes_mask |= (STATX_ATTR_APPEND | 1661 + STATX_ATTR_COMPRESSED | 1662 + STATX_ATTR_ENCRYPTED | 1663 + STATX_ATTR_IMMUTABLE); 1664 + 1647 1665 generic_fillattr(inode, stat); 1648 1666 stat->blksize = UBIFS_BLOCK_SIZE; 1649 1667 stat->size = ui->ui_size;
+10 -17
fs/ubifs/file.c
··· 735 735 int err, page_idx, page_cnt, ret = 0, n = 0; 736 736 int allocate = bu->buf ? 0 : 1; 737 737 loff_t isize; 738 + gfp_t ra_gfp_mask = readahead_gfp_mask(mapping) & ~__GFP_FS; 738 739 739 740 err = ubifs_tnc_get_bu_keys(c, bu); 740 741 if (err) ··· 797 796 798 797 if (page_offset > end_index) 799 798 break; 800 - page = find_or_create_page(mapping, page_offset, 801 - GFP_NOFS | __GFP_COLD); 799 + page = find_or_create_page(mapping, page_offset, ra_gfp_mask); 802 800 if (!page) 803 801 break; 804 802 if (!PageUptodate(page)) ··· 1284 1284 if (err) 1285 1285 return err; 1286 1286 1287 + if (ubifs_crypt_is_encrypted(inode) && (attr->ia_valid & ATTR_SIZE)) { 1288 + err = fscrypt_get_encryption_info(inode); 1289 + if (err) 1290 + return err; 1291 + if (!fscrypt_has_encryption_key(inode)) 1292 + return -ENOKEY; 1293 + } 1294 + 1287 1295 if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size < inode->i_size) 1288 1296 /* Truncation to a smaller size */ 1289 1297 err = do_truncation(c, inode, attr); ··· 1615 1607 static int ubifs_file_mmap(struct file *file, struct vm_area_struct *vma) 1616 1608 { 1617 1609 int err; 1618 - struct inode *inode = file->f_mapping->host; 1619 - 1620 - if (ubifs_crypt_is_encrypted(inode)) { 1621 - err = fscrypt_get_encryption_info(inode); 1622 - if (err) 1623 - return -EACCES; 1624 - if (!fscrypt_has_encryption_key(inode)) 1625 - return -ENOKEY; 1626 - } 1627 1610 1628 1611 err = generic_file_mmap(file, vma); 1629 1612 if (err) ··· 1696 1697 } 1697 1698 1698 1699 pstr.name[pstr.len] = '\0'; 1699 - 1700 - // XXX this probably won't happen anymore... 1701 - if (pstr.name[0] == '\0') { 1702 - fscrypt_fname_free_buffer(&pstr); 1703 - return ERR_PTR(-ENOENT); 1704 - } 1705 1700 1706 1701 set_delayed_call(done, kfree_link, pstr.name); 1707 1702 return pstr.name;
+18 -18
fs/ubifs/journal.c
··· 549 549 struct ubifs_ino_node *ino; 550 550 union ubifs_key dent_key, ino_key; 551 551 552 - //dbg_jnl("ino %lu, dent '%.*s', data len %d in dir ino %lu", 553 - // inode->i_ino, nm->len, nm->name, ui->data_len, dir->i_ino); 554 552 ubifs_assert(mutex_is_locked(&host_ui->ui_mutex)); 555 553 556 554 dlen = UBIFS_DENT_NODE_SZ + fname_len(nm) + 1; ··· 572 574 /* Make sure to also account for extended attributes */ 573 575 len += host_ui->data_len; 574 576 575 - dent = kmalloc(len, GFP_NOFS); 577 + dent = kzalloc(len, GFP_NOFS); 576 578 if (!dent) 577 579 return -ENOMEM; 578 580 ··· 583 585 584 586 if (!xent) { 585 587 dent->ch.node_type = UBIFS_DENT_NODE; 586 - dent_key_init(c, &dent_key, dir->i_ino, nm); 588 + if (nm->hash) 589 + dent_key_init_hash(c, &dent_key, dir->i_ino, nm->hash); 590 + else 591 + dent_key_init(c, &dent_key, dir->i_ino, nm); 587 592 } else { 588 593 dent->ch.node_type = UBIFS_XENT_NODE; 589 594 xent_key_init(c, &dent_key, dir->i_ino, nm); ··· 630 629 kfree(dent); 631 630 632 631 if (deletion) { 633 - err = ubifs_tnc_remove_nm(c, &dent_key, nm); 632 + if (nm->hash) 633 + err = ubifs_tnc_remove_dh(c, &dent_key, nm->minor_hash); 634 + else 635 + err = ubifs_tnc_remove_nm(c, &dent_key, nm); 634 636 if (err) 635 637 goto out_ro; 636 638 err = ubifs_add_dirt(c, lnum, dlen); ··· 954 950 int twoparents = (fst_dir != snd_dir); 955 951 void *p; 956 952 957 - //dbg_jnl("dent '%pd' in dir ino %lu between dent '%pd' in dir ino %lu", 958 - // fst_dentry, fst_dir->i_ino, snd_dentry, snd_dir->i_ino); 959 - 960 953 ubifs_assert(ubifs_inode(fst_dir)->data_len == 0); 961 954 ubifs_assert(ubifs_inode(snd_dir)->data_len == 0); 962 955 ubifs_assert(mutex_is_locked(&ubifs_inode(fst_dir)->ui_mutex)); ··· 968 967 if (twoparents) 969 968 len += plen; 970 969 971 - dent1 = kmalloc(len, GFP_NOFS); 970 + dent1 = kzalloc(len, GFP_NOFS); 972 971 if (!dent1) 973 972 return -ENOMEM; 974 973 ··· 985 984 dent1->nlen = cpu_to_le16(fname_len(snd_nm)); 986 985 memcpy(dent1->name, fname_name(snd_nm), fname_len(snd_nm)); 987 986 dent1->name[fname_len(snd_nm)] = '\0'; 987 + set_dent_cookie(c, dent1); 988 988 zero_dent_node_unused(dent1); 989 989 ubifs_prep_grp_node(c, dent1, dlen1, 0); 990 990 ··· 998 996 dent2->nlen = cpu_to_le16(fname_len(fst_nm)); 999 997 memcpy(dent2->name, fname_name(fst_nm), fname_len(fst_nm)); 1000 998 dent2->name[fname_len(fst_nm)] = '\0'; 999 + set_dent_cookie(c, dent2); 1001 1000 zero_dent_node_unused(dent2); 1002 1001 ubifs_prep_grp_node(c, dent2, dlen2, 0); 1003 1002 ··· 1097 1094 int move = (old_dir != new_dir); 1098 1095 struct ubifs_inode *uninitialized_var(new_ui); 1099 1096 1100 - //dbg_jnl("dent '%pd' in dir ino %lu to dent '%pd' in dir ino %lu", 1101 - // old_dentry, old_dir->i_ino, new_dentry, new_dir->i_ino); 1102 1097 ubifs_assert(ubifs_inode(old_dir)->data_len == 0); 1103 1098 ubifs_assert(ubifs_inode(new_dir)->data_len == 0); 1104 1099 ubifs_assert(mutex_is_locked(&ubifs_inode(old_dir)->ui_mutex)); ··· 1118 1117 len = aligned_dlen1 + aligned_dlen2 + ALIGN(ilen, 8) + ALIGN(plen, 8); 1119 1118 if (move) 1120 1119 len += plen; 1121 - dent = kmalloc(len, GFP_NOFS); 1120 + dent = kzalloc(len, GFP_NOFS); 1122 1121 if (!dent) 1123 1122 return -ENOMEM; 1124 1123 ··· 1299 1298 goto out; 1300 1299 } 1301 1300 1302 - if (compr_type != UBIFS_COMPR_NONE) { 1301 + if (compr_type == UBIFS_COMPR_NONE) { 1302 + out_len = *new_len; 1303 + } else { 1303 1304 err = ubifs_decompress(c, &dn->data, dlen, buf, &out_len, compr_type); 1304 1305 if (err) 1305 1306 goto out; ··· 1488 1485 int sync = IS_DIRSYNC(host); 1489 1486 struct ubifs_inode *host_ui = ubifs_inode(host); 1490 1487 1491 - //dbg_jnl("host %lu, xattr ino %lu, name '%s', data len %d", 1492 - // host->i_ino, inode->i_ino, nm->name, 1493 - // ubifs_inode(inode)->data_len); 1494 1488 ubifs_assert(inode->i_nlink == 0); 1495 1489 ubifs_assert(mutex_is_locked(&host_ui->ui_mutex)); 1496 1490 ··· 1500 1500 hlen = host_ui->data_len + UBIFS_INO_NODE_SZ; 1501 1501 len = aligned_xlen + UBIFS_INO_NODE_SZ + ALIGN(hlen, 8); 1502 1502 1503 - xent = kmalloc(len, GFP_NOFS); 1503 + xent = kzalloc(len, GFP_NOFS); 1504 1504 if (!xent) 1505 1505 return -ENOMEM; 1506 1506 ··· 1607 1607 aligned_len1 = ALIGN(len1, 8); 1608 1608 aligned_len = aligned_len1 + ALIGN(len2, 8); 1609 1609 1610 - ino = kmalloc(aligned_len, GFP_NOFS); 1610 + ino = kzalloc(aligned_len, GFP_NOFS); 1611 1611 if (!ino) 1612 1612 return -ENOMEM; 1613 1613
+1
fs/ubifs/key.h
··· 162 162 uint32_t hash = c->key_hash(fname_name(nm), fname_len(nm)); 163 163 164 164 ubifs_assert(!(hash & ~UBIFS_S_KEY_HASH_MASK)); 165 + ubifs_assert(!nm->hash && !nm->minor_hash); 165 166 key->u32[0] = inum; 166 167 key->u32[1] = hash | (UBIFS_DENT_KEY << UBIFS_S_KEY_HASH_BITS); 167 168 }
+10 -1
fs/ubifs/super.c
··· 45 45 #define UBIFS_KMALLOC_OK (128*1024) 46 46 47 47 /* Slab cache for UBIFS inodes */ 48 - struct kmem_cache *ubifs_inode_slab; 48 + static struct kmem_cache *ubifs_inode_slab; 49 49 50 50 /* UBIFS TNC shrinker description */ 51 51 static struct shrinker ubifs_shrinker_info = { ··· 445 445 seq_printf(s, ",compr=%s", 446 446 ubifs_compr_name(c->mount_opts.compr_type)); 447 447 } 448 + 449 + seq_printf(s, ",ubi=%d,vol=%d", c->vi.ubi_num, c->vi.vol_id); 448 450 449 451 return 0; 450 452 } ··· 933 931 Opt_chk_data_crc, 934 932 Opt_no_chk_data_crc, 935 933 Opt_override_compr, 934 + Opt_ignore, 936 935 Opt_err, 937 936 }; 938 937 ··· 945 942 {Opt_chk_data_crc, "chk_data_crc"}, 946 943 {Opt_no_chk_data_crc, "no_chk_data_crc"}, 947 944 {Opt_override_compr, "compr=%s"}, 945 + {Opt_ignore, "ubi=%s"}, 946 + {Opt_ignore, "vol=%s"}, 948 947 {Opt_err, NULL}, 949 948 }; 950 949 ··· 1047 1042 c->default_compr = c->mount_opts.compr_type; 1048 1043 break; 1049 1044 } 1045 + case Opt_ignore: 1046 + break; 1050 1047 default: 1051 1048 { 1052 1049 unsigned long flag; ··· 1876 1869 bu_init(c); 1877 1870 else { 1878 1871 dbg_gen("disable bulk-read"); 1872 + mutex_lock(&c->bu_mutex); 1879 1873 kfree(c->bu.buf); 1880 1874 c->bu.buf = NULL; 1875 + mutex_unlock(&c->bu_mutex); 1881 1876 } 1882 1877 1883 1878 ubifs_assert(c->lst.taken_empty_lebs > 0);
+118 -32
fs/ubifs/tnc.c
··· 1812 1812 int found, n, err; 1813 1813 struct ubifs_znode *znode; 1814 1814 1815 - //dbg_tnck(key, "name '%.*s' key ", nm->len, nm->name); 1815 + dbg_tnck(key, "key "); 1816 1816 mutex_lock(&c->tnc_mutex); 1817 1817 found = ubifs_lookup_level0(c, key, &znode, &n); 1818 1818 if (!found) { ··· 1880 1880 return do_lookup_nm(c, key, node, nm); 1881 1881 } 1882 1882 1883 + static int search_dh_cookie(struct ubifs_info *c, const union ubifs_key *key, 1884 + struct ubifs_dent_node *dent, uint32_t cookie, 1885 + struct ubifs_znode **zn, int *n) 1886 + { 1887 + int err; 1888 + struct ubifs_znode *znode = *zn; 1889 + struct ubifs_zbranch *zbr; 1890 + union ubifs_key *dkey; 1891 + 1892 + for (;;) { 1893 + if (!err) { 1894 + err = tnc_next(c, &znode, n); 1895 + if (err) 1896 + goto out; 1897 + } 1898 + 1899 + zbr = &znode->zbranch[*n]; 1900 + dkey = &zbr->key; 1901 + 1902 + if (key_inum(c, dkey) != key_inum(c, key) || 1903 + key_type(c, dkey) != key_type(c, key)) { 1904 + err = -ENOENT; 1905 + goto out; 1906 + } 1907 + 1908 + err = tnc_read_hashed_node(c, zbr, dent); 1909 + if (err) 1910 + goto out; 1911 + 1912 + if (key_hash(c, key) == key_hash(c, dkey) && 1913 + le32_to_cpu(dent->cookie) == cookie) { 1914 + *zn = znode; 1915 + goto out; 1916 + } 1917 + } 1918 + 1919 + out: 1920 + 1921 + return err; 1922 + } 1923 + 1883 1924 static int do_lookup_dh(struct ubifs_info *c, const union ubifs_key *key, 1884 1925 struct ubifs_dent_node *dent, uint32_t cookie) 1885 1926 { 1886 - int n, err, type = key_type(c, key); 1927 + int n, err; 1887 1928 struct ubifs_znode *znode; 1888 - struct ubifs_zbranch *zbr; 1889 - union ubifs_key *dkey, start_key; 1929 + union ubifs_key start_key; 1890 1930 1891 1931 ubifs_assert(is_hash_key(c, key)); 1892 1932 ··· 1937 1897 if (unlikely(err < 0)) 1938 1898 goto out_unlock; 1939 1899 1940 - for (;;) { 1941 - if (!err) { 1942 - err = tnc_next(c, &znode, &n); 1943 - if (err) 1944 - goto out_unlock; 1945 - } 1946 - 1947 - zbr = &znode->zbranch[n]; 1948 - dkey = &zbr->key; 1949 - 1950 - if (key_inum(c, dkey) != key_inum(c, key) || 1951 - key_type(c, dkey) != type) { 1952 - err = -ENOENT; 1953 - goto out_unlock; 1954 - } 1955 - 1956 - err = tnc_read_hashed_node(c, zbr, dent); 1957 - if (err) 1958 - goto out_unlock; 1959 - 1960 - if (key_hash(c, key) == key_hash(c, dkey) && 1961 - le32_to_cpu(dent->cookie) == cookie) 1962 - goto out_unlock; 1963 - } 1900 + err = search_dh_cookie(c, key, dent, cookie, &znode, &n); 1964 1901 1965 1902 out_unlock: 1966 1903 mutex_unlock(&c->tnc_mutex); ··· 2410 2393 struct ubifs_znode *znode; 2411 2394 2412 2395 mutex_lock(&c->tnc_mutex); 2413 - //dbg_tnck(key, "LEB %d:%d, name '%.*s', key ", 2414 - // lnum, offs, nm->len, nm->name); 2396 + dbg_tnck(key, "LEB %d:%d, key ", lnum, offs); 2415 2397 found = lookup_level0_dirty(c, key, &znode, &n); 2416 2398 if (found < 0) { 2417 2399 err = found; ··· 2644 2628 struct ubifs_znode *znode; 2645 2629 2646 2630 mutex_lock(&c->tnc_mutex); 2647 - //dbg_tnck(key, "%.*s, key ", nm->len, nm->name); 2631 + dbg_tnck(key, "key "); 2648 2632 err = lookup_level0_dirty(c, key, &znode, &n); 2649 2633 if (err < 0) 2650 2634 goto out_unlock; ··· 2671 2655 } 2672 2656 } 2673 2657 2658 + out_unlock: 2659 + if (!err) 2660 + err = dbg_check_tnc(c, 0); 2661 + mutex_unlock(&c->tnc_mutex); 2662 + return err; 2663 + } 2664 + 2665 + /** 2666 + * ubifs_tnc_remove_dh - remove an index entry for a "double hashed" node. 2667 + * @c: UBIFS file-system description object 2668 + * @key: key of node 2669 + * @cookie: node cookie for collision resolution 2670 + * 2671 + * Returns %0 on success or negative error code on failure. 2672 + */ 2673 + int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, 2674 + uint32_t cookie) 2675 + { 2676 + int n, err; 2677 + struct ubifs_znode *znode; 2678 + struct ubifs_dent_node *dent; 2679 + struct ubifs_zbranch *zbr; 2680 + 2681 + if (!c->double_hash) 2682 + return -EOPNOTSUPP; 2683 + 2684 + mutex_lock(&c->tnc_mutex); 2685 + err = lookup_level0_dirty(c, key, &znode, &n); 2686 + if (err <= 0) 2687 + goto out_unlock; 2688 + 2689 + zbr = &znode->zbranch[n]; 2690 + dent = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS); 2691 + if (!dent) { 2692 + err = -ENOMEM; 2693 + goto out_unlock; 2694 + } 2695 + 2696 + err = tnc_read_hashed_node(c, zbr, dent); 2697 + if (err) 2698 + goto out_free; 2699 + 2700 + /* If the cookie does not match, we're facing a hash collision. */ 2701 + if (le32_to_cpu(dent->cookie) != cookie) { 2702 + union ubifs_key start_key; 2703 + 2704 + lowest_dent_key(c, &start_key, key_inum(c, key)); 2705 + 2706 + err = ubifs_lookup_level0(c, &start_key, &znode, &n); 2707 + if (unlikely(err < 0)) 2708 + goto out_free; 2709 + 2710 + err = search_dh_cookie(c, key, dent, cookie, &znode, &n); 2711 + if (err) 2712 + goto out_free; 2713 + } 2714 + 2715 + if (znode->cnext || !ubifs_zn_dirty(znode)) { 2716 + znode = dirty_cow_bottom_up(c, znode); 2717 + if (IS_ERR(znode)) { 2718 + err = PTR_ERR(znode); 2719 + goto out_free; 2720 + } 2721 + } 2722 + err = tnc_delete(c, znode, n); 2723 + 2724 + out_free: 2725 + kfree(dent); 2674 2726 out_unlock: 2675 2727 if (!err) 2676 2728 err = dbg_check_tnc(c, 0); ··· 2886 2802 dbg_tnc("xent '%s', ino %lu", xent->name, 2887 2803 (unsigned long)xattr_inum); 2888 2804 2805 + ubifs_evict_xattr_inode(c, xattr_inum); 2806 + 2889 2807 fname_name(&nm) = xent->name; 2890 2808 fname_len(&nm) = le16_to_cpu(xent->nlen); 2891 2809 err = ubifs_tnc_remove_nm(c, &key1, &nm); ··· 2949 2863 struct ubifs_zbranch *zbr; 2950 2864 union ubifs_key *dkey; 2951 2865 2952 - //dbg_tnck(key, "%s ", nm->name ? (char *)nm->name : "(lowest)"); 2866 + dbg_tnck(key, "key "); 2953 2867 ubifs_assert(is_hash_key(c, key)); 2954 2868 2955 2869 mutex_lock(&c->tnc_mutex);
+4
fs/ubifs/tnc_commit.c
··· 57 57 ubifs_dump_znode(c, znode); 58 58 if (zbr->znode) 59 59 ubifs_dump_znode(c, zbr->znode); 60 + 61 + return -EINVAL; 60 62 } 61 63 } 62 64 ubifs_prepare_node(c, idx, len, 0); ··· 861 859 ubifs_dump_znode(c, znode); 862 860 if (zbr->znode) 863 861 ubifs_dump_znode(c, zbr->znode); 862 + 863 + return -EINVAL; 864 864 } 865 865 } 866 866 len = ubifs_idx_node_sz(c, znode->child_cnt);
+4 -2
fs/ubifs/ubifs.h
··· 1451 1451 extern struct list_head ubifs_infos; 1452 1452 extern spinlock_t ubifs_infos_lock; 1453 1453 extern atomic_long_t ubifs_clean_zn_cnt; 1454 - extern struct kmem_cache *ubifs_inode_slab; 1455 1454 extern const struct super_operations ubifs_super_operations; 1456 1455 extern const struct address_space_operations ubifs_file_address_operations; 1457 1456 extern const struct file_operations ubifs_file_operations; ··· 1589 1590 int ubifs_tnc_remove(struct ubifs_info *c, const union ubifs_key *key); 1590 1591 int ubifs_tnc_remove_nm(struct ubifs_info *c, const union ubifs_key *key, 1591 1592 const struct fscrypt_name *nm); 1593 + int ubifs_tnc_remove_dh(struct ubifs_info *c, const union ubifs_key *key, 1594 + uint32_t cookie); 1592 1595 int ubifs_tnc_remove_range(struct ubifs_info *c, union ubifs_key *from_key, 1593 1596 union ubifs_key *to_key); 1594 1597 int ubifs_tnc_remove_ino(struct ubifs_info *c, ino_t inum); ··· 1755 1754 extern const struct xattr_handler *ubifs_xattr_handlers[]; 1756 1755 ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size); 1757 1756 int ubifs_xattr_set(struct inode *host, const char *name, const void *value, 1758 - size_t size, int flags); 1757 + size_t size, int flags, bool check_lock); 1759 1758 ssize_t ubifs_xattr_get(struct inode *host, const char *name, void *buf, 1760 1759 size_t size); 1760 + void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum); 1761 1761 1762 1762 #ifdef CONFIG_UBIFS_FS_SECURITY 1763 1763 extern int ubifs_init_security(struct inode *dentry, struct inode *inode,
+30 -9
fs/ubifs/xattr.c
··· 280 280 } 281 281 282 282 int ubifs_xattr_set(struct inode *host, const char *name, const void *value, 283 - size_t size, int flags) 283 + size_t size, int flags, bool check_lock) 284 284 { 285 285 struct inode *inode; 286 286 struct ubifs_info *c = host->i_sb->s_fs_info; ··· 289 289 union ubifs_key key; 290 290 int err; 291 291 292 - /* 293 - * Creating an encryption context is done unlocked since we 294 - * operate on a new inode which is not visible to other users 295 - * at this point. 296 - */ 297 - if (strcmp(name, UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT) != 0) 292 + if (check_lock) 298 293 ubifs_assert(inode_is_locked(host)); 299 294 300 295 if (size > UBIFS_MAX_INO_DATA) ··· 508 513 return err; 509 514 } 510 515 516 + /** 517 + * ubifs_evict_xattr_inode - Evict an xattr inode. 518 + * @c: UBIFS file-system description object 519 + * @xattr_inum: xattr inode number 520 + * 521 + * When an inode that hosts xattrs is being removed we have to make sure 522 + * that cached inodes of the xattrs also get removed from the inode cache 523 + * otherwise we'd waste memory. This function looks up an inode from the 524 + * inode cache and clears the link counter such that iput() will evict 525 + * the inode. 526 + */ 527 + void ubifs_evict_xattr_inode(struct ubifs_info *c, ino_t xattr_inum) 528 + { 529 + struct inode *inode; 530 + 531 + inode = ilookup(c->vfs_sb, xattr_inum); 532 + if (inode) { 533 + clear_nlink(inode); 534 + iput(inode); 535 + } 536 + } 537 + 511 538 static int ubifs_xattr_remove(struct inode *host, const char *name) 512 539 { 513 540 struct inode *inode; ··· 593 576 } 594 577 strcpy(name, XATTR_SECURITY_PREFIX); 595 578 strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name); 579 + /* 580 + * creating a new inode without holding the inode rwsem, 581 + * no need to check whether inode is locked. 582 + */ 596 583 err = ubifs_xattr_set(inode, name, xattr->value, 597 - xattr->value_len, 0); 584 + xattr->value_len, 0, false); 598 585 kfree(name); 599 586 if (err < 0) 600 587 break; ··· 645 624 name = xattr_full_name(handler, name); 646 625 647 626 if (value) 648 - return ubifs_xattr_set(inode, name, value, size, flags); 627 + return ubifs_xattr_set(inode, name, value, size, flags, true); 649 628 else 650 629 return ubifs_xattr_remove(inode, name); 651 630 }