perf: Fix perf_event_validate_size()

[ Upstream commit 382c27f4ed28f803b1f1473ac2d8db0afc795a1b ]

Budimir noted that perf_event_validate_size() only checks the size of
the newly added event, even though the sizes of all existing events
can also change due to not all events having the same read_format.

When we attach the new event, perf_group_attach(), we do re-compute
the size for all events.

BUG=b/317059204
TEST=presubmit
RELEASE_NOTE=Fixed CVE-2023-6931 in the Linux kernel.

Fixes: a723968c0ed3 ("perf: Fix u16 overflows")
Reported-by: Budimir Markovic <markovicbudimir@gmail.com>
Change-Id: I56cd31af0113a317ef7868e7a0869299d75a5207
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit ebc7597ce9719d2ff72e13df072680aa491f27fb)
Signed-off-by: Arnav Kansal <rnv@google.com>
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/62697
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
1 file changed