From: I Hsin Cheng <richard120310@gmail.com>
To: mark.rutland@arm.com
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
namhyung@kernel.org, alexander.shishkin@linux.intel.com,
jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, jserv@ccns.ncku.edu.tw,
shuah@kernel.org, I Hsin Cheng <richard120310@gmail.com>
Subject: [RFC PATCH] perf/core: Prevent dereferencing NULL pointer
Date: Thu, 6 Feb 2025 03:06:08 +0800 [thread overview]
Message-ID: <20250205190608.93508-1-richard120310@gmail.com> (raw)
According to coverity scan check, there's possible cases where
"ring_buffer_get()" returns a NULL in "perf_mmap_close".
Use a "BUG_ON()" to check for NULL pointer existence, panic if it does
exist, otherwise it's safe to dereference "rb" and access its members.
The scan check report link is:
scan5.scan.coverity.com/#/project-view/63416/10063?selectedIssue=1636067
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
kernel/events/core.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index bcb09e011e9e..fe83d4754746 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6410,11 +6410,17 @@ static void perf_mmap_close(struct vm_area_struct *vma)
{
struct perf_event *event = vma->vm_file->private_data;
struct perf_buffer *rb = ring_buffer_get(event);
- struct user_struct *mmap_user = rb->mmap_user;
- int mmap_locked = rb->mmap_locked;
- unsigned long size = perf_data_size(rb);
+ struct user_struct *mmap_user;
+ int mmap_locked;
+ unsigned long size;
bool detach_rest = false;
+ BUG_ON(!rb);
+
+ mmap_user = rb->mmap_user;
+ mmap_locked = rb->mmap_locked;
+ size = perf_data_size(rb);
+
if (event->pmu->event_unmapped)
event->pmu->event_unmapped(event, vma->vm_mm);
--
2.43.0
next reply other threads:[~2025-02-05 19:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 19:06 I Hsin Cheng [this message]
2025-02-06 8:05 ` [RFC PATCH] perf/core: Prevent dereferencing NULL pointer Peter Zijlstra
2025-02-10 8:07 ` I Hsin Cheng
2025-02-10 8:36 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250205190608.93508-1-richard120310@gmail.com \
--to=richard120310@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).