Blame SOURCES/0054-extensions-SECMARK-Implement-revision-1.patch

082114
From 3bd3af273ccfa550ed50ad19d4bcd04a29b88f5b Mon Sep 17 00:00:00 2001
082114
From: Phil Sutter <phil@nwl.cc>
082114
Date: Thu, 29 Apr 2021 15:28:59 +0200
082114
Subject: [PATCH] extensions: SECMARK: Implement revision 1
082114
082114
The changed data structure for communication with kernel allows to
082114
exclude the field 'secid' which is populated on kernel side. Thus
082114
this fixes the formerly always failing extension comparison breaking
082114
rule check and rule delete by content.
082114
082114
Signed-off-by: Phil Sutter <phil@nwl.cc>
082114
(cherry picked from commit 616800af0da86d151cb695f1376d5ec6ede6fa72)
082114
---
082114
 extensions/libxt_SECMARK.c           | 90 +++++++++++++++++++++-------
082114
 extensions/libxt_SECMARK.t           |  4 ++
082114
 include/linux/netfilter/xt_SECMARK.h |  6 ++
082114
 3 files changed, 80 insertions(+), 20 deletions(-)
082114
 create mode 100644 extensions/libxt_SECMARK.t
082114
082114
diff --git a/extensions/libxt_SECMARK.c b/extensions/libxt_SECMARK.c
082114
index 6ba8606355daa..24249bd618ffe 100644
082114
--- a/extensions/libxt_SECMARK.c
082114
+++ b/extensions/libxt_SECMARK.c
082114
@@ -29,6 +29,13 @@ static const struct xt_option_entry SECMARK_opts[] = {
082114
 	XTOPT_TABLEEND,
082114
 };
082114
 
082114
+static const struct xt_option_entry SECMARK_opts_v1[] = {
082114
+	{.name = "selctx", .id = O_SELCTX, .type = XTTYPE_STRING,
082114
+	 .flags = XTOPT_MAND | XTOPT_PUT,
082114
+	 XTOPT_POINTER(struct xt_secmark_target_info_v1, secctx)},
082114
+	XTOPT_TABLEEND,
082114
+};
082114
+
082114
 static void SECMARK_parse(struct xt_option_call *cb)
082114
 {
082114
 	struct xt_secmark_target_info *info = cb->data;
082114
@@ -37,15 +44,23 @@ static void SECMARK_parse(struct xt_option_call *cb)
082114
 	info->mode = SECMARK_MODE_SEL;
082114
 }
082114
 
082114
-static void print_secmark(const struct xt_secmark_target_info *info)
082114
+static void SECMARK_parse_v1(struct xt_option_call *cb)
082114
+{
082114
+	struct xt_secmark_target_info_v1 *info = cb->data;
082114
+
082114
+	xtables_option_parse(cb);
082114
+	info->mode = SECMARK_MODE_SEL;
082114
+}
082114
+
082114
+static void print_secmark(__u8 mode, const char *secctx)
082114
 {
082114
-	switch (info->mode) {
082114
+	switch (mode) {
082114
 	case SECMARK_MODE_SEL:
082114
-		printf("selctx %s", info->secctx);
082114
+		printf("selctx %s", secctx);
082114
 		break;
082114
-	
082114
+
082114
 	default:
082114
-		xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", info->mode);
082114
+		xtables_error(OTHER_PROBLEM, PFX "invalid mode %hhu\n", mode);
082114
 	}
082114
 }
082114
 
082114
@@ -56,7 +71,17 @@ static void SECMARK_print(const void *ip, const struct xt_entry_target *target,
082114
 		(struct xt_secmark_target_info*)(target)->data;
082114
 
082114
 	printf(" SECMARK ");
082114
-	print_secmark(info);
082114
+	print_secmark(info->mode, info->secctx);
082114
+}
082114
+
082114
+static void SECMARK_print_v1(const void *ip,
082114
+			     const struct xt_entry_target *target, int numeric)
082114
+{
082114
+	const struct xt_secmark_target_info_v1 *info =
082114
+		(struct xt_secmark_target_info_v1 *)(target)->data;
082114
+
082114
+	printf(" SECMARK ");
082114
+	print_secmark(info->mode, info->secctx);
082114
 }
082114
 
082114
 static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
082114
@@ -65,24 +90,49 @@ static void SECMARK_save(const void *ip, const struct xt_entry_target *target)
082114
 		(struct xt_secmark_target_info*)target->data;
082114
 
082114
 	printf(" --");
082114
-	print_secmark(info);
082114
+	print_secmark(info->mode, info->secctx);
082114
 }
082114
 
082114
-static struct xtables_target secmark_target = {
082114
-	.family		= NFPROTO_UNSPEC,
082114
-	.name		= "SECMARK",
082114
-	.version	= XTABLES_VERSION,
082114
-	.revision	= 0,
082114
-	.size		= XT_ALIGN(sizeof(struct xt_secmark_target_info)),
082114
-	.userspacesize	= XT_ALIGN(sizeof(struct xt_secmark_target_info)),
082114
-	.help		= SECMARK_help,
082114
-	.print		= SECMARK_print,
082114
-	.save		= SECMARK_save,
082114
-	.x6_parse	= SECMARK_parse,
082114
-	.x6_options	= SECMARK_opts,
082114
+static void SECMARK_save_v1(const void *ip,
082114
+			    const struct xt_entry_target *target)
082114
+{
082114
+	const struct xt_secmark_target_info_v1 *info =
082114
+		(struct xt_secmark_target_info_v1 *)target->data;
082114
+
082114
+	printf(" --");
082114
+	print_secmark(info->mode, info->secctx);
082114
+}
082114
+
082114
+static struct xtables_target secmark_tg_reg[] = {
082114
+	{
082114
+		.family		= NFPROTO_UNSPEC,
082114
+		.name		= "SECMARK",
082114
+		.version	= XTABLES_VERSION,
082114
+		.revision	= 0,
082114
+		.size		= XT_ALIGN(sizeof(struct xt_secmark_target_info)),
082114
+		.userspacesize	= XT_ALIGN(sizeof(struct xt_secmark_target_info)),
082114
+		.help		= SECMARK_help,
082114
+		.print		= SECMARK_print,
082114
+		.save		= SECMARK_save,
082114
+		.x6_parse	= SECMARK_parse,
082114
+		.x6_options	= SECMARK_opts,
082114
+	},
082114
+	{
082114
+		.family		= NFPROTO_UNSPEC,
082114
+		.name		= "SECMARK",
082114
+		.version	= XTABLES_VERSION,
082114
+		.revision	= 1,
082114
+		.size		= XT_ALIGN(sizeof(struct xt_secmark_target_info_v1)),
082114
+		.userspacesize	= XT_ALIGN(offsetof(struct xt_secmark_target_info_v1, secid)),
082114
+		.help		= SECMARK_help,
082114
+		.print		= SECMARK_print_v1,
082114
+		.save		= SECMARK_save_v1,
082114
+		.x6_parse	= SECMARK_parse_v1,
082114
+		.x6_options	= SECMARK_opts_v1,
082114
+	}
082114
 };
082114
 
082114
 void _init(void)
082114
 {
082114
-	xtables_register_target(&secmark_target);
082114
+	xtables_register_targets(secmark_tg_reg, ARRAY_SIZE(secmark_tg_reg));
082114
 }
082114
diff --git a/extensions/libxt_SECMARK.t b/extensions/libxt_SECMARK.t
082114
new file mode 100644
082114
index 0000000000000..39d4c09348bf4
082114
--- /dev/null
082114
+++ b/extensions/libxt_SECMARK.t
082114
@@ -0,0 +1,4 @@
082114
+:INPUT,FORWARD,OUTPUT
082114
+*security
082114
+-j SECMARK --selctx system_u:object_r:firewalld_exec_t:s0;=;OK
082114
+-j SECMARK;;FAIL
082114
diff --git a/include/linux/netfilter/xt_SECMARK.h b/include/linux/netfilter/xt_SECMARK.h
082114
index 989092bd6274b..31760a286a854 100644
082114
--- a/include/linux/netfilter/xt_SECMARK.h
082114
+++ b/include/linux/netfilter/xt_SECMARK.h
082114
@@ -19,4 +19,10 @@ struct xt_secmark_target_info {
082114
 	char secctx[SECMARK_SECCTX_MAX];
082114
 };
082114
 
082114
+struct xt_secmark_target_info_v1 {
082114
+	__u8 mode;
082114
+	char secctx[SECMARK_SECCTX_MAX];
082114
+	__u32 secid;
082114
+};
082114
+
082114
 #endif /*_XT_SECMARK_H_target */
082114
-- 
082114
2.31.1
082114