diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2024-06-24 23:10:59 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-08-19 05:33:29 +0200 |
commit | b54962dc4eec9e46e03795bb65cf3bd943cfd815 (patch) | |
tree | e67d114418ebc445e54c6df051ee38f7e9aa92a2 /kernel | |
parent | 7d87d26bd186456cf90e19a28f89b07901cb225f (diff) | |
download | linux-b54962dc4eec9e46e03795bb65cf3bd943cfd815.tar.gz linux-b54962dc4eec9e46e03795bb65cf3bd943cfd815.tar.bz2 linux-b54962dc4eec9e46e03795bb65cf3bd943cfd815.zip |
perf: Prevent passing zero nr_pages to rb_alloc_aux()
[ Upstream commit dbc48c8f41c208082cfa95e973560134489e3309 ]
nr_pages is unsigned long but gets passed to rb_alloc_aux() as an int,
and is stored as an int.
Only power-of-2 values are accepted, so if nr_pages is a 64_bit value, it
will be passed to rb_alloc_aux() as zero.
That is not ideal because:
1. the value is incorrect
2. rb_alloc_aux() is at risk of misbehaving, although it manages to
return -ENOMEM in that case, it is a result of passing zero to get_order()
even though the get_order() result is documented to be undefined in that
case.
Fix by simply validating the maximum supported value in the first place.
Use -ENOMEM error code for consistency with the current error code that
is returned in that case.
Fixes: 45bfb2e50471 ("perf: Add AUX area to ring buffer for raw data streams")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240624201101.60186-6-adrian.hunter@intel.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/events/core.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index 2347dda682ab..39cf0040e6df 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5830,6 +5830,8 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) return -EINVAL; nr_pages = vma_size / PAGE_SIZE; + if (nr_pages > INT_MAX) + return -ENOMEM; mutex_lock(&event->mmap_mutex); ret = -EINVAL; |