Skip to content

Commit 3c25fc9

Browse files
melverPeter Zijlstra
authored andcommitted
perf: Copy perf_event_attr::sig_data on modification
The intent has always been that perf_event_attr::sig_data should also be modifiable along with PERF_EVENT_IOC_MODIFY_ATTRIBUTES, because it is observable by user space if SIGTRAP on events is requested. Currently only PERF_TYPE_BREAKPOINT is modifiable, and explicitly copies relevant breakpoint-related attributes in hw_breakpoint_copy_attr(). This misses copying perf_event_attr::sig_data. Since sig_data is not specific to PERF_TYPE_BREAKPOINT, introduce a helper to copy generic event-type-independent attributes on modification. Fixes: 97ba62b ("perf: Add support for SIGTRAP on perf events") Reported-by: Dmitry Vyukov <[email protected]> Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a01994f commit 3c25fc9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

kernel/events/core.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,15 @@ static int perf_event_modify_breakpoint(struct perf_event *bp,
32383238
return err;
32393239
}
32403240

3241+
/*
3242+
* Copy event-type-independent attributes that may be modified.
3243+
*/
3244+
static void perf_event_modify_copy_attr(struct perf_event_attr *to,
3245+
const struct perf_event_attr *from)
3246+
{
3247+
to->sig_data = from->sig_data;
3248+
}
3249+
32413250
static int perf_event_modify_attr(struct perf_event *event,
32423251
struct perf_event_attr *attr)
32433252
{
@@ -3260,10 +3269,17 @@ static int perf_event_modify_attr(struct perf_event *event,
32603269
WARN_ON_ONCE(event->ctx->parent_ctx);
32613270

32623271
mutex_lock(&event->child_mutex);
3272+
/*
3273+
* Event-type-independent attributes must be copied before event-type
3274+
* modification, which will validate that final attributes match the
3275+
* source attributes after all relevant attributes have been copied.
3276+
*/
3277+
perf_event_modify_copy_attr(&event->attr, attr);
32633278
err = func(event, attr);
32643279
if (err)
32653280
goto out;
32663281
list_for_each_entry(child, &event->child_list, child_list) {
3282+
perf_event_modify_copy_attr(&child->attr, attr);
32673283
err = func(child, attr);
32683284
if (err)
32693285
goto out;

0 commit comments

Comments
 (0)