From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>, netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH 3/4] netlink: Keep going after set element parsing failures
Date: Wed, 21 May 2025 19:19:19 +0200 [thread overview]
Message-ID: <aC4LF_xAVp9WIMLe@orbyte.nwl.cc> (raw)
In-Reply-To: <aC3gjbdJ_z8gewqd@calendula>
On Wed, May 21, 2025 at 04:17:49PM +0200, Pablo Neira Ayuso wrote:
> On Wed, May 21, 2025 at 03:12:41PM +0200, Phil Sutter wrote:
> > Print an error message and try to deserialize the remaining elements
> > instead of calling BUG().
> >
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > src/netlink.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/netlink.c b/src/netlink.c
> > index 1222919458bae..3221d9f8ffc93 100644
> > --- a/src/netlink.c
> > +++ b/src/netlink.c
> > @@ -1475,7 +1475,9 @@ int netlink_delinearize_setelem(struct netlink_ctx *ctx,
> > key->byteorder = set->key->byteorder;
> > key->len = set->key->len;
> > } else {
> > - BUG("Unexpected set element with no key\n");
> > + netlink_io_error(ctx, NULL,
> > + "Unexpected set element with no key\n");
> > + return 0;
>
> If set element has no key, then something is very wrong. There is
> already one exception that is the catch-all element (which has no
> key).
Yes, in these cases the ruleset parser fails and the output is very
likely broken or at least incomplete. This series merely aligns error
handling: Take netlink_parse_cmp() for instance: If NFTNL_EXPR_CMP_SREG
attribute is missing or bogus, netlink_error() is called and the
function returns (void). No error status propagation happens (which we
could change easily), but most importantly the parser continues to
deserialize as much as possible.
> This is enqueuing an error record, but 0 is returned, I am not sure if
> this is ever going to be printed.
It does: Forcing the code to enter that third branch, listing a set with three
elements looks like this:
% sudo ./src/nft list ruleset
table ip t {
set s {
type inet_service
}
}
netlink: Error: Unexpected set element with no key
netlink: Error: Unexpected set element with no key
netlink: Error: Unexpected set element with no key
> I am not sure this patch works.
Well, that extra newline is indeed a bug. :)
Cheers, Phil
next prev parent reply other threads:[~2025-05-21 17:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 13:12 [nft PATCH 0/4] Continue upon netlink deserialization failures Phil Sutter
2025-05-21 13:12 ` [nft PATCH 1/4] netlink_delinearize: Replace some BUG()s by error messages Phil Sutter
2025-05-21 13:12 ` [nft PATCH 2/4] netlink: Pass netlink_ctx to netlink_delinearize_setelem() Phil Sutter
2025-05-21 13:12 ` [nft PATCH 3/4] netlink: Keep going after set element parsing failures Phil Sutter
2025-05-21 14:17 ` Pablo Neira Ayuso
2025-05-21 17:19 ` Phil Sutter [this message]
2025-05-22 17:17 ` Pablo Neira Ayuso
2025-05-21 13:12 ` [nft PATCH 4/4] cache: Tolerate object deserialization failures Phil Sutter
2025-05-22 17:18 ` [nft PATCH 0/4] Continue upon netlink " Pablo Neira Ayuso
2025-05-25 7:58 ` Phil Sutter
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=aC4LF_xAVp9WIMLe@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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.