From: Peter Zijlstra <peterz@infradead.org>
To: I Hsin Cheng <richard120310@gmail.com>
Cc: mark.rutland@arm.com, 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
Subject: Re: [RFC PATCH] perf/core: Prevent dereferencing NULL pointer
Date: Mon, 10 Feb 2025 09:36:48 +0100 [thread overview]
Message-ID: <20250210083648.GB10324@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <Z6mz1A804NXZpFm-@vaxr-BM6660-BM6360>
On Mon, Feb 10, 2025 at 04:07:48PM +0800, I Hsin Cheng wrote:
> On Thu, Feb 06, 2025 at 09:05:20AM +0100, Peter Zijlstra wrote:
> > On Thu, Feb 06, 2025 at 03:06:08AM +0800, I Hsin Cheng wrote:
> > > According to coverity scan check, there's possible cases where
> > > "ring_buffer_get()" returns a NULL in "perf_mmap_close".
> >
> > That makes no sense. Having a mmap should pin the buffer.
> >
> > > 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.
> >
> > How the hell is a BUG_ON() any better than a NULL deref?
> >
>
> Hi Peter,
>
> Thanks for the review ! I get it so I think this issue reported by
> coverity scan should be marked as false positive or disgard.
>
> > That makes no sense. Having a mmap should pin the buffer.
>
> I see, so if I understand correctly, the "event" in perf_mmap_close()
> is guaranteed to have available buffer and the buffer's refcount is
> zero, so returning a NULL will never happen right?
Right, the vma / mapping has a refcount on the event, the event has a
refcount on the buffer, and event->mmap_count is incremented, which
makes sure event->rb isn't changd.
So yes, at the time of perf_mmap_close() it *should* be impossible for
ring_buffer_get() to return NULL.
prev parent reply other threads:[~2025-02-10 8:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 19:06 I Hsin Cheng
2025-02-06 8:05 ` Peter Zijlstra
2025-02-10 8:07 ` I Hsin Cheng
2025-02-10 8:36 ` Peter Zijlstra [this message]
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=20250210083648.GB10324@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--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=richard120310@gmail.com \
--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
all inboxes | Powered by JetHome®