All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH v2 02/11] mergesort: Fix sorting of string values
Date: Wed, 28 Jan 2026 13:11:33 +0100	[thread overview]
Message-ID: <aXn89RA9apxGSXd_@orbyte.nwl.cc> (raw)
In-Reply-To: <aXlKECq5p9SUYuJO@chamomile>

On Wed, Jan 28, 2026 at 12:28:16AM +0100, Pablo Neira Ayuso wrote:
> On Fri, Nov 14, 2025 at 01:25:33AM +0100, Phil Sutter wrote:
> > Sorting order was obviously wrong, e.g. "ppp0" ordered before "eth1".
> > Moreover, this happened on Little Endian only so sorting order actually
> > depended on host's byteorder. By reimporting string values as Big
> > Endian, both issues are fixed: On one hand, GMP-internal byteorder no
> > longer depends on host's byteorder, on the other comparing strings
> > really starts with the first character, not the last.
> > 
> > Fixes: 14ee0a979b622 ("src: sort set elements in netlink_get_setelems()")
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> >  src/mergesort.c                               |  7 +++
> >  tests/py/any/meta.t.json.output               | 54 -------------------
> >  tests/py/any/queue.t.json.output              |  4 +-
> >  tests/py/inet/osf.t.json.output               | 54 +++++++++++++++++++
> >  .../testcases/maps/dumps/0012map_0.json-nft   | 20 +++----
> >  .../shell/testcases/maps/dumps/0012map_0.nft  |  8 +--
> >  .../maps/dumps/named_ct_objects.json-nft      |  4 +-
> >  .../testcases/maps/dumps/named_ct_objects.nft |  4 +-
> >  .../sets/dumps/sets_with_ifnames.json-nft     |  4 +-
> >  .../sets/dumps/sets_with_ifnames.nft          |  2 +-
> >  10 files changed, 84 insertions(+), 77 deletions(-)
> > 
> > diff --git a/src/mergesort.c b/src/mergesort.c
> > index a9cba614612ed..97e36917280f3 100644
> > --- a/src/mergesort.c
> > +++ b/src/mergesort.c
> > @@ -37,6 +37,13 @@ static mpz_srcptr expr_msort_value(const struct expr *expr, mpz_t value)
> >  	case EXPR_RANGE:
> >  		return expr_msort_value(expr->left, value);
> >  	case EXPR_VALUE:
> > +		if (expr_basetype(expr)->type == TYPE_STRING) {
> > +			char buf[expr->len];
> > +
> > +			mpz_export_data(buf, expr->value, BYTEORDER_HOST_ENDIAN, expr->len);
> > +			mpz_import_data(value, buf, BYTEORDER_BIG_ENDIAN, expr->len);
> > +			return value;
> > +		}
> 
> This is also used for automerge, not only get_setelems().
> 
> Are you sure this is correct?

If it isn't, we don't have test coverage for the broken code-path.

Cheers, Phil

  reply	other threads:[~2026-01-28 12:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14  0:25 [nft PATCH v2 00/11] Fix netlink debug output on Big Endian Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 01/11] segtree: Fix range aggregation " Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 02/11] mergesort: Fix sorting of string values Phil Sutter
2026-01-27 23:28   ` Pablo Neira Ayuso
2026-01-28 12:11     ` Phil Sutter [this message]
2025-11-14  0:25 ` [nft PATCH v2 03/11] mergesort: Align concatenation sort order with Big Endian Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 04/11] intervals: Convert byte order implicitly Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 05/11] expression: Set range expression 'len' field Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 06/11] netlink: Introduce struct nft_data_linearize::byteorder Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 07/11] netlink: Introduce struct nft_data_linearize::sizes Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 08/11] netlink: Make use of nftnl_{expr,set_elem}_set_imm() Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 09/11] tests: py: tools: Add regen_payloads.sh Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 10/11] tests: py: Update payload records Phil Sutter
2025-11-14  0:25 ` [nft PATCH v2 11/11] utils: Introduce expr_print_debug() Phil Sutter
2026-01-27 22:04 ` [nft PATCH v2 00/11] Fix netlink debug output on Big Endian 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=aXn89RA9apxGSXd_@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --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.