netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Haller <thaller@redhat.com>
To: NetFilter <netfilter-devel@vger.kernel.org>
Cc: Thomas Haller <thaller@redhat.com>
Subject: [PATCH nft v3 1/6] json: fix use after free in table_flags_json()
Date: Tue, 14 Nov 2023 16:29:25 +0100	[thread overview]
Message-ID: <20231114153150.406334-2-thaller@redhat.com> (raw)
In-Reply-To: <20231114153150.406334-1-thaller@redhat.com>

Add `$NFT -j list ruleset` to the end of "tests/shell/testcases/transactions/table_onoff".
Then valgrind will find this issue:

  $ make -j && ./tests/shell/run-tests.sh tests/shell/testcases/transactions/table_onoff -V

Gives:

  ==286== Invalid read of size 4
  ==286==    at 0x49B0261: do_dump (dump.c:211)
  ==286==    by 0x49B08B8: do_dump (dump.c:378)
  ==286==    by 0x49B08B8: do_dump (dump.c:378)
  ==286==    by 0x49B04F7: do_dump (dump.c:273)
  ==286==    by 0x49B08B8: do_dump (dump.c:378)
  ==286==    by 0x49B0E84: json_dump_callback (dump.c:465)
  ==286==    by 0x48AF22A: do_command_list_json (json.c:2016)
  ==286==    by 0x48732F1: do_command_list (rule.c:2335)
  ==286==    by 0x48737F5: do_command (rule.c:2605)
  ==286==    by 0x48A867D: nft_netlink (libnftables.c:42)
  ==286==    by 0x48A92B1: nft_run_cmd_from_buffer (libnftables.c:597)
  ==286==    by 0x402CBA: main (main.c:533)

Fixes: e70354f53e9f ("libnftables: Implement JSON output support")
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 src/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/json.c b/src/json.c
index 23bd247221d3..81328ab3a4e4 100644
--- a/src/json.c
+++ b/src/json.c
@@ -496,7 +496,7 @@ static json_t *table_flags_json(const struct table *table)
 		json_decref(root);
 		return NULL;
 	case 1:
-		json_unpack(root, "[o]", &tmp);
+		json_unpack(root, "[O]", &tmp);
 		json_decref(root);
 		root = tmp;
 		break;
-- 
2.41.0


  reply	other threads:[~2023-11-14 15:32 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 15:29 [PATCH nft v3 0/6] add and check dump files for JSON in tests/shell Thomas Haller
2023-11-14 15:29 ` Thomas Haller [this message]
2023-11-15  9:58   ` [PATCH nft v3 1/6] json: fix use after free in table_flags_json() Pablo Neira Ayuso
2023-11-14 16:08 ` [PATCH nft v3 2/6] tests/shell: check and generate JSON dump files Thomas Haller
2023-11-14 16:08   ` [PATCH nft v3 4/6] tools: simplify error handling in "check-tree.sh" by adding msg_err()/msg_warn() Thomas Haller
2023-11-14 16:08   ` [PATCH nft v3 5/6] tools: check more strictly for bash shebang in "check-tree.sh" Thomas Haller
2023-11-14 16:08   ` [PATCH nft v3 6/6] tools: check for consistency of .json-nft dumps " Thomas Haller
2023-11-15  8:24   ` [PATCH nft v3 2/6] tests/shell: check and generate JSON dump files Florian Westphal
2023-11-15  9:54     ` Pablo Neira Ayuso
2023-11-15 10:01       ` Florian Westphal
2023-11-15 10:05         ` Pablo Neira Ayuso
2023-11-15 10:10           ` Florian Westphal
2023-11-15 10:26             ` Pablo Neira Ayuso
2023-11-15 10:31               ` Florian Westphal
2023-11-15 10:35                 ` Pablo Neira Ayuso
2023-11-15 10:43         ` Pablo Neira Ayuso
2023-11-15 12:21           ` Florian Westphal
2023-11-15 12:30             ` Pablo Neira Ayuso
2023-11-15 12:36               ` Thomas Haller
2023-11-16 16:10                 ` Pablo Neira Ayuso
2023-11-16 16:49                   ` Thomas Haller
2023-11-16 16:55                     ` Thomas Haller
2023-11-16 23:00                   ` Florian Westphal
2023-11-16 23:02                     ` Florian Westphal
2023-11-17  8:27                     ` Pablo Neira Ayuso
2023-11-17 16:16                     ` Thomas Haller
2023-11-17 16:36                       ` Pablo Neira Ayuso
2023-11-17 16:56                         ` Thomas Haller
2023-11-17 16:57                         ` Phil Sutter
2023-11-17 17:06                           ` Thomas Haller
2023-11-17 17:11                             ` Phil Sutter
2023-11-17 17:23                               ` Thomas Haller
2023-11-17 22:30                                 ` Phil Sutter
2023-11-15 10:11       ` Thomas Haller

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=20231114153150.406334-2-thaller@redhat.com \
    --to=thaller@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).