Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1818117

Summary: assertion fails printed instead of error messages
Product: Red Hat Enterprise Linux 8 Reporter: Jiri Peska <jpeska>
Component: nftablesAssignee: Phil Sutter <psutter>
Status: CLOSED ERRATA QA Contact: Štěpán Němec <snemec>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.4CC: todoleza
Target Milestone: rcKeywords: Triaged
Target Release: 8.0Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: nftables-0.9.3-19.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-11-09 19:53:44 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jiri Peska 2020-03-27 18:45:57 UTC
Description of problem:
When star (*) is used for iifname, failed assertion is shown. It should give an error, since the rule does not make much sense, but printed error should be more explanatory. 


Version-Release number of selected component (if applicable):
nftables-0.9.3-11.el8.x86_64


How reproducible:
always


Steps to Reproduce:
1. Create following file 
#cat ruleset.nft
add rule ip filter input iifname "*" ct state new accept

2. load ruleset from file
#nft -f ruleset.nft


Actual results:
nft: expression.c:394: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
Aborted (core dumped)


Expected results:
Explanatory error message instead of assertion.


Additional info:

Comment 1 Tomas Dolezal 2020-09-04 18:12:35 UTC
Adding Regression keyword. from nftables-0.9.3-12.el8 to nftables-0.9.3-16.el8 the output for following ruleset changed in a way that '\' before '*' in iifname is omitted thus cannot be saved and loaded again.

cropped output 1 (valid):
iifname "\*" meta l4proto tcp tcp dport 80 counter
cropped output 1 (invalid):
iifname "*" tcp dport 80 counter

cat > nft-a.rules <<EOF
flush ruleset
table ip filter {
	chain INPUT {
		type filter hook input priority filter; policy accept;
		iifname "\*" tcp dport 80 counter accept
	}
}
EOF
nft 'flush ruleset; include "./nft-a.rules"'
nft -s list ruleset > nft-b.rules
nft 'flush ruleset; include "./nft-b.rules"'
nft: expression.c:394: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
Aborted (core dumped)

cat nft-b.rules
table ip filter {
	chain INPUT {
		type filter hook input priority filter; policy accept;
		iifname "*" tcp dport 80 counter accept
	}
}

Comment 3 Phil Sutter 2020-10-06 13:02:32 UTC
(In reply to Tomas Dolezal from comment #1)
> Adding Regression keyword. from nftables-0.9.3-12.el8 to
> nftables-0.9.3-16.el8 the output for following ruleset changed in a way that
> '\' before '*' in iifname is omitted thus cannot be saved and loaded again.
> 
> cropped output 1 (valid):
> iifname "\*" meta l4proto tcp tcp dport 80 counter
> cropped output 1 (invalid):
> iifname "*" tcp dport 80 counter
> 
> cat > nft-a.rules <<EOF
> flush ruleset
> table ip filter {
> 	chain INPUT {
> 		type filter hook input priority filter; policy accept;
> 		iifname "\*" tcp dport 80 counter accept
> 	}
> }
> EOF
> nft 'flush ruleset; include "./nft-a.rules"'
> nft -s list ruleset > nft-b.rules
> nft 'flush ruleset; include "./nft-b.rules"'
> nft: expression.c:394: constant_expr_alloc: Assertion `(((len) + (8) - 1) /
> (8)) > 0' failed.
> Aborted (core dumped)
> 
> cat nft-b.rules
> table ip filter {
> 	chain INPUT {
> 		type filter hook input priority filter; policy accept;
> 		iifname "*" tcp dport 80 counter accept
> 	}
> }

For unknown reasons, I can't reproduce this on a machine with
nftables-0.9.3-16.el8.x86_64 installed. If nft-a.rules contains 'iifname "\*"',
so does 'nft list ruleset'.

Comment 4 Phil Sutter 2020-10-06 15:37:13 UTC
A fix for the first issue was submitted upstream: https://lore.kernel.org/netfilter-devel/20200924170639.15842-1-phil@nwl.cc/

Comment 5 Phil Sutter 2020-12-17 16:20:01 UTC
Upstream commit to backport:

commit 032c9f745c6daab8c27176a95963b1c32b0a5d12
Author: Phil Sutter <phil>
Date:   Thu Sep 24 17:38:45 2020 +0200

    evaluate: Reject quoted strings containing only wildcard
    
    Fix for an assertion fail when trying to match against an all-wildcard
    interface name:
    
    | % nft add rule t c iifname '"*"'
    | nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
    | zsh: abort      nft add rule t c iifname '"*"'
    
    Fix this by detecting the string in expr_evaluate_string() and returning
    an error message:
    
    | % nft add rule t c iifname '"*"'
    | Error: All-wildcard strings are not supported
    | add rule t c iifname "*"
    |                      ^^^
    
    While being at it, drop the 'datalen >= 1' clause from the following
    conditional as together with the added check for 'datalen == 0', all
    possible other values have been caught already.

Comment 6 Tomas Dolezal 2021-05-14 18:56:02 UTC
(In reply to Phil Sutter from comment #3)
> (In reply to Tomas Dolezal from comment #1)
> > Adding Regression keyword. from nftables-0.9.3-12.el8 to
> > nftables-0.9.3-16.el8 the output for following ruleset changed in a way that
> > '\' before '*' in iifname is omitted thus cannot be saved and loaded again.
> For unknown reasons, I can't reproduce this on a machine with
> nftables-0.9.3-16.el8.x86_64 installed. If nft-a.rules contains 'iifname
> "\*"',
> so does 'nft list ruleset'.

I am sorry to be unable to reproduce this one as well. I can't explain it better than as a badly described environment or a mistake when observing versions. I also tried upgrading from nftables-0.9.3-12.el8 to R-16 with no success in reproducing on 8.2.1's kernel

Comment 14 errata-xmlrpc 2021-11-09 19:53:44 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (nftables bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4465