From patchwork Sun May 24 13:00:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Brivio X-Patchwork-Id: 1296848 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d+jUBJrK; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49VL1p4J3Nz9sSF for ; Sun, 24 May 2020 23:00:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729155AbgEXNAq (ORCPT ); Sun, 24 May 2020 09:00:46 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28373 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725873AbgEXNAp (ORCPT ); Sun, 24 May 2020 09:00:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590325245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V99fkelWIQWqXSHN4rM1HWWLAEMPaKKBjhox0AdFKPw=; b=d+jUBJrKJ6mFE1pvLcl9oi6m00P7wjmqkJGHSqA1iM+24innvGiaQwKwSDDmoTlkPO93QA UMoEplVNgYIBF6VUwccj/HPtG6Lkk05mfrIkWI4APtPLfKumS9mFWGXKQ/XZSpusvFp8wy W1aH6SBniyVdOTnezEZ1fXTzLoWOUpg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-wJ38HEUxNFuVxywWTigO-A-1; Sun, 24 May 2020 09:00:43 -0400 X-MC-Unique: wJ38HEUxNFuVxywWTigO-A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 399BA1800D42; Sun, 24 May 2020 13:00:42 +0000 (UTC) Received: from epycfail.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23BAB63F8C; Sun, 24 May 2020 13:00:40 +0000 (UTC) From: Stefano Brivio To: Pablo Neira Ayuso Cc: Phil Sutter , netfilter-devel@vger.kernel.org Subject: [PATCH nft 1/2] evaluate: Perform set evaluation on implicitly declared (anonymous) sets Date: Sun, 24 May 2020 15:00:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org If a set is implicitly declared, set_evaluate() is not called as a result of cmd_evaluate_add(), because we're adding in fact something else (e.g. a rule). Expression-wise, evaluation still happens as the implicit set expression is eventually found in the tree and handled by expr_evaluate_set(), but context-wise evaluation (set_evaluate()) is skipped, and this might be relevant instead. This is visible in the reported case of an anonymous set including concatenated ranges: # nft add rule t c ip saddr . tcp dport { 192.0.2.1 . 20-30 } accept BUG: invalid range expression type concat nft: expression.c:1160: range_expr_value_low: Assertion `0' failed. Aborted because we reach do_add_set() without properly evaluated flags and set description, and eventually end up in expr_to_intervals(), which can't handle that expression. Explicitly call set_evaluate() as we add anonymous sets into the context, and instruct the same function to skip expression-wise set evaluation if the set is anonymous, as that happens later anyway as part of the general tree evaluation. Reported-by: Pablo Neira Ayuso Reported-by: Phil Sutter Signed-off-by: Stefano Brivio Acked-by: Phil Sutter --- src/evaluate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/evaluate.c b/src/evaluate.c index 506f2c6a257e..ee019bc98480 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -76,6 +76,7 @@ static void key_fix_dtype_byteorder(struct expr *key) datatype_set(key, set_datatype_alloc(dtype, key->byteorder)); } +static int set_evaluate(struct eval_ctx *ctx, struct set *set); static struct expr *implicit_set_declaration(struct eval_ctx *ctx, const char *name, struct expr *key, @@ -107,6 +108,8 @@ static struct expr *implicit_set_declaration(struct eval_ctx *ctx, list_add_tail(&cmd->list, &ctx->cmd->list); } + set_evaluate(ctx, set); + return set_ref_expr_alloc(&expr->location, set); } @@ -3547,7 +3550,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) } ctx->set = set; - if (set->init != NULL) { + if (!set_is_anonymous(set->flags) && set->init != NULL) { __expr_set_context(&ctx->ectx, set->key->dtype, set->key->byteorder, set->key->len, 0); if (expr_evaluate(ctx, &set->init) < 0) From patchwork Sun May 24 13:00:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Brivio X-Patchwork-Id: 1296849 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TS31JgV1; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49VL1r2gn7z9sSF for ; Sun, 24 May 2020 23:00:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729361AbgEXNAs (ORCPT ); Sun, 24 May 2020 09:00:48 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36748 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725873AbgEXNAr (ORCPT ); Sun, 24 May 2020 09:00:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590325246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yCWbbSQdUSB34seiefqT+0h/Wh/XEyCYpwYHY597OdY=; b=TS31JgV1wgVMOa5RRf8reejIYxsoa8wJS98xYVhWoGlp7wvk9f5lAaSvk6TfGLIIkVBbnA 8er6ZOaZyOKZrtcjL+K6dJ0OasjV0fNOLuzhdjOCeFZdNSJPVwHF/oTDtfW1yaTWBo3/Sy gZ3rjwwM6gjOhT8Ofx4lnp7G3ecz6+w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-Zlxz1pTlPh-p4PLt8_R60A-1; Sun, 24 May 2020 09:00:44 -0400 X-MC-Unique: Zlxz1pTlPh-p4PLt8_R60A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AEFB01855A00; Sun, 24 May 2020 13:00:43 +0000 (UTC) Received: from epycfail.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A957797EB; Sun, 24 May 2020 13:00:42 +0000 (UTC) From: Stefano Brivio To: Pablo Neira Ayuso Cc: Phil Sutter , netfilter-devel@vger.kernel.org Subject: [PATCH nft 2/2] tests: shell: Introduce test for concatenated ranges in anonymous sets Date: Sun, 24 May 2020 15:00:27 +0200 Message-Id: <5735155a0e98738cdc5507385d6225e05c225465.1590324033.git.sbrivio@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Add a simple anonymous set including a concatenated range and check it's inserted correctly. This is roughly based on the existing 0025_anonymous_set_0 test case. Signed-off-by: Stefano Brivio --- tests/shell/testcases/sets/0048anonymous_set_concat_0 | 7 +++++++ .../testcases/sets/dumps/0048anonymous_set_concat_0.nft | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100755 tests/shell/testcases/sets/0048anonymous_set_concat_0 create mode 100644 tests/shell/testcases/sets/dumps/0048anonymous_set_concat_0.nft diff --git a/tests/shell/testcases/sets/0048anonymous_set_concat_0 b/tests/shell/testcases/sets/0048anonymous_set_concat_0 new file mode 100755 index 000000000000..fab61231d0c0 --- /dev/null +++ b/tests/shell/testcases/sets/0048anonymous_set_concat_0 @@ -0,0 +1,7 @@ +#!/bin/sh -e +# +# 0048anonymous_sets_concat_0 - Anonymous sets with concatenated ranges + +${NFT} add table t +${NFT} add chain t c '{ type filter hook forward priority 0 ; }' +${NFT} add rule t c 'ip daddr . tcp dport { 192.0.2.1 . 49152-65535 }' diff --git a/tests/shell/testcases/sets/dumps/0048anonymous_set_concat_0.nft b/tests/shell/testcases/sets/dumps/0048anonymous_set_concat_0.nft new file mode 100644 index 000000000000..c54ffae9d6d2 --- /dev/null +++ b/tests/shell/testcases/sets/dumps/0048anonymous_set_concat_0.nft @@ -0,0 +1,6 @@ +table ip t { + chain c { + type filter hook forward priority filter; policy accept; + ip daddr . tcp dport { 192.0.2.1 . 49152-65535 } + } +}