Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp710365lqo; Fri, 10 May 2024 12:16:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWS3ndDkejnvBxPtnH6QBaaeFexRkkIAuB6xYjvKKcwPNh+zFWrGbCcuntE8h3shzqkVhExWCwEgvtHPEGpL6EZkP1OCeGMi+pKMnCAnQ== X-Google-Smtp-Source: AGHT+IHYUmjzxBgzw6MYHadOC1Pk6PYLkhHdkOxk92ASfe/kHAoCci6VIwjgUjwOeaBqfXw9NSao X-Received: by 2002:a05:6a20:5a96:b0:1a9:c4ca:dc74 with SMTP id adf61e73a8af0-1afde0a9bf7mr3716212637.5.1715368594355; Fri, 10 May 2024 12:16:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715368594; cv=pass; d=google.com; s=arc-20160816; b=qpyFDWsv9xOUVMRTDOpNug3msXLyrp4vy4hHhvYHRKURfumeNQeo6lsGhlhUdBd+zL DP0pyEt+J0082NcmwB4fxqCcoWHUNbGijfsvG3zorLLDoXHKUZQjzIoa60xPaWOuRenW kp5JVEC/medCD9IfUObNJLV3Z5gAWuaQ0zc2SWwmznqBlvBMxL70zqY/p+DvZ0SPOWVV yopo4QrjIWD7C8vh8dUM7uhTr8xCCGg5POkEzOzBYzRsVUoz5L2VWeGGg3u/pz3WEGuo OYBuFRH6uFRn64Az7AHTNCFN8Vz5HRL7LqGQFrwVXY/BWDLz6JclYM45GRIVS/wnxIUX 9ppw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=EylM3vFA7lZulI4V1G3R5cUfH0kthc6cGsP9Vyzx3vo=; fh=7w60JlPuMWVQYdmgc61sLC1E88gfVKgdcjr48POpGsU=; b=Jhbix1jW14plHLaHTtcA12pPVG3pBrE8oj+OV/heZIlHtYDvGBH5q/7GgYkOsq8075 8ygBlmeZKxJrAxv4iwC8+xyVyspnYe8m6vp49MBAYcSJR1X079BG8QqI/BDLL1CwjcqD SG1TmFpsNFCHFu0VpebCo2M/dmjAghmCJgdFTc07Dn2MIBPKDHdP/jKNNXoblV7S/SO8 5j/THIG3PXy4kXn/2r+TD14DmHkJpCGB1nKvUS+guGD/0zMVfxqjO5yBrZDm4VF0q9Ee 8y7/UVrUl0jlrZM6d8nDaiOYt9F7vC8ZSYBwlpntpsccO4jp3aXOCIWN5/mlntfIDFQB DPPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XFlNaoYV; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-176132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2aeee1csi4205930b3a.188.2024.05.10.12.16.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 12:16:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XFlNaoYV; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-176132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F3D59B24F9F for ; Fri, 10 May 2024 19:14:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F1DED481A5; Fri, 10 May 2024 19:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XFlNaoYV" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC6D645034 for ; Fri, 10 May 2024 19:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715368481; cv=none; b=fwhhUKqEJwBPGREX2ibklqItihtweZOLKuY7yOZUkppcanC3n8LTLiINbgKdp+RGzSlian91OBEt65uDgbcltjNKP7Kq7WHrWHDztktGLqrwAIFSQe1WK7AypDF6atj1yfR2QFRSTjb3OYI8NE6nJvd4gExiLl/haDRFxjUN+Ao= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715368481; c=relaxed/simple; bh=lM7Ffa7a34WiHH98qjX1e31MHrDcWjJyEDQyUEnhRS8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=B6IFp5//YuQM3e4swtz7Ic1RGL7kwYdmaY0YpLVQLQEAhAzRajk7nhYDOayHsT2vlRQJP/1rkbndSffsoIFfdaibQU7vD0VJBaLwllvWg0vROXUM8+OmzMvHJzQA7hdiG0NNUCXCapfq8eg42QILRI20lsiLq68ReIN/VdPMKPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=XFlNaoYV; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6ceade361so4897461276.0 for ; Fri, 10 May 2024 12:14:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715368479; x=1715973279; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=EylM3vFA7lZulI4V1G3R5cUfH0kthc6cGsP9Vyzx3vo=; b=XFlNaoYVzX9GjKEIbuq5Fy7cLywGJafcvsi6kKz8WNpklVpqdYtAGqbO7N4prS0sNF XT4jN1+sRE+cwCeEVllNgQ2l83OR6DFtFiirFfVig9DU/iqPll339FfWKhPL/BMlmFky ccskUr0N7ZHPkrl/ILuMx0WJ6VrCmpIVjDEh/+/M8pQB38gcDBsHPPbzGvbreqnu1tMN OlEgCZjxSbDRzcv8VRo91CN0RH/6POcJKkkdHvI31afQL0/doGUQN/pe7uIpqjsH++TI CpVCE96lXXbgfBXY4lRGrFe9D29yS0myaczzhUR3w9jJC/qOkBHBEeyhn1BWBZU8cE7v noPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715368479; x=1715973279; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EylM3vFA7lZulI4V1G3R5cUfH0kthc6cGsP9Vyzx3vo=; b=bB2X9HV6MpubHDwBhV/tCMr1STRbryCN/lVW5oAN908Eq1wWShME7jnp575c9+7Oaf H+l5KUbNHAm1DswDfXCd+Y6G9SN2jMuaqATpaVkaMykRPvCK2Dh3N/e+Qp0EStC3MJ1O waJOpc+bXCMrYBeBZr7OCUkrnZQEQFizy8k6deusSXBpEuVAZph7J3p4/+IcM6GUsku2 JiA1I3Pf7EpnalSQuJqMQuy7UVV3uV1bASCXLzv0/0Rd3ruyd37rmMLjDEwRYHfB9yvp t/pQQj76ftazHTWO6AEZmmQw26hrkNVWpT8nTNBxs6QvE7lR6QYruminuvmMfrGxcRn1 sRPA== X-Forwarded-Encrypted: i=1; AJvYcCU7XktLF4/gIFPa6X9az1Ln+lzT9dPuCztBdsVWmPfl/hv482DJ9VTAKhtQPCOso40jfyTOSk6YBk6gm9xJD7Q3kudJ0bMrSINKNjzb X-Gm-Message-State: AOJu0YySeBl3/eSpj5OCuRsZfqaPHnLDGKhWpFz9RMpNHXWzQmHHFa+R cG7sE88MSFbxLnZJTIySYQaI2byAYA7hedTDNragkGowd22FvsOlAbZo6cV1WBJJWC3Dywu8cGD l X-Received: from yabinc-desktop.mtv.corp.google.com ([2620:15c:211:202:d3a5:c745:caa1:83ed]) (user=yabinc job=sendgmr) by 2002:a05:6902:110e:b0:dcc:f01f:65e1 with SMTP id 3f1490d57ef6-dee4f506107mr928748276.8.1715368478676; Fri, 10 May 2024 12:14:38 -0700 (PDT) Date: Fri, 10 May 2024 12:14:20 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510191423.2297538-1-yabinc@google.com> Subject: [PATCH v4 0/3] perf/core: Check sample_type in sample data saving helper functions From: Yabin Cui To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Hello, We use helper functions to save raw data, callchain and branch stack in perf_sample_data. These functions update perf_sample_data->dyn_size without checking event->attr.sample_type, which may result in unused space allocated in sample records. To prevent this from happening, this patchset enforces checking sample_type of an event in these helper functions. Thanks, Yabin Changes since v1: - Check event->attr.sample_type & PERF_SAMPLE_RAW before calling perf_sample_save_raw_data(). - Subject has been changed to reflect the change of solution. Changes since v2: - Move sample_type check into perf_sample_save_raw_data(). - (New patch) Move sample_type check into perf_sample_save_callchain(). - (New patch) Move sample_type check into perf_sample_save_brstack(). Changes since v3: - Fix -Werror=implicit-function-declaration by moving has_branch_stack(). Original commit message from v1: perf/core: Trim dyn_size if raw data is absent Original commit message from v2/v3: perf/core: Save raw sample data conditionally based on sample type Yabin Cui (3): perf/core: Save raw sample data conditionally based on sample type perf/core: Check sample_type in perf_sample_save_callchain perf/core: Check sample_type in perf_sample_save_brstack arch/s390/kernel/perf_cpum_cf.c | 2 +- arch/s390/kernel/perf_pai_crypto.c | 2 +- arch/s390/kernel/perf_pai_ext.c | 2 +- arch/x86/events/amd/core.c | 3 +-- arch/x86/events/amd/ibs.c | 5 ++--- arch/x86/events/core.c | 3 +-- arch/x86/events/intel/ds.c | 9 +++----- include/linux/perf_event.h | 20 ++++++++++++----- kernel/events/core.c | 35 +++++++++++++++--------------- kernel/trace/bpf_trace.c | 11 +++++----- 10 files changed, 49 insertions(+), 43 deletions(-) -- 2.45.0.118.g7fe29c98d7-goog