From: Anton Skorup <antonsk@axis.com>
To: <openembedded-devel@lists.openembedded.org>
Cc: Anton Skorup <anton@skorup.se>, Anton Skorup <anton.skorup@axis.com>
Subject: [PATCH 6/8] jq: patch CVE-2026-40612
Date: Tue, 16 Jun 2026 08:27:52 +0200 [thread overview]
Message-ID: <20260616062754.748436-6-antonsk@axis.com> (raw)
In-Reply-To: <20260616062754.748436-1-antonsk@axis.com>
From: Anton Skorup <anton@skorup.se>
CVE details: https://www.cve.org/CVERecord?id=CVE-2026-40612
Signed-off-by: Anton Skorup <anton.skorup@axis.com>
---
.../jq/jq/CVE-2026-40612.patch | 136 ++++++++++++++++++
meta-oe/recipes-devtools/jq/jq_1.8.1.bb | 1 +
2 files changed, 137 insertions(+)
create mode 100644 meta-oe/recipes-devtools/jq/jq/CVE-2026-40612.patch
diff --git a/meta-oe/recipes-devtools/jq/jq/CVE-2026-40612.patch b/meta-oe/recipes-devtools/jq/jq/CVE-2026-40612.patch
new file mode 100644
index 0000000000..4078b8b10d
--- /dev/null
+++ b/meta-oe/recipes-devtools/jq/jq/CVE-2026-40612.patch
@@ -0,0 +1,136 @@
+From d1a12569d91641135976a8536776a4a329c02cc2 Mon Sep 17 00:00:00 2001
+From: itchyny <itchyny@cybozu.co.jp>
+Date: Fri, 24 Apr 2026 22:02:24 +0900
+Subject: [PATCH] Limit the containment check depth
+
+This fixes CVE-2026-40612.
+
+Signed-off-by: Anton Skorup
+Upstream-Status: Backport [https://github.com/jqlang/jq/commit/d1a12569d91641135976a8536776a4a329c02cc2]
+---
+ src/builtin.c | 5 ++++-
+ src/jv.c | 40 +++++++++++++++++++++++++++-------------
+ tests/jq.test | 9 +++++++++
+ 3 files changed, 40 insertions(+), 14 deletions(-)
+
+diff --git a/src/builtin.c b/src/builtin.c
+index d33e9fb162..2b2a2d40da 100644
+--- a/src/builtin.c
++++ b/src/builtin.c
+@@ -421,7 +421,10 @@ jv binop_greatereq(jv a, jv b) {
+
+ static jv f_contains(jq_state *jq, jv a, jv b) {
+ if (jv_get_kind(a) == jv_get_kind(b)) {
+- return jv_bool(jv_contains(a, b));
++ int r = jv_contains(a, b);
++ if (r < 0)
++ return jv_invalid_with_msg(jv_string("Containment check too deep"));
++ return jv_bool(r);
+ } else {
+ return type_error2(a, b, "cannot have their containment checked");
+ }
+diff --git a/src/jv.c b/src/jv.c
+index 607ac174f7..4b18c00cf6 100644
+--- a/src/jv.c
++++ b/src/jv.c
+@@ -938,19 +938,19 @@ static void jvp_clamp_slice_params(int len, int *pstart, int *pend)
+ }
+
+
+-static int jvp_array_contains(jv a, jv b) {
++static int jvp_contains(jv a, jv b, int depth);
++
++static int jvp_array_contains(jv a, jv b, int depth) {
+ int r = 1;
+ jv_array_foreach(b, bi, belem) {
+ int ri = 0;
+ jv_array_foreach(a, ai, aelem) {
+- if (jv_contains(aelem, jv_copy(belem))) {
+- ri = 1;
+- break;
+- }
++ ri = jvp_contains(aelem, jv_copy(belem), depth);
++ if (ri) break;
+ }
+ jv_free(belem);
+- if (!ri) {
+- r = 0;
++ if (ri <= 0) {
++ r = ri;
+ break;
+ }
+ }
+@@ -1844,7 +1844,7 @@ static int jvp_object_equal(jv o1, jv o2) {
+ return len1 == len2;
+ }
+
+-static int jvp_object_contains(jv a, jv b) {
++static int jvp_object_contains(jv a, jv b, int depth) {
+ assert(JVP_HAS_KIND(a, JV_KIND_OBJECT));
+ assert(JVP_HAS_KIND(b, JV_KIND_OBJECT));
+ int r = 1;
+@@ -1852,9 +1852,9 @@ static int jvp_object_contains(jv a, jv b) {
+ jv_object_foreach(b, key, b_val) {
+ jv a_val = jv_object_get(jv_copy(a), key);
+
+- r = jv_contains(a_val, b_val);
++ r = jvp_contains(a_val, b_val, depth);
+
+- if (!r) break;
++ if (r <= 0) break;
+ }
+ return r;
+ }
+@@ -2086,14 +2086,23 @@ int jv_identical(jv a, jv b) {
+ return r;
+ }
+
+-int jv_contains(jv a, jv b) {
++#ifndef MAX_CONTAINS_DEPTH
++#define MAX_CONTAINS_DEPTH (10000)
++#endif
++
++static int jvp_contains(jv a, jv b, int depth) {
++ if (depth > MAX_CONTAINS_DEPTH) {
++ jv_free(a);
++ jv_free(b);
++ return -1;
++ }
+ int r = 1;
+ if (jv_get_kind(a) != jv_get_kind(b)) {
+ r = 0;
+ } else if (JVP_HAS_KIND(a, JV_KIND_OBJECT)) {
+- r = jvp_object_contains(a, b);
++ r = jvp_object_contains(a, b, depth + 1);
+ } else if (JVP_HAS_KIND(a, JV_KIND_ARRAY)) {
+- r = jvp_array_contains(a, b);
++ r = jvp_array_contains(a, b, depth + 1);
+ } else if (JVP_HAS_KIND(a, JV_KIND_STRING)) {
+ int b_len = jv_string_length_bytes(jv_copy(b));
+ if (b_len != 0) {
+@@ -2109,3 +2118,8 @@ int jv_contains(jv a, jv b) {
+ jv_free(b);
+ return r;
+ }
++
++// Returns 1 (contained), 0 (not contained), or -1 (too deep)
++int jv_contains(jv a, jv b) {
++ return jvp_contains(a, b, 0);
++}
+diff --git a/tests/jq.test b/tests/jq.test
+index 0cd5198f8d..8094a5b6eb 100644
+--- a/tests/jq.test
++++ b/tests/jq.test
+@@ -2593,3 +2593,12 @@ null
+ try delpaths([[range(10001) | 0]]) catch .
+ null
+ "Path too deep"
++
++# regression test for CVE-2026-40612
++reduce range(10000) as $_ ([]; [.]) | contains([[]])
++null
++true
++
++try (reduce range(10001) as $_ ([]; [.]) as $x | $x | contains($x)) catch .
++null
++"Containment check too deep"
diff --git a/meta-oe/recipes-devtools/jq/jq_1.8.1.bb b/meta-oe/recipes-devtools/jq/jq_1.8.1.bb
index bb4601b667..0653dcd1f1 100644
--- a/meta-oe/recipes-devtools/jq/jq_1.8.1.bb
+++ b/meta-oe/recipes-devtools/jq/jq_1.8.1.bb
@@ -17,6 +17,7 @@ SRC_URI = "git://github.com/jqlang/jq.git;protocol=https;branch=master;tag=jq-${
file://CVE-2026-33947.patch \
file://CVE-2026-33948.patch \
file://CVE-2026-39979.patch \
+ file://CVE-2026-40612.patch \
file://CVE-2026-41256.patch \
file://CVE-2026-41257.patch \
file://CVE-2026-43896.patch \
--
2.43.0
next prev parent reply other threads:[~2026-06-16 7:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 6:27 [PATCHv2 1/8] jq: patch CVE-2026-49839 Anton Skorup
2026-06-16 6:27 ` [PATCH 2/8] jq: patch CVE-2026-41256 Anton Skorup
2026-06-16 6:27 ` [PATCH 3/8] jq: patch CVE-2026-44777 Anton Skorup
2026-06-16 6:27 ` [PATCH 4/8] jq: patch CVE-2026-43896 Anton Skorup
2026-06-16 6:27 ` [PATCH 5/8] jq: patch CVE-2026-41257 Anton Skorup
2026-06-16 6:27 ` Anton Skorup [this message]
2026-06-16 6:27 ` [PATCH 7/8] jq: patch CVE-2026-43894 Anton Skorup
2026-06-16 6:27 ` [PATCH 8/8] jq: patch CVE-2026-43895 Anton Skorup
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=20260616062754.748436-6-antonsk@axis.com \
--to=antonsk@axis.com \
--cc=anton.skorup@axis.com \
--cc=anton@skorup.se \
--cc=openembedded-devel@lists.openembedded.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.