All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Florian Westphal <fw@strlen.de>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft] json: work around fuzzer-induced assert crashes
Date: Wed, 4 Jun 2025 17:40:49 +0200	[thread overview]
Message-ID: <aEBpAUZBwuQn1Imn@orbyte.nwl.cc> (raw)
In-Reply-To: <aD87gslgK0kk5qzT@orbyte.nwl.cc>

Hi,

On Tue, Jun 03, 2025 at 08:14:26PM +0200, Phil Sutter wrote:
> On Mon, Jun 02, 2025 at 02:12:49PM +0200, Florian Westphal wrote:
> > fuzzer can cause assert failures due to json_pack() returning a NULL
> > value and therefore triggering the assert(out) in __json_pack macro.
> > 
> > All instances I saw are due to invalid UTF-8 strings, i.e., table/chain
> > names with non-text characters in them.
> 
> So these odd strings are supported everywhere else and we only fail to
> format them into JSON? According to the spec[1] this should even support
> "\uXXXX"-style escapes. Not sure if it helps us, but to me this sounds
> like a bug in libjansson. Or are these really binary sequences somehow
> entered into nftables wich jansson's utf8_check_string() identifies as
> invalid?
> 
> > Work around this for now, replace the assert with a plaintext error
> > message and return NULL instead of abort().
> 
> The old code was active with DEBUG builds, only. If undefined, it would
> just call json_pack() itself. Did you test a non-DEBUG build, too? I
> wonder if json.c swallows the NULL return or we see at least an error
> message.

So for testing purposes, I built a json_pack() wrapper which
occasionally returns NULL (and does not assert()). This causes almost
all py testsuite tests to fail, obviously due to JSON dump differences.

Piping the non-empty ruleset-after.json files into json_pp shows no
errors, i.e. if we get any JSON output it is valid at least.

Looking at testout.log of those tests with rc-failed-dump status, I
don't see error messages related to JSON output. So catching the NULL
return is definitely necessary, also with non-DEBUG builds. Hence:

Acked-by: Phil Sutter <phil@nwl.cc>

Thanks, Phil

  reply	other threads:[~2025-06-04 15:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 12:12 [PATCH nft] json: work around fuzzer-induced assert crashes Florian Westphal
2025-06-03 18:14 ` Phil Sutter
2025-06-04 15:40   ` Phil Sutter [this message]
2025-06-05 13:43     ` Florian Westphal

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=aEBpAUZBwuQn1Imn@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=fw@strlen.de \
    --cc=netfilter-devel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.