From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (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 4CB71321F2D for ; Wed, 24 Jun 2026 05:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782278171; cv=none; b=Rh7Tgc5BVMvh/QAVxEwPLEdNAvwpxMFsXJshwQdItlvTbrFrPfPQqoyjj5a4WoMWWkCKQAYP6wSYyH9FR62MJeeeQmcGFnKNyZpCbPk5ubmWUdPCz1C9n2fwKkZ2MX7BzR4BgXczSof+8nPZon0p3L64C2TiWTSqNHXjDWbrQ+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782278171; c=relaxed/simple; bh=5NSOfZxC9tZSZzh5nzx4J56ffxbdULsyGYFbtB+mfwA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QJ2nwlNYdEV/TzlYk27BiKmbNOiSVsGz1hklMGHGnvXOaJUP03lj45N6T3anux5CABs9ahvY8C4aDEWzOrrpW2E2RONUuutKLTTf+ojXWVRB4Sd+zBmXXm9WaN7eDn+P5+ONOWeuioIidD/fjk917i/rYbcI8GVSbfHJtODRI1s= 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=MeI6Qk39; arc=none smtp.client-ip=74.125.82.73 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="MeI6Qk39" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-139b62317d0so2509063c88.0 for ; Tue, 23 Jun 2026 22:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782278169; x=1782882969; 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=GVfnkNq1PIBmqGscS0ilZAevukokJ/LZeW/s+TEeeuo=; b=MeI6Qk39JwyHZmJaTlnOIrDUgdr1pOeViSikekaA4PxLts/NOWzUXoYtaGN5dnj3C6 PRvoaBiplWg5ff+E9yGSHdCX2ER4YE95CYY10owpEJzu2BVu1RABBBLn9/BTB2pP6NMo /LQdsiFI6VNPi1YMGNAsgEA5nGx1sElqlsLRF/5KTEP2BC/zLN6UM29nflrB4aJlRQS0 jD9UxfiM15A4fZQToKL49dG/YyIjx5Q+8J0DPBDZNRy+SlaNYdRBk03EXAJcEU+NAL9C kefcYm8bYLdgBa6nN4/rXYbbQlTZhqtOvtVG8pZnNFZahmAwvlCmFJJ1FbEXYfIHou6L fAgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782278169; x=1782882969; 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=GVfnkNq1PIBmqGscS0ilZAevukokJ/LZeW/s+TEeeuo=; b=ODi8UkzU8bqWsyF72GEu9FmHnDpxZkq2uBb2+2WhB8ZOv3T9tNScf7WnIWEIu/GvQB J8P3qDIsDUUITRtcs7m33RpEzc1qlzA3V9j6FsYTqY8FKMo4cJ3q8JzzNEsmGV/KbwTS CtRUXDYpin/K3gZ2cxqEKQKColwIOogXySqEjCyirvYglzVhd/81FuvsreLZEiG5KXa1 2LUeRlPPZMoYYNFL78k1dMxHKesNMVfNBSGBDI46uGzl2dP9M4RVxxGN+vXGB34YI7M/ dUToam8fJGJD4N6GESnZOK6FD05bgx9DLvQoxLzPG0wJCybog4zHFWRjwoVgUc6ubbro kagA== X-Forwarded-Encrypted: i=1; AFNElJ9MW6/xdRCxpVWb0MfxGMWqGwEjdreM0qziPN1gls/h3fkuBlrH3lr8AAjv8hxnsPqbniJbtz8shR9MHxg=@vger.kernel.org X-Gm-Message-State: AOJu0Yyzn+ea52TEj9Crb2owqWy35yWItWcv+AxxEJLwxktIcSA/ZXcv a7XxoWddvHhgdC7B43B9alMgcQk5F7nLtaZdPRZXkUxG9QT92PPW7Xs1yvohLTz6bP6Jw9Si1ie 55G8FcQA8PA== X-Received: from dlbqc12.prod.google.com ([2002:a05:7023:a8c:b0:139:c208:51f7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ec6:b0:136:4a60:43ce with SMTP id a92af1059eb24-139d0c1921bmr1579546c88.11.1782278169134; Tue, 23 Jun 2026 22:16:09 -0700 (PDT) Date: Tue, 23 Jun 2026 22:15:30 -0700 In-Reply-To: <20260624051535.3584977-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: <20260623053515.2677888-1-irogers@google.com> <20260624051535.3584977-1-irogers@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260624051535.3584977-14-irogers@google.com> Subject: [PATCH v2 12/16] perf python: Add thread and PMU uninitialized checks From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, alice.mei.rogers@gmail.com, dapeng1.mi@linux.intel.com, james.clark@linaro.org, leo.yan@linux.dev, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, tmricht@linux.ibm.com Content-Type: text/plain; charset="UTF-8" Add CHECK_INITIALIZED checks to the thread attribute getters (get_pid, get_tid, get_ppid) to prevent crashes if they are accessed before being properly initialized. Fixes: 3b96bf7af60d ("perf python: Add python session abstraction wrapping perf's session") Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 71be130b38c5..b17b191b1625 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1678,6 +1678,7 @@ static PyObject *pyrf_pmu__name(PyObject *self) { struct pyrf_pmu *ppmu = (void *)self; + CHECK_INITIALIZED(ppmu->pmu, "pmu"); return PyUnicode_FromString(ppmu->pmu->name); } @@ -1730,6 +1731,8 @@ static PyObject *pyrf_pmu__events(PyObject *self) PyObject *py_list = PyList_New(0); int ret; + CHECK_INITIALIZED(ppmu->pmu, "pmu"); + if (!py_list) return NULL; @@ -3758,21 +3761,25 @@ static PyMethodDef pyrf_thread__methods[] = { static PyObject *pyrf_thread__get_pid(struct pyrf_thread *pthread, void *closure __maybe_unused) { + CHECK_INITIALIZED(pthread->thread, "thread"); return PyLong_FromLong(thread__pid(pthread->thread)); } static PyObject *pyrf_thread__get_tid(struct pyrf_thread *pthread, void *closure __maybe_unused) { + CHECK_INITIALIZED(pthread->thread, "thread"); return PyLong_FromLong(thread__tid(pthread->thread)); } static PyObject *pyrf_thread__get_ppid(struct pyrf_thread *pthread, void *closure __maybe_unused) { + CHECK_INITIALIZED(pthread->thread, "thread"); return PyLong_FromLong(thread__ppid(pthread->thread)); } static PyObject *pyrf_thread__get_cpu(struct pyrf_thread *pthread, void *closure __maybe_unused) { + CHECK_INITIALIZED(pthread->thread, "thread"); return PyLong_FromLong(thread__cpu(pthread->thread)); } -- 2.55.0.rc0.799.gd6f94ed593-goog