mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
xfs: don't allow sorting sparse arrays
Now that we've reduced the functionality of xfarray_unset, let's add a new safeguard: no sorting of xfarrays with sparse holes in them. It's not clear what that even means, and nobody actually does this, so we're really just eliminating subtle logic bombs. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
parent
3a94b91aef
commit
76ac15cafb
|
|
@ -152,6 +152,9 @@ xfarray_trim(
|
|||
return -ENODATA;
|
||||
|
||||
array->nr -= nr;
|
||||
if (!array->nr)
|
||||
array->possibly_sparse = false;
|
||||
|
||||
new_eof = xfarray_pos(array, array->nr);
|
||||
xfile_discard(array->xfile, new_eof, MAX_LFS_FILESIZE - new_eof);
|
||||
return 0;
|
||||
|
|
@ -179,6 +182,8 @@ xfarray_store(
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (idx > array->nr)
|
||||
array->possibly_sparse = true;
|
||||
array->nr = max(array->nr, idx + 1);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -853,6 +858,14 @@ xfarray_sort(
|
|||
return 0;
|
||||
if (array->nr >= QSORT_MAX_RECS)
|
||||
return -E2BIG;
|
||||
if (array->possibly_sparse) {
|
||||
/*
|
||||
* What does it mean to sort an array with holes in it?
|
||||
* Currently none of the users need this ability.
|
||||
*/
|
||||
ASSERT(!array->possibly_sparse);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
error = xfarray_sortinfo_alloc(array, cmp_fn, flags, &si);
|
||||
if (error)
|
||||
|
|
@ -1006,4 +1019,5 @@ xfarray_truncate(
|
|||
{
|
||||
xfile_discard(array->xfile, 0, MAX_LFS_FILESIZE);
|
||||
array->nr = 0;
|
||||
array->possibly_sparse = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ struct xfarray {
|
|||
|
||||
/* log2 of array element size, if possible. */
|
||||
int obj_size_log;
|
||||
|
||||
/* Might there be sparse holes in this array? */
|
||||
bool possibly_sparse;
|
||||
};
|
||||
|
||||
int xfarray_create(const char *descr, unsigned long long required_capacity,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user