linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: mhiramat@kernel.org, corbet@lwn.net, shuah@kernel.org,
	linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 tracing 3/6] tracing: support IPv6 filter predicates
Date: Fri, 9 Jun 2023 17:15:46 -0400	[thread overview]
Message-ID: <20230609171546.4bd8097f@gandalf.local.home> (raw)
In-Reply-To: <20230609171227.56dc45b6@gandalf.local.home>

On Fri, 9 Jun 2023 17:12:27 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> > +		while (isalnum(str[i]) || str[i] == ':') {
> > +			switch (str[i]) {
> > +			case ':':
> > +				i++;
> > +				/* mark "::" index by setting gap */
> > +				if (str[i] == ':') {
> > +					gap = index;
> > +					gap_count++;
> > +					i++;
> > +				}
> > +				if (gap_count > 1) {
> > +					parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP,
> > +						    pos + s);
> > +					goto err_free;
> > +				}
> > +				break;
> > +			default:
> > +				if (sscanf(&str[i], "%hx", &tmp_v6addr[index]) != 1) {
> > +					parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP,
> > +						    pos + s);
> > +					goto err_free;
> > +				}
> > +				index++;
> > +				while (isalnum(str[i]))
> > +					i++;
> > +				break;

There should also be a lot more checks here where the input coming in is
correct. It also accepted:

 "123456789abcdef0" as "def0", where I expected it to fail.

-- Steve


> > +			}
> > +		}  
> 
> There appears to be no limit to the above loop. I panic'd my machine with:
> 
>  # echo 'saddr_v6 == 0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef:0123:4567:89ab:cdef' > /sys/kernel/tracing/events/sock/inet_sk_error_report/filter
> 
> -- Steve
> 
> > +		/* The gap_size here represents the number of u16s the "::"
> > +		 * represents; for ::1 the gap size is 7, for feed::face
> > +		 * it is 6, etc.
> > +		 */
> > +		gap_size = 8 - index;
> > +		index = 0;
> > +		for (j = 0; j < 8; ) {
> > +			if (gap_size > 0 && j == gap) {
> > +				j += gap_size;
> > +			} else {
> > +#ifdef __BIG_ENDIAN
> > +				v6addr[j++] = tmp_v6addr[index];
> > +#else
> > +				v6addr[j++] = ((tmp_v6addr[index] & 0xff) << 8) +
> > +					      ((tmp_v6addr[index] & 0xff00) >> 8);
> > +#endif
> > +				index++;
> > +			}
> > +		}
> > +		pred_val = kzalloc(field->size, GFP_KERNEL);
> > +		memcpy(pred_val, v6addr, field->size);
> > +		pred->val = (u64)pred_val;
> > +		pred->fn_num = FILTER_PRED_FN_MEMCMP;
> > +		if (pred->op == OP_NE)
> > +			pred->not = 1;
> > +
> >  	} else if (str[i] == '0' && tolower(str[i + 1]) == 'x' &&
> >  		   field->size > 8) {
> >  		/* For sizes > 8 bytes, we store hex bytes for comparison;  


  reply	other threads:[~2023-06-09 21:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 15:34 [PATCH v2 tracing 0/6] tracing: additional filter predicates Alan Maguire
2023-04-28 15:34 ` [PATCH v2 tracing 1/6] tracing: support > 8 byte array " Alan Maguire
2023-04-28 15:34 ` [PATCH v2 tracing 2/6] tracing: support IPv4 address filter predicate Alan Maguire
2023-04-28 15:34 ` [PATCH v2 tracing 3/6] tracing: support IPv6 filter predicates Alan Maguire
2023-06-09 21:12   ` Steven Rostedt
2023-06-09 21:15     ` Steven Rostedt [this message]
2023-04-28 15:34 ` [PATCH v2 tracing 4/6] tracing: support MAC address " Alan Maguire
2023-04-28 15:34 ` [PATCH v2 tracing 5/6] selftests/ftrace: add test coverage for " Alan Maguire
2023-04-28 15:34 ` [PATCH v2 tracing 6/6] tracing: document IPv4, IPv6, MAC address and > 8 byte numeric filtering support Alan Maguire

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=20230609171546.4bd8097f@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=alan.maguire@oracle.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.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).