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 'ntfs3_for_6.13' of https://github.com/Paragon-Software-Group/linux-ntfs3

Pull ntfs3 updates from Konstantin Komarov:

- additional checks to address issues identified by syzbot

- continuation of the transition from 'page' to 'folio'

* tag 'ntfs3_for_6.13' of https://github.com/Paragon-Software-Group/linux-ntfs3:
fs/ntfs3: Accumulated refactoring changes
fs/ntfs3: Switch to folio to release resources
fs/ntfs3: Add check in ntfs_extend_initialized_size
fs/ntfs3: Add more checks in mi_enum_attr (part 2)
fs/ntfs3: Equivalent transition from page to folio
fs/ntfs3: Fix case when unmarked clusters intersect with zone
fs/ntfs3: Fix warning in ni_fiemap

+102 -166
+4 -5
fs/ntfs3/attrib.c
··· 977 977 978 978 /* Check for compressed frame. */ 979 979 err = attr_is_frame_compressed(ni, attr_b, vcn >> NTFS_LZNT_CUNIT, 980 - &hint); 980 + &hint, run); 981 981 if (err) 982 982 goto out; 983 983 ··· 1521 1521 * attr_is_frame_compressed - Used to detect compressed frame. 1522 1522 * 1523 1523 * attr - base (primary) attribute segment. 1524 + * run - run to use, usually == &ni->file.run. 1524 1525 * Only base segments contains valid 'attr->nres.c_unit' 1525 1526 */ 1526 1527 int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr, 1527 - CLST frame, CLST *clst_data) 1528 + CLST frame, CLST *clst_data, struct runs_tree *run) 1528 1529 { 1529 1530 int err; 1530 1531 u32 clst_frame; 1531 1532 CLST clen, lcn, vcn, alen, slen, vcn_next; 1532 1533 size_t idx; 1533 - struct runs_tree *run; 1534 1534 1535 1535 *clst_data = 0; 1536 1536 ··· 1542 1542 1543 1543 clst_frame = 1u << attr->nres.c_unit; 1544 1544 vcn = frame * clst_frame; 1545 - run = &ni->file.run; 1546 1545 1547 1546 if (!run_lookup_entry(run, vcn, &lcn, &clen, &idx)) { 1548 1547 err = attr_load_runs_vcn(ni, attr->type, attr_name(attr), ··· 1677 1678 if (err) 1678 1679 goto out; 1679 1680 1680 - err = attr_is_frame_compressed(ni, attr_b, frame, &clst_data); 1681 + err = attr_is_frame_compressed(ni, attr_b, frame, &clst_data, run); 1681 1682 if (err) 1682 1683 goto out; 1683 1684
+17 -45
fs/ntfs3/bitmap.c
··· 710 710 { 711 711 int err = 0; 712 712 struct super_block *sb = wnd->sb; 713 - size_t bits0 = bits; 714 713 u32 wbits = 8 * sb->s_blocksize; 715 714 size_t iw = bit >> (sb->s_blocksize_bits + 3); 716 715 u32 wbit = bit & (wbits - 1); 717 716 struct buffer_head *bh; 717 + u32 op; 718 718 719 - while (iw < wnd->nwnd && bits) { 720 - u32 tail, op; 721 - 719 + for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) { 722 720 if (iw + 1 == wnd->nwnd) 723 721 wbits = wnd->bits_last; 724 722 725 - tail = wbits - wbit; 726 - op = min_t(u32, tail, bits); 723 + op = min_t(u32, wbits - wbit, bits); 727 724 728 725 bh = wnd_map(wnd, iw); 729 726 if (IS_ERR(bh)) { ··· 733 736 ntfs_bitmap_clear_le(bh->b_data, wbit, op); 734 737 735 738 wnd->free_bits[iw] += op; 739 + wnd->total_zeroes += op; 736 740 737 741 set_buffer_uptodate(bh); 738 742 mark_buffer_dirty(bh); 739 743 unlock_buffer(bh); 740 744 put_bh(bh); 741 745 742 - wnd->total_zeroes += op; 743 - bits -= op; 744 - wbit = 0; 745 - iw += 1; 746 + wnd_add_free_ext(wnd, bit, op, false); 746 747 } 747 - 748 - wnd_add_free_ext(wnd, bit, bits0, false); 749 - 750 748 return err; 751 749 } 752 750 ··· 752 760 { 753 761 int err = 0; 754 762 struct super_block *sb = wnd->sb; 755 - size_t bits0 = bits; 756 763 size_t iw = bit >> (sb->s_blocksize_bits + 3); 757 764 u32 wbits = 8 * sb->s_blocksize; 758 765 u32 wbit = bit & (wbits - 1); 759 766 struct buffer_head *bh; 767 + u32 op; 760 768 761 - while (iw < wnd->nwnd && bits) { 762 - u32 tail, op; 763 - 769 + for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) { 764 770 if (unlikely(iw + 1 == wnd->nwnd)) 765 771 wbits = wnd->bits_last; 766 772 767 - tail = wbits - wbit; 768 - op = min_t(u32, tail, bits); 773 + op = min_t(u32, wbits - wbit, bits); 769 774 770 775 bh = wnd_map(wnd, iw); 771 776 if (IS_ERR(bh)) { ··· 774 785 775 786 ntfs_bitmap_set_le(bh->b_data, wbit, op); 776 787 wnd->free_bits[iw] -= op; 788 + wnd->total_zeroes -= op; 777 789 778 790 set_buffer_uptodate(bh); 779 791 mark_buffer_dirty(bh); 780 792 unlock_buffer(bh); 781 793 put_bh(bh); 782 794 783 - wnd->total_zeroes -= op; 784 - bits -= op; 785 - wbit = 0; 786 - iw += 1; 795 + if (!RB_EMPTY_ROOT(&wnd->start_tree)) 796 + wnd_remove_free_ext(wnd, bit, op); 787 797 } 788 - 789 - if (!RB_EMPTY_ROOT(&wnd->start_tree)) 790 - wnd_remove_free_ext(wnd, bit, bits0); 791 - 792 798 return err; 793 799 } 794 800 ··· 836 852 size_t iw = bit >> (sb->s_blocksize_bits + 3); 837 853 u32 wbits = 8 * sb->s_blocksize; 838 854 u32 wbit = bit & (wbits - 1); 855 + u32 op; 839 856 840 - while (iw < wnd->nwnd && bits) { 841 - u32 tail, op; 842 - 857 + for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) { 843 858 if (unlikely(iw + 1 == wnd->nwnd)) 844 859 wbits = wnd->bits_last; 845 860 846 - tail = wbits - wbit; 847 - op = min_t(u32, tail, bits); 861 + op = min_t(u32, wbits - wbit, bits); 848 862 849 863 if (wbits != wnd->free_bits[iw]) { 850 864 bool ret; ··· 857 875 if (!ret) 858 876 return false; 859 877 } 860 - 861 - bits -= op; 862 - wbit = 0; 863 - iw += 1; 864 878 } 865 879 866 880 return true; ··· 906 928 size_t iw = bit >> (sb->s_blocksize_bits + 3); 907 929 u32 wbits = 8 * sb->s_blocksize; 908 930 u32 wbit = bit & (wbits - 1); 931 + u32 op; 909 932 size_t end; 910 933 struct rb_node *n; 911 934 struct e_node *e; ··· 924 945 return false; 925 946 926 947 use_wnd: 927 - while (iw < wnd->nwnd && bits) { 928 - u32 tail, op; 929 - 948 + for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) { 930 949 if (unlikely(iw + 1 == wnd->nwnd)) 931 950 wbits = wnd->bits_last; 932 951 933 - tail = wbits - wbit; 934 - op = min_t(u32, tail, bits); 952 + op = min_t(u32, wbits - wbit, bits); 935 953 936 954 if (wnd->free_bits[iw]) { 937 955 bool ret; ··· 942 966 if (!ret) 943 967 goto out; 944 968 } 945 - 946 - bits -= op; 947 - wbit = 0; 948 - iw += 1; 949 969 } 950 970 ret = true; 951 971
+21 -13
fs/ntfs3/file.c
··· 182 182 loff_t pos = valid; 183 183 int err; 184 184 185 + if (valid >= new_valid) 186 + return 0; 187 + 185 188 if (is_resident(ni)) { 186 189 ni->i_valid = new_valid; 187 190 return 0; 188 191 } 189 192 190 193 WARN_ON(is_compressed(ni)); 191 - WARN_ON(valid >= new_valid); 192 194 193 195 for (;;) { 194 196 u32 zerofrom, len; ··· 224 222 if (err) 225 223 goto out; 226 224 227 - folio_zero_range(folio, zerofrom, folio_size(folio)); 225 + folio_zero_range(folio, zerofrom, folio_size(folio) - zerofrom); 228 226 229 227 err = ntfs_write_end(file, mapping, pos, len, len, folio, NULL); 230 228 if (err < 0) ··· 989 987 u64 frame_vbo; 990 988 pgoff_t index; 991 989 bool frame_uptodate; 990 + struct folio *folio; 992 991 993 992 if (frame_size < PAGE_SIZE) { 994 993 /* ··· 1044 1041 if (err) { 1045 1042 for (ip = 0; ip < pages_per_frame; ip++) { 1046 1043 page = pages[ip]; 1047 - unlock_page(page); 1048 - put_page(page); 1044 + folio = page_folio(page); 1045 + folio_unlock(folio); 1046 + folio_put(folio); 1049 1047 } 1050 1048 goto out; 1051 1049 } ··· 1056 1052 off = offset_in_page(valid); 1057 1053 for (; ip < pages_per_frame; ip++, off = 0) { 1058 1054 page = pages[ip]; 1055 + folio = page_folio(page); 1059 1056 zero_user_segment(page, off, PAGE_SIZE); 1060 1057 flush_dcache_page(page); 1061 - SetPageUptodate(page); 1058 + folio_mark_uptodate(folio); 1062 1059 } 1063 1060 1064 1061 ni_lock(ni); ··· 1068 1063 1069 1064 for (ip = 0; ip < pages_per_frame; ip++) { 1070 1065 page = pages[ip]; 1071 - SetPageUptodate(page); 1072 - unlock_page(page); 1073 - put_page(page); 1066 + folio = page_folio(page); 1067 + folio_mark_uptodate(folio); 1068 + folio_unlock(folio); 1069 + folio_put(folio); 1074 1070 } 1075 1071 1076 1072 if (err) ··· 1113 1107 for (ip = 0; ip < pages_per_frame; 1114 1108 ip++) { 1115 1109 page = pages[ip]; 1116 - unlock_page(page); 1117 - put_page(page); 1110 + folio = page_folio(page); 1111 + folio_unlock(folio); 1112 + folio_put(folio); 1118 1113 } 1119 1114 goto out; 1120 1115 } ··· 1156 1149 for (ip = 0; ip < pages_per_frame; ip++) { 1157 1150 page = pages[ip]; 1158 1151 ClearPageDirty(page); 1159 - SetPageUptodate(page); 1160 - unlock_page(page); 1161 - put_page(page); 1152 + folio = page_folio(page); 1153 + folio_mark_uptodate(folio); 1154 + folio_unlock(folio); 1155 + folio_put(folio); 1162 1156 } 1163 1157 1164 1158 if (err)
+15 -89
fs/ntfs3/frecord.c
··· 1901 1901 } 1902 1902 1903 1903 /* 1904 - * fiemap_fill_next_extent_k - a copy of fiemap_fill_next_extent 1905 - * but it uses 'fe_k' instead of fieinfo->fi_extents_start 1906 - */ 1907 - static int fiemap_fill_next_extent_k(struct fiemap_extent_info *fieinfo, 1908 - struct fiemap_extent *fe_k, u64 logical, 1909 - u64 phys, u64 len, u32 flags) 1910 - { 1911 - struct fiemap_extent extent; 1912 - 1913 - /* only count the extents */ 1914 - if (fieinfo->fi_extents_max == 0) { 1915 - fieinfo->fi_extents_mapped++; 1916 - return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; 1917 - } 1918 - 1919 - if (fieinfo->fi_extents_mapped >= fieinfo->fi_extents_max) 1920 - return 1; 1921 - 1922 - if (flags & FIEMAP_EXTENT_DELALLOC) 1923 - flags |= FIEMAP_EXTENT_UNKNOWN; 1924 - if (flags & FIEMAP_EXTENT_DATA_ENCRYPTED) 1925 - flags |= FIEMAP_EXTENT_ENCODED; 1926 - if (flags & (FIEMAP_EXTENT_DATA_TAIL | FIEMAP_EXTENT_DATA_INLINE)) 1927 - flags |= FIEMAP_EXTENT_NOT_ALIGNED; 1928 - 1929 - memset(&extent, 0, sizeof(extent)); 1930 - extent.fe_logical = logical; 1931 - extent.fe_physical = phys; 1932 - extent.fe_length = len; 1933 - extent.fe_flags = flags; 1934 - 1935 - memcpy(fe_k + fieinfo->fi_extents_mapped, &extent, sizeof(extent)); 1936 - 1937 - fieinfo->fi_extents_mapped++; 1938 - if (fieinfo->fi_extents_mapped == fieinfo->fi_extents_max) 1939 - return 1; 1940 - return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; 1941 - } 1942 - 1943 - /* 1944 1904 * ni_fiemap - Helper for file_fiemap(). 1945 1905 * 1946 1906 * Assumed ni_lock. ··· 1910 1950 __u64 vbo, __u64 len) 1911 1951 { 1912 1952 int err = 0; 1913 - struct fiemap_extent *fe_k = NULL; 1914 1953 struct ntfs_sb_info *sbi = ni->mi.sbi; 1915 1954 u8 cluster_bits = sbi->cluster_bits; 1916 - struct runs_tree *run; 1917 - struct rw_semaphore *run_lock; 1955 + struct runs_tree run; 1918 1956 struct ATTRIB *attr; 1919 1957 CLST vcn = vbo >> cluster_bits; 1920 1958 CLST lcn, clen; ··· 1923 1965 u32 flags; 1924 1966 bool ok; 1925 1967 1968 + run_init(&run); 1926 1969 if (S_ISDIR(ni->vfs_inode.i_mode)) { 1927 - run = &ni->dir.alloc_run; 1928 1970 attr = ni_find_attr(ni, NULL, NULL, ATTR_ALLOC, I30_NAME, 1929 1971 ARRAY_SIZE(I30_NAME), NULL, NULL); 1930 - run_lock = &ni->dir.run_lock; 1931 1972 } else { 1932 - run = &ni->file.run; 1933 1973 attr = ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, 1934 1974 NULL); 1935 1975 if (!attr) { ··· 1942 1986 "fiemap is not supported for compressed file (cp -r)"); 1943 1987 goto out; 1944 1988 } 1945 - run_lock = &ni->file.run_lock; 1946 1989 } 1947 1990 1948 1991 if (!attr || !attr->non_res) { ··· 1953 1998 goto out; 1954 1999 } 1955 2000 1956 - /* 1957 - * To avoid lock problems replace pointer to user memory by pointer to kernel memory. 1958 - */ 1959 - fe_k = kmalloc_array(fieinfo->fi_extents_max, 1960 - sizeof(struct fiemap_extent), 1961 - GFP_NOFS | __GFP_ZERO); 1962 - if (!fe_k) { 1963 - err = -ENOMEM; 1964 - goto out; 1965 - } 1966 - 1967 2001 end = vbo + len; 1968 2002 alloc_size = le64_to_cpu(attr->nres.alloc_size); 1969 2003 if (end > alloc_size) 1970 2004 end = alloc_size; 1971 2005 1972 - down_read(run_lock); 1973 - 1974 2006 while (vbo < end) { 1975 2007 if (idx == -1) { 1976 - ok = run_lookup_entry(run, vcn, &lcn, &clen, &idx); 2008 + ok = run_lookup_entry(&run, vcn, &lcn, &clen, &idx); 1977 2009 } else { 1978 2010 CLST vcn_next = vcn; 1979 2011 1980 - ok = run_get_entry(run, ++idx, &vcn, &lcn, &clen) && 2012 + ok = run_get_entry(&run, ++idx, &vcn, &lcn, &clen) && 1981 2013 vcn == vcn_next; 1982 2014 if (!ok) 1983 2015 vcn = vcn_next; 1984 2016 } 1985 2017 1986 2018 if (!ok) { 1987 - up_read(run_lock); 1988 - down_write(run_lock); 1989 - 1990 2019 err = attr_load_runs_vcn(ni, attr->type, 1991 2020 attr_name(attr), 1992 - attr->name_len, run, vcn); 1993 - 1994 - up_write(run_lock); 1995 - down_read(run_lock); 2021 + attr->name_len, &run, vcn); 1996 2022 1997 2023 if (err) 1998 2024 break; 1999 2025 2000 - ok = run_lookup_entry(run, vcn, &lcn, &clen, &idx); 2026 + ok = run_lookup_entry(&run, vcn, &lcn, &clen, &idx); 2001 2027 2002 2028 if (!ok) { 2003 2029 err = -EINVAL; ··· 2003 2067 } else if (is_attr_compressed(attr)) { 2004 2068 CLST clst_data; 2005 2069 2006 - err = attr_is_frame_compressed( 2007 - ni, attr, vcn >> attr->nres.c_unit, &clst_data); 2070 + err = attr_is_frame_compressed(ni, attr, 2071 + vcn >> attr->nres.c_unit, 2072 + &clst_data, &run); 2008 2073 if (err) 2009 2074 break; 2010 2075 if (clst_data < NTFS_LZNT_CLUSTERS) ··· 2034 2097 if (vbo + dlen >= end) 2035 2098 flags |= FIEMAP_EXTENT_LAST; 2036 2099 2037 - err = fiemap_fill_next_extent_k(fieinfo, fe_k, vbo, lbo, 2038 - dlen, flags); 2100 + err = fiemap_fill_next_extent(fieinfo, vbo, lbo, dlen, 2101 + flags); 2039 2102 2040 2103 if (err < 0) 2041 2104 break; ··· 2056 2119 if (vbo + bytes >= end) 2057 2120 flags |= FIEMAP_EXTENT_LAST; 2058 2121 2059 - err = fiemap_fill_next_extent_k(fieinfo, fe_k, vbo, lbo, bytes, 2060 - flags); 2122 + err = fiemap_fill_next_extent(fieinfo, vbo, lbo, bytes, flags); 2061 2123 if (err < 0) 2062 2124 break; 2063 2125 if (err == 1) { ··· 2067 2131 vbo += bytes; 2068 2132 } 2069 2133 2070 - up_read(run_lock); 2071 - 2072 - /* 2073 - * Copy to user memory out of lock 2074 - */ 2075 - if (copy_to_user(fieinfo->fi_extents_start, fe_k, 2076 - fieinfo->fi_extents_max * 2077 - sizeof(struct fiemap_extent))) { 2078 - err = -EFAULT; 2079 - } 2080 - 2081 2134 out: 2082 - kfree(fe_k); 2135 + run_close(&run); 2083 2136 return err; 2084 2137 } 2085 2138 ··· 2597 2672 down_write(&ni->file.run_lock); 2598 2673 run_truncate_around(run, le64_to_cpu(attr->nres.svcn)); 2599 2674 frame = frame_vbo >> (cluster_bits + NTFS_LZNT_CUNIT); 2600 - err = attr_is_frame_compressed(ni, attr, frame, &clst_data); 2675 + err = attr_is_frame_compressed(ni, attr, frame, &clst_data, 2676 + run); 2601 2677 up_write(&ni->file.run_lock); 2602 2678 if (err) 2603 2679 goto out1;
fs/ntfs3/fsntfs.c
+2 -1
fs/ntfs3/ntfs_fs.h
··· 446 446 struct runs_tree *run, u64 frame, u64 frames, 447 447 u8 frame_bits, u32 *ondisk_size, u64 *vbo_data); 448 448 int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr, 449 - CLST frame, CLST *clst_data); 449 + CLST frame, CLST *clst_data, 450 + struct runs_tree *run); 450 451 int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size, 451 452 u64 new_valid); 452 453 int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);
+13 -3
fs/ntfs3/record.c
··· 212 212 return NULL; 213 213 214 214 if (off >= used || off < MFTRECORD_FIXUP_OFFSET_1 || 215 - !IS_ALIGNED(off, 4)) { 215 + !IS_ALIGNED(off, 8)) { 216 216 return NULL; 217 217 } 218 218 ··· 236 236 off += asize; 237 237 } 238 238 239 - /* Can we use the first field (attr->type). */ 240 - /* NOTE: this code also checks attr->size availability. */ 239 + /* 240 + * Can we use the first fields: 241 + * attr->type, 242 + * attr->size 243 + */ 241 244 if (off + 8 > used) { 242 245 static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) == 8); 243 246 return NULL; ··· 262 259 263 260 asize = le32_to_cpu(attr->size); 264 261 262 + if (!IS_ALIGNED(asize, 8)) 263 + return NULL; 264 + 265 265 /* Check overflow and boundary. */ 266 266 if (off + asize < off || off + asize > used) 267 + return NULL; 268 + 269 + /* Can we use the field attr->non_res. */ 270 + if (off + 9 > used) 267 271 return NULL; 268 272 269 273 /* Check size of attribute. */
+30 -10
fs/ntfs3/run.c
··· 1055 1055 { 1056 1056 int ret, err; 1057 1057 CLST next_vcn, lcn, len; 1058 - size_t index; 1059 - bool ok; 1058 + size_t index, done; 1059 + bool ok, zone; 1060 1060 struct wnd_bitmap *wnd; 1061 1061 1062 1062 ret = run_unpack(run, sbi, ino, svcn, evcn, vcn, run_buf, run_buf_size); ··· 1087 1087 continue; 1088 1088 1089 1089 down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); 1090 + zone = max(wnd->zone_bit, lcn) < min(wnd->zone_end, lcn + len); 1090 1091 /* Check for free blocks. */ 1091 - ok = wnd_is_used(wnd, lcn, len); 1092 + ok = !zone && wnd_is_used(wnd, lcn, len); 1092 1093 up_read(&wnd->rw_lock); 1093 1094 if (ok) 1094 1095 continue; ··· 1097 1096 /* Looks like volume is corrupted. */ 1098 1097 ntfs_set_state(sbi, NTFS_DIRTY_ERROR); 1099 1098 1100 - if (down_write_trylock(&wnd->rw_lock)) { 1101 - /* Mark all zero bits as used in range [lcn, lcn+len). */ 1102 - size_t done; 1103 - err = wnd_set_used_safe(wnd, lcn, len, &done); 1104 - up_write(&wnd->rw_lock); 1105 - if (err) 1106 - return err; 1099 + if (!down_write_trylock(&wnd->rw_lock)) 1100 + continue; 1101 + 1102 + if (zone) { 1103 + /* 1104 + * Range [lcn, lcn + len) intersects with zone. 1105 + * To avoid complex with zone just turn it off. 1106 + */ 1107 + wnd_zone_set(wnd, 0, 0); 1107 1108 } 1109 + 1110 + /* Mark all zero bits as used in range [lcn, lcn+len). */ 1111 + err = wnd_set_used_safe(wnd, lcn, len, &done); 1112 + if (zone) { 1113 + /* Restore zone. Lock mft run. */ 1114 + struct rw_semaphore *lock = 1115 + is_mounted(sbi) ? &sbi->mft.ni->file.run_lock : 1116 + NULL; 1117 + if (lock) 1118 + down_read(lock); 1119 + ntfs_refresh_zone(sbi); 1120 + if (lock) 1121 + up_read(lock); 1122 + } 1123 + up_write(&wnd->rw_lock); 1124 + if (err) 1125 + return err; 1108 1126 } 1109 1127 1110 1128 return ret;