mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: peterz@infradead.org, andi@firstfloor.org
Cc: tj@kernel.org, srostedt@redhat.com, linux@horizon.com,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC] globmatch() helper function
Date: Wed, 17 Dec 2008 11:04:17 -0500	[thread overview]
Message-ID: <20081217160417.18507.qmail@science.horizon.com> (raw)
In-Reply-To: <1229526942.9487.75.camel@twins>

Peter Zijlstra <peterz@infradead.org> wrote:
> ftrace has a globbing thing in there somewhere as well and that does
> indeed take user input.

Yes, but (I just looked at the code), its patterns take the form:
- Optional leading *
- Literal text
- Optional trailing *

Thus, only one case (*literal*) requires any backtracking, and it's
just strstr().

> Using recursion in kernel code is indeed not recommended, what Andi said
> we have tiny stacks.

The stack frame is tiny, and it only recurses on a *, so if the number
of *s in the pattern is bounded, the stack usage is bounded.

For the intended application (compile-time constant device blacklists),
this is not a problem at all.  Indeed, nothing but a trailing * is even
needed; I only implemented the feature to be compatible with fnmatch().
(Which is part of the reason I'm reluctant to do anything heroic to
make it work.)

The problem is, what if some future thoughtless person feeds user data
into the pattern argument?

I could just take support for non-trailing * out entirely.  That would be
a different sort of documentation burden.

Or I could just add an explicit 2-level stack. If you overflow the stack,
matching always fails.  Unfortunately, the code will be larger.

Do people think that would be, on balance, better?  It would be plenty
good enough for the blacklist application.

  parent reply	other threads:[~2008-12-17 16:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-17 10:42 George Spelvin
2008-12-17 13:28 ` Andi Kleen
2008-12-17 15:15   ` Peter Zijlstra
2008-12-17 15:47     ` Steven Rostedt
2008-12-17 16:15       ` Andi Kleen
2008-12-18  8:00       ` George Spelvin
2008-12-18  8:55         ` George Spelvin
2008-12-18 19:53           ` Casey Dahlin
2008-12-18 21:53             ` George Spelvin
2008-12-17 16:04     ` George Spelvin [this message]
2008-12-17 16:13       ` Steven Rostedt
2008-12-17 16:22       ` Tejun Heo
2008-12-17 16:31         ` Steven Rostedt
2008-12-17 16:33           ` Tejun Heo
2008-12-17 16:36             ` Peter Zijlstra
2008-12-17 16:45               ` Tejun Heo
2008-12-17 16:37             ` Steven Rostedt
2008-12-17 16:51               ` Andi Kleen
2008-12-17 16:54                 ` Steven Rostedt
2008-12-17 15:37   ` George Spelvin

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=20081217160417.18507.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=srostedt@redhat.com \
    --cc=tj@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®