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: I97cbbe44489a8e013ba2ac0fb493ff6da3f635be
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 208dd116f96ea19e5d38d7b80fce49bc5ce1bbe8)
Signed-off-by: Arnav Kansal <rnv@google.com>
Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/62695
Reviewed-by: Oleksandr Tymoshenko <ovt@google.com>
Tested-by: Cusky Presubmit Bot <presubmit@cos-infra-prod.iam.gserviceaccount.com>
1 file changed