From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 4754B33FE2F for ; Sat, 11 Apr 2026 06:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775890701; cv=none; b=LuiebB1lb+g3Z/lkAtx9Ii/KaHDrGMQmd+hd+IISzYNd1aMF20QjFynYDgnfr8RwdGIIsqWB7ThA3Yzb16/TZn+j0gcPOmKeW/Ji0buN8qVOJGJ5JZCLM7G6Mt8iJmzZ5bl7g/cRwifD/u2ZJJMoiqKqTnJjHxEDEvHUEITBKr0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775890701; c=relaxed/simple; bh=TORHr2hwj56t1K+9uUsjLQo6KHkuVY+QoSlV3b0luUk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lY/c9ORjQbsDjJsQDN14QpRcMa/DmoRhDSepkcfu3Vx9Di04O6K4YoORLyE8Bpe1QyhlJjZxNrDApQFxhSry/2vQnzOzeKSEWiu7bPI48YZknqQHvB9kuJBUf8BFXzUx9BMNNiTAyvp9AJ4PjzbR5GeSGcLSTF7OKjirH/X0vH8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ku2Zr54G; arc=none smtp.client-ip=74.125.82.74 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ku2Zr54G" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12737f276a2so13499923c88.1 for ; Fri, 10 Apr 2026 23:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775890699; x=1776495499; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hQS4P5hyltqhKwRzLCXyq1MWFkkdWjplTUZAMK0ialE=; b=ku2Zr54G7Xhx/PQYEYHNz0TGtn7tQwtjzZaM+4w4sBfNBqVFwaS6gpYGJUR0fS2yDZ RPePPbDUYTNsGwxGQ51EmJHtnWXWgY11KluTvCIfqphmj6s8dqPyPRt7ypCjPKJmJcvQ f8aqsk710wLUl1FTyiZkuhy5yddBR4AvdY+wJv+jWkXI1WF4E70re9faTWirQQ/GclEX yYkm8rSy1BLUCJ5dncZj69I8EsAqhKtf2+QEZldxMNrNIINoMdIOd7t7E3wxRGoEwC1R Fck9tPFZAUAOUuhwjIcjp3qXGTrIe3hc2qf2SVI14kGijEdF7ZAVvkRaVSMV5Mep/6jY umXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775890699; x=1776495499; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hQS4P5hyltqhKwRzLCXyq1MWFkkdWjplTUZAMK0ialE=; b=saWCuxknYgh/++VRnLJIbBE7yAye5NF95XaKbK7P/oziDyqYhuUvB5ohKUQI/tO7U4 GLNOyWjZbiz321CyuA2jfKN5uienc8bArNDFoNmjx91rTox5C5wejeAAn3ZaJFqc4Pli mRjHGzJEE0TyZlPQc736wjFX6kvgt7mPlluLFnQonDQ7bhs4fjWbQhGBGOVnXFoQ/mWj tOmjuJXqC3tMwoZe9vRBCLNY2TGbJQr7TPMumIl/I4ehQq+yCs3zQuJUuLCzIbK5wHI0 2T/TGRU3YGXNRGZbXfuwCULYRCeUy/bP6crAIqNEDn/1EpD3zqJSUGjU+2f1yiYsUXkz 75LQ== X-Forwarded-Encrypted: i=1; AJvYcCWJ8sGb0XoFP2+lW2Xw+D8vXC8IXsoCUG8wwyJKFEgFDIUqThqw7ZYvswMX/wDpCON0aRpuK7ufk1XH3UA=@vger.kernel.org X-Gm-Message-State: AOJu0YxeFwh2avwWxcwOKdQweZyM0SXcif+eRyEPaJDn+y6UMpcMS6OY b2lobInCbHIEx8KwlIvM/qxyWAXk3HvsgQxvKARrGmLmNMJWOjXfGhr9FDLEs9k1XKDTywu/gr2 PRSiTo61Zpw== X-Received: from dlaf2.prod.google.com ([2002:a05:701b:2402:b0:128:cff2:6560]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:68d:b0:12c:33dd:fa15 with SMTP id a92af1059eb24-12c34ef1940mr3545599c88.34.1775890699174; Fri, 10 Apr 2026 23:58:19 -0700 (PDT) Date: Fri, 10 Apr 2026 23:57:13 -0700 In-Reply-To: <20260411065718.372240-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260408072601.210837-1-irogers@google.com> <20260411065718.372240-1-irogers@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260411065718.372240-25-irogers@google.com> Subject: [PATCH v8 24/29] perf kmem: Add bounds checks to tracepoint read values From: Ian Rogers To: namhyung@kernel.org Cc: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com, ajones@ventanamicro.com, ak@linux.intel.com, alex@ghiti.fr, alexander.shishkin@linux.intel.com, anup@brainfault.org, aou@eecs.berkeley.edu, atrajeev@linux.ibm.com, blakejones@google.com, ctshao@google.com, dapeng1.mi@linux.intel.com, derek.foreman@collabora.com, dvyukov@google.com, howardchu95@gmail.com, hrishikesh123s@gmail.com, james.clark@linaro.org, jolsa@kernel.org, krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux@treblig.org, mingo@redhat.com, nichen@iscas.ac.cn, palmer@dabbelt.com, peterz@infradead.org, pjw@kernel.org, ravi.bangoria@amd.com, swapnil.sapkal@amd.com, tanze@kylinos.cn, thomas.falcon@intel.com, tianyou.li@intel.com, yujie.liu@intel.com, zhouquan@iscas.ac.cn Content-Type: text/plain; charset="UTF-8" Avoid out-of-bound memory accesses by bound checking order and migrate_type when coming from page_alloc_event and page_free_event. Signed-off-by: Ian Rogers --- tools/perf/builtin-kmem.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index daf2272c7337..33585e353efe 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -826,6 +826,16 @@ static int evsel__process_page_alloc_event(struct perf_sample *sample) .migrate_type = migrate_type, }; + if (order >= MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + + if (migrate_type >= MAX_MIGRATE_TYPES) { + pr_debug("Out-of-bounds migratetype %u\n", migrate_type); + return -1; + } + if (use_pfn) page = perf_sample__intval(sample, "pfn"); else @@ -892,6 +902,11 @@ static int evsel__process_page_free_event(struct perf_sample *sample) .order = order, }; + if (order >= MAX_PAGE_ORDER) { + pr_debug("Out-of-bounds order %u\n", order); + return -1; + } + if (use_pfn) page = perf_sample__intval(sample, "pfn"); else -- 2.53.0.1213.gd9a14994de-goog