Blame SOURCES/0074-nft-Fix-EPERM-handling-for-extensions-without-rev-0.patch

d8275f
From 3696c4af80496a0dd5a3637e4be11754e2cdc99e Mon Sep 17 00:00:00 2001
d8275f
From: Phil Sutter <phil@nwl.cc>
d8275f
Date: Wed, 4 May 2022 11:19:16 +0200
d8275f
Subject: [PATCH] nft: Fix EPERM handling for extensions without rev 0
d8275f
d8275f
Treating revision 0 as compatible in EPERM case works fine as long as
d8275f
there is a revision 0 of that extension defined in DSO. Fix the code for
d8275f
others: Extend the EPERM handling to all revisions and keep the existing
d8275f
warning for revision 0.
d8275f
d8275f
Fixes: 17534cb18ed0a ("Improve error messages for unsupported extensions")
d8275f
Signed-off-by: Phil Sutter <phil@nwl.cc>
d8275f
(cherry picked from commit 8468fd4f7c85c21ab375402bc80d0188412b6cbf)
d8275f
---
d8275f
 iptables/nft.c                                        | 11 +++++++----
d8275f
 .../shell/testcases/iptables/0008-unprivileged_0      |  6 ++++++
d8275f
 2 files changed, 13 insertions(+), 4 deletions(-)
d8275f
d8275f
diff --git a/iptables/nft.c b/iptables/nft.c
d8275f
index 9643abf2d0085..9839e8c683708 100644
d8275f
--- a/iptables/nft.c
d8275f
+++ b/iptables/nft.c
d8275f
@@ -3110,15 +3110,18 @@ int nft_compatible_revision(const char *name, uint8_t rev, int opt)
d8275f
 err:
d8275f
 	mnl_socket_close(nl);
d8275f
 
d8275f
-	/* pretend revision 0 is valid -
d8275f
+	/* ignore EPERM and errors for revision 0 -
d8275f
 	 * this is required for printing extension help texts as user, also
d8275f
 	 * helps error messaging on unavailable kernel extension */
d8275f
-	if (ret < 0 && rev == 0) {
d8275f
-		if (errno != EPERM)
d8275f
+	if (ret < 0) {
d8275f
+		if (errno == EPERM)
d8275f
+			return 1;
d8275f
+		if (rev == 0) {
d8275f
 			fprintf(stderr,
d8275f
 				"Warning: Extension %s revision 0 not supported, missing kernel module?\n",
d8275f
 				name);
d8275f
-		return 1;
d8275f
+			return 1;
d8275f
+		}
d8275f
 	}
d8275f
 
d8275f
 	return ret < 0 ? 0 : 1;
d8275f
diff --git a/iptables/tests/shell/testcases/iptables/0008-unprivileged_0 b/iptables/tests/shell/testcases/iptables/0008-unprivileged_0
d8275f
index 43e3bc8721dbd..983531fef4720 100755
d8275f
--- a/iptables/tests/shell/testcases/iptables/0008-unprivileged_0
d8275f
+++ b/iptables/tests/shell/testcases/iptables/0008-unprivileged_0
d8275f
@@ -35,6 +35,12 @@ let "rc+=$?"
d8275f
 grep_or_rc "DNAT target options:" <<< "$out"
d8275f
 let "rc+=$?"
d8275f
 
d8275f
+# TEE has no revision 0
d8275f
+out=$(run $XT_MULTI iptables -j TEE --help)
d8275f
+let "rc+=$?"
d8275f
+grep_or_rc "TEE target options:" <<< "$out"
d8275f
+let "rc+=$?"
d8275f
+
d8275f
 out=$(run $XT_MULTI iptables -p tcp -j DNAT --help)
d8275f
 let "rc+=$?"
d8275f
 grep_or_rc "tcp match options:" <<< "$out"
d8275f
-- 
d8275f
2.34.1
d8275f