From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Naveen N Rao <naveen@kernel.org>,
Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
"David S. Miller" <davem@davemloft.net>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Jinjie Ruan <ruanjinjie@huawei.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, patches@lists.linux.dev
Subject: Re: [PATCH 1/2] kprobes: Fix __get_insn_slot() after __counted_by annotation
Date: Fri, 1 Nov 2024 10:53:06 +0900 [thread overview]
Message-ID: <20241101105306.d198e543f9b60270cdcd570c@kernel.org> (raw)
In-Reply-To: <20241031033731.GA2553234@thelio-3990X>
On Wed, 30 Oct 2024 20:37:31 -0700
Nathan Chancellor <nathan@kernel.org> wrote:
> On Thu, Oct 31, 2024 at 10:58:27AM +0900, Masami Hiramatsu wrote:
> > On Wed, 30 Oct 2024 09:14:48 -0700
> > Nathan Chancellor <nathan@kernel.org> wrote:
> >
> > > Commit 0888460c9050 ("kprobes: Annotate structs with __counted_by()")
> > > added a __counted_by annotation without adjusting the code for the
> > > __counted_by requirements, resulting in a panic when UBSAN_BOUNDS and
> > > FORTIFY_SOURCE are enabled:
> > >
> > > | memset: detected buffer overflow: 512 byte write of buffer size 0
> > > | WARNING: CPU: 0 PID: 1 at lib/string_helpers.c:1032 __fortify_report+0x64/0x80
> > > | Call Trace:
> > > | __fortify_report+0x60/0x80 (unreliable)
> > > | __fortify_panic+0x18/0x1c
> > > | __get_insn_slot+0x33c/0x340
> > >
> > > __counted_by requires that the counter be set before accessing the
> > > flexible array but ->nused is not set until after ->slot_used is
> > > accessed via memset(). Even if the current ->nused assignment were moved
> > > up before memset(), the value of 1 would be incorrect because the entire
> > > array is being accessed, not just one element.
> >
> > Ah, I think I misunderstood the __counted_by(). If so, ->nused can be
> > smaller than the accessing element of slot_used[]. I should revert it.
> > The accessing index and ->nused should have no relationship.
> >
> > for example, slots_per_page(c) is 10, and 10 kprobes are registered
> > and then, the 1st and 2nd kprobes are unregistered. At this moment,
> > ->nused is 8 but slot_used[9] is still used. To unregister this 10th
> > kprobe, we have to access slot_used[9].
>
> Ah, I totally missed that bit of the code, sorry about that. Thanks for
> the explanation!
>
> > So let's just revert the commit 0888460c9050.
>
> Reverting that change sounds totally reasonable to me based on the
> above. Will you take care of that?
Yeah, probes/for-next is a working branch. So I just dropped it.
>
> For what it's worth, I think patch #2 should still be applicable, if you
> are okay with that one.
Yes, other patches look good to me.
Thank you,
>
> Cheers,
> Nathan
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-11-01 1:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 16:14 [PATCH 0/2] kprobes: Adjustments for __counted_by addition Nathan Chancellor
2024-10-30 16:14 ` [PATCH 1/2] kprobes: Fix __get_insn_slot() after __counted_by annotation Nathan Chancellor
2024-10-31 1:58 ` Masami Hiramatsu
2024-10-31 3:37 ` Nathan Chancellor
2024-11-01 1:53 ` Masami Hiramatsu [this message]
2024-10-30 16:14 ` [PATCH 2/2] kprobes: Use struct_size() in __get_insn_slot() Nathan Chancellor
2024-10-31 1:58 ` Masami Hiramatsu
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=20241101105306.d198e543f9b60270cdcd570c@kernel.org \
--to=mhiramat@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=davem@davemloft.net \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=naveen@kernel.org \
--cc=patches@lists.linux.dev \
--cc=ruanjinjie@huawei.com \
/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).