From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796212756; b=m33Aw5nd+RUldUvPKuAbbEC61T0Im7iqNy8D9Zx6+lnQ6Qrk+OB+bob/QFZU2Iia+whT FLp4FYwzaxsGmKgXAqwcIgs4VpGdIQ2zxgg79SuZnbyRvekt1uXJkWZzBnoda4ss0Dr9I oXyPTAdzqte1DfrAlnhbASDO6G1Hz6r8r/LGIYNFk5WbV1EsrklOvreEecD0Qcr3Ojbo0 QeUEt/z8yBuumDhvhkpMybuL7LrONf86RLMfNaLaztZWYmqjD+FLnjKs3qyLjHqEfwEyj gwsnigDOxLnZZqzPy4EUNIkgz4SiPZabknqsBwTeX7HlB7cYQATPqOX+4XDxut0wwJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796212756; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=v2KGkgNUQsfFoicacyKjyU63w+TnA8NPqvP/XO0N1g0=; b=2v71WZBWWir+Q4fF3ZWAxDJ7b3GxTsyuF/8MA96xUcC3OI8KG01x52qCKPSvCC8Cwx4A Z9SfAYy9KJxncxGd11dUpfKY8rrbBKcB7sKuezy7WJSxnx0/HwCCiu81aQNsWzCIZ/YIF 306JvEqa/ndx0R86Vo71tqQNv6hzM6v/ziRrPTNoVTwULbMc6+yNRVpBIKYGwwjx04NhE ESunBawKLq8WrUgkzKnD+LbuSL+TdfK+81BQOiP4D+UGmfs5ipalqzZX8PmPT+Oav/t/Q LdVOtvM0CoOd9+dbP8f31rL0haIxw68O7sI+UDRk/gIDeG7GIpA/rTdb4eZ6JUweWJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Hhu1+lhM; arc=none smtp.remote-ip=209.85.215.179 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F703606A32D for ; Wed, 2 Dec 2026 11:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F703606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Hhu1+lhM Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-cc4be0e5351so8325996a12.0 for ; Wed, 02 Dec 2026 03:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796212756; x=1796817556; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=v2KGkgNUQsfFoicacyKjyU63w+TnA8NPqvP/XO0N1g0=; b=Hhu1+lhMxv8/JHwiAP/LJB8DTKiZgv/qMFSD0noC+IshW+UQjmpNF30Z/luFsHKHku LXrk+oXmiwA2q9xVFvYVa9iFBsQJ51LETQ8NTV0XJC1kOWPi/Gy6loHL5dWzkf1CNaIA k6TKD7GmTAXS9nnMOlF07wL7NPmVahtRqhoLOsMlKnY3f2ZV/glVKEjeWI723PqIPouc k7E0mYx0tB45i951ssAeuVQJma244MuHFgjCAJlHzoC0upyvhKaa3MCngp0Qz9wKIthi zekCk3Ps1a7ECu0BuGV9PQ8ragxweuQVjDlW89nTJeiL4Zir8FON5ylkydaqDRyVmejC T1jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796212756; x=1796817556; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=v2KGkgNUQsfFoicacyKjyU63w+TnA8NPqvP/XO0N1g0=; b=qGPQa3/pDkrm6wySXmgvYrSvG2+DyromL330qOZbldFFPhz7DYVKb7MQnfdcMfpzH5 BEu3EEy/owtKlSmVwSGefKKbMrzNl+MKsLfhYJ3YIru30Eb0wIwXWzn1b31QNGlLbsYv 7A2n2F18WfdYMjxkFd5gPVVmgB2wPtsYl60NuU9rnZfDko87nTLLhGKinBUC6GxiwFAE 4CQP5mgAXKaP+6l5hxWUKaHi8C+1cZaW4JfvNZT0nrVAgk4QXZAz++Yg8pAJTqlhUE4m +zYy10WtBCDpP/sm4FpLfT1HV5dfUpsVChBtCVNpWoflGpENHW0CeHBGApFc/73pltpW 4PTg== X-Forwarded-Encrypted: i=1; AL+hErH9Smdk7wf7RJF1tVd9ymNh+YF+RGF9OZ9cpmT7vfOCD5J3ejTKSWzLGA5++OwxF6UeE3g0DyvqsICPmwU7SjVm@vger.kernel.org X-Gm-Message-State: APuU4Z8kRPreX717npobch4ME238EeKv03KBmPFBiPW5R5IZsgzO/sCZ IXnp3pPR+pylmMGkVq3WtfmetkkHtxnztVgwphDaE01uq//CicwrRyj2 X-Gm-Gg: AZFdTZcWX0xeWL7OnLf+7Zq7CrDf6i3+ll3955PZvhITnmR7Ud9gD9xrBvTUJy7VVmG v8HfIIpuAXVe4qQzNq61Jv0Mvdz/1vDVyJk2+Ay7iq8j4LVkjBW2J0hMQUHhe4D7+uSDQ+iv0yk swZmSWvOTg+6JzRQVxbVU8WCXzcfoa36qfskBP3dn344eLREjKhONgQt1g3yNbTngsO5SJzjX7b Zxn63YBfgGo4kcAw9W+ibRTtSJO33aOGBukSJYLbMqZtdefc0+NFSSHvDcY3GVjusLkSTI6Re8g VQIC5jAiMTsCrxnU13wWPBqq5fM+hqdoktXYlfUqiiDp1hTs0pUkMo2FWGItZCZTDQyh8dwkgDg uAeJJWz2Vrl3d0QeKv2lxZyza7BaNLxVYjqP0Sv9xL4fwx2XRWIN7Y0VuHNPm9JZ0rpxai0u1O+ G3S34s8ATp0ZJrVMfMbq+WU+xEsQI4sJkpASpdALqrhMbxNl9XqU6fhka/qztkpl8T0LI1Ic+OU FhxRVnPwBYtmbuAi36IyPfxiuBz2lKDXifA6Wr3SMVX9Gdu1fzMHYOsqUPlhNo2QLdcpRgo2NbJ vn7cxpeKnhQYb2bGGic6/EHFew+Tf6kC5DlsRRPIiIjNeavuyXwlnWUQ X-Received: by 2002:a05:6300:8095:b0:3f9:f95a:7416 with SMTP id adf61e73a8af0-4014c2519a5mr36205643637.57.1796212755628; Wed, 02 Dec 2026 03:59:15 -0800 (PST) Received: from Desktop ([182.161.246.158]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6d03adafsm22410362a12.23.2026.12.02.03.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 03:59:15 -0800 (PST) From: JunYoung Lee To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, james.clark@linaro.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, JunYoung Lee , stable@vger.kernel.org Subject: [PATCH v2 1/2] perf/core: Don't report a kernel IP for exclude_kernel events Date: Wed, 2 Dec 2026 20:59:01 +0900 Message-ID: <20261202115902.586760-2-ljyoung04@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202115902.586760-1-ljyoung04@gmail.com> References: <20261202115902.586760-1-ljyoung04@gmail.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit perf_instruction_pointer() hides the IP of an exclude_kernel event only when the sampled frame is not in user mode. A user mode frame can still carry a kernel IP: a data breakpoint on the memory operand of an indirect "jmp *mem" traps after the jump, so the user mode trap frame holds the kernel jump target. PERF_SAMPLE_CODE_PAGE_SIZE then reports the page size of that kernel address, which lets an unprivileged user find the kernel image and the direct map despite KASLR. Also return 0 when the IP is a kernel address. The problem was found with the help of an AI coding assistant (Claude). Fixes: 995f088efebe ("perf/core: Add support for PERF_SAMPLE_CODE_PAGE_SIZE") Cc: stable@vger.kernel.org Signed-off-by: JunYoung Lee --- Changes in v2: - Filter the kernel IP in perf_instruction_pointer() instead of in perf_get_page_size() (Peter). - Move the bad pmd fix to its own patch, 2/2 (Peter). - Shorten the changelog. Tested on 693c2e04e3f1 with the kernelCTF LTS config, KASLR on, in a KVM guest on an AMD host, as uid 65534 with perf_event_paranoid=2: - Kernel addresses: samples now carry ip=0 and code_page_size=0, and a scan of the kernel image and direct map windows finds nothing. - User addresses: IP and page size unchanged. - cpu-clock with exclude_kernel: all 7390 samples have a user IP and 4K. - exclude_kernel=0 as root: _stext still reports 2M. Kernels without the generic perf_instruction_pointer() (for example v6.12.y) need the same check where perf_prepare_sample() sets data->ip. kernel/events/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 4ab3919ac..4c7f173d7 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7858,6 +7858,8 @@ unsigned long perf_misc_flags(struct perf_event *event, unsigned long perf_instruction_pointer(struct perf_event *event, struct pt_regs *regs) { + unsigned long ip; + /* * Hardware skid can lead to a scenario where a PMI is * delivered after the CPU has already entered kernel mode. @@ -7870,8 +7872,18 @@ unsigned long perf_instruction_pointer(struct perf_event *event, 0 : perf_guest_get_ip(); } - return event->attr.exclude_kernel && !user_mode(regs) ? - 0 : perf_arch_instruction_pointer(regs); + ip = perf_arch_instruction_pointer(regs); + + /* + * A user mode frame can still carry a kernel IP, for example when a + * debug trap is taken right after a jump to a kernel address, before + * the instruction fetch faults. + */ + if (event->attr.exclude_kernel && + (!user_mode(regs) || ip >= TASK_SIZE_MAX)) + return 0; + + return ip; } u64 __weak perf_reg_value(struct pt_regs *regs, int idx) base-commit: 693c2e04e3f1d4c59af236e1211b7b8cb165a790 -- 2.56.1