Re: [PATCH 1/3] tracing/filter: degrade addr in filter_pred_string() from double pointer to pointer

From: Pingfan Liu
Date: Sun Jan 09 2022 - 21:58:20 EST


On Fri, Jan 07, 2022 at 12:18:42PM -0500, Steven Rostedt wrote:
> On Fri, 7 Jan 2022 12:49:49 +0800
> Pingfan Liu <kernelfans@xxxxxxxxx> wrote:
>
> > Since FILTER_PTR_STRING has the type of "char *", it is meaningless to
> > convert it to "char **". Hence degrading addr from double pointer to
> > single.
> >
> > Signed-off-by: Pingfan Liu <kernelfans@xxxxxxxxx>
> > Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
> > Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> > To: linux-kernel@xxxxxxxxxxxxxxx
> > ---
> > kernel/trace/trace_events_filter.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> > index c9124038b140..264456e1698f 100644
> > --- a/kernel/trace/trace_events_filter.c
> > +++ b/kernel/trace/trace_events_filter.c
> > @@ -670,11 +670,11 @@ static int filter_pred_string(struct filter_pred *pred, void *event)
> > /* Filter predicate for char * pointers */
> > static int filter_pred_pchar(struct filter_pred *pred, void *event)
> > {
> > - char **addr = (char **)(event + pred->offset);
> > + char *addr = (char *)(event + pred->offset);
>
> This doesn't look right. The address of the pointer should be in the event.
> "event" is an address to the content of the event in the kernel ring buffer.
>
> event + pred->offset
>
> Is then the address of position of the event.
>
> Let's say we have an event record at 0xffff8000, and the pred->offset is at
> 0x10. And the pointer to the string (in user space) is at 0x70008000.
>
> 0xffff8000: <heade>
> 0xffff8010: 0x70008000
>
> 0x70008000: "user space sting"
>
> event + pred->offset gives us 0xffff8010
>
> If we now have that as char *addr, then addr is 0xffff8010
>
>
> > int cmp, match;
> > - int len = strlen(*addr) + 1; /* including tailing '\0' */
> > + int len = strlen(addr) + 1; /* including tailing '\0' */
>
> This would give us the addr = 0xffff8010, which is not where the string
> exists.
>
> How would this work?
>
No, it can not work.


Thanks,

Pingfan