Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp687982pxb; Tue, 1 Feb 2022 08:23:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWN+4ztoIsq7I9647npD1WI6SKXGPVCFe5R/0zKrf6iGJU/rTwYCnbznUjsy2Qqwn2PMMj X-Received: by 2002:a17:902:db0f:: with SMTP id m15mr26765625plx.158.1643732580251; Tue, 01 Feb 2022 08:23:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643732580; cv=none; d=google.com; s=arc-20160816; b=HUOL29w6kSp7Lm18WrAztaJ5St85AdLjYNNATpI+xKYW6QhDTPlA4oF75r3+TOH1x3 HTpauBTMtEZKIaioEtM3Q58b8eRi97U5KpeGcykkqJTrfV4C69rBnO9dR2GtNg3bFhAC zgu8UGXZ4lAkLYcWS4tHHCVtj7/fidOZ/iyDpVCUNtNOYDQmLTFkOzBTHu9q418qG/ku ysYUAT7eYWGgiBfgJ5/VVc3aXQuaJOVXa/lsC6tBHaJR3JrBZLYlvAF/tR8n2yrJjzOc mNjwxweyXzpnCFqPznJYxyEvRUUryHfVK9U0fUDrdXTJvj8h52qXg25jWMhav8RjuKQy f14A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=gQiXNhpWeE3w8plSrWyGvN1lrZy07A1L66IKLC7CKbA=; b=wjr54Mnx+F/yhi4EjDgNqotdGX3FOHVQ+4lVpp+UoyROpz2rWskkz/LBd+oWaiy1mt Z8+Y/IdDDlWq9vtfhDf2GzjXN+42QQNr0tXSI3GU+MzpEloe0cN5DCUBpNDwjPPiJ1Gv SxV9Ttxa6tj9vNibLm+ORSoUkFCzF2gXoECwokmeCFLJtIatR88ZvgoH+kd4tS6fcjEp 6yVa8VEdzeBU93xRpOQLSOsSVFf3m9HBw7mpOaDCyjGMyDNvfn/nGO96yWidJ7u864RC JgqHRZTg9YBgaYIbkVEL/DL5MpiFVDfv02YTS3/nuZ8TAJIjeDRe4FglFMSoubfw5jng yTAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jBeNywyu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si17375444pgm.271.2022.02.01.08.22.46; Tue, 01 Feb 2022 08:23:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jBeNywyu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239984AbiAaKfj (ORCPT + 99 others); Mon, 31 Jan 2022 05:35:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358234AbiAaKeQ (ORCPT ); Mon, 31 Jan 2022 05:34:16 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48019C06173B for ; Mon, 31 Jan 2022 02:34:16 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e130-20020a255088000000b006126feb051eso25994591ybb.18 for ; Mon, 31 Jan 2022 02:34:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=gQiXNhpWeE3w8plSrWyGvN1lrZy07A1L66IKLC7CKbA=; b=jBeNywyuEOrcXul646YOTEnDNkvf2B21oUP/1LvS6MfqUeLNbH4ecLDYPUWeYJBghY z3i5ILdvdOG+3+CnkALg8SHprnIucGpcnCQgkDxUIoyEtUk08H/S4biUQfAdMcF4RcDi rm6Tp4txIJN4G18FTdqFDJeQZMu2zGr5Kb72KOMCnErupl+0AsPpFtL/eUu+TekxggYV 8WHC9X3E3y8J3Sjg4TWSGzvFUP0F/8Gj/82MlWlodrZo4F++MQ8Y9k3vTM9BY5EPj0Aj 5dES73C/VqfnNoLUtMrRSADU3rAktKKtrGALulf1IYdQkDnW/POpci29EY4pLJrtmKCI Ovpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=gQiXNhpWeE3w8plSrWyGvN1lrZy07A1L66IKLC7CKbA=; b=vJy45Fjox/xVjhxo/iHBP2AnvnE66U2Wo69lQUsO5xjfPf9p1O4xfGGY08cxmCpG7q zEhjsgubipkduxYn/tkkuXPH0bfeNEMRtqlmWzbvRRx7brfy7T/wptmLFFlhP451eaf8 AaAk6RAvJ48UEX8o2gtY3UpNx2QZzhFcWn7G7AumYGudNPLhh0na0Bt0a+AFod0yl6Uy lzwSxn2SLeeI2Idlz/YEVPyhDhwASPtsPrKj7wFRL59BvZswIczA8N1lLK8jelgJ77fw reztXghBHstCbG2X7L3hEdsSB6ny8JAEmdfz/U9X5+sfqzXYgBCgteoLsnaKpAMHB0qp R5LA== X-Gm-Message-State: AOAM53346AGNfNWFJauuyngCZxYvGErQnjh9bRae08MTVb7HY+O6o+dm rVKwUDmtvdFt6Azjcm6CUQySov10Zw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:76:dcf3:95f9:db8b]) (user=elver job=sendgmr) by 2002:a81:6fc5:: with SMTP id k188mr1653ywc.507.1643625254572; Mon, 31 Jan 2022 02:34:14 -0800 (PST) Date: Mon, 31 Jan 2022 11:34:05 +0100 Message-Id: <20220131103407.1971678-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog Subject: [PATCH 1/3] perf: Copy perf_event_attr::sig_data on modification From: Marco Elver To: elver@google.com, Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Dmitry Vyukov , linux-perf-users@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events") Reported-by: Dmitry Vyukov Signed-off-by: Marco Elver --- kernel/events/core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index fc18664f49b0..db0d85a85f1b 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -3197,6 +3197,15 @@ static int perf_event_modify_breakpoint(struct perf_event *bp, return err; } +/* + * Copy event-type-independent attributes that may be modified. + */ +static void perf_event_modify_copy_attr(struct perf_event_attr *to, + const struct perf_event_attr *from) +{ + to->sig_data = from->sig_data; +} + static int perf_event_modify_attr(struct perf_event *event, struct perf_event_attr *attr) { @@ -3219,10 +3228,17 @@ static int perf_event_modify_attr(struct perf_event *event, WARN_ON_ONCE(event->ctx->parent_ctx); mutex_lock(&event->child_mutex); + /* + * Event-type-independent attributes must be copied before event-type + * modification, which will validate that final attributes match the + * source attributes after all relevant attributes have been copied. + */ + perf_event_modify_copy_attr(&event->attr, attr); err = func(event, attr); if (err) goto out; list_for_each_entry(child, &event->child_list, child_list) { + perf_event_modify_copy_attr(&child->attr, attr); err = func(child, attr); if (err) goto out; -- 2.35.0.rc2.247.g8bbb082509-goog