eBPF-based security platform
upatch: drop the policy unlabel section nothing builds
Daniel Borkmannf6a9831d75fb
diff --git a/include/shirudo/upatch.h b/include/shirudo/upatch.hindex bb30a063..3274c1a0 100644--- a/include/shirudo/upatch.h+++ b/include/shirudo/upatch.h@@ -82,12 +82,10 @@ enum upatch_section_tag {UPATCH_SECTION_UNLOAD = 0x444c4e55u, /* "UNLD" le */UPATCH_SECTION_DECODERS = 0x42444344u, /* "DCDB" le */UPATCH_SECTION_POLICY_LABELS = 0x4c504853u, /* "SHPL" le */- UPATCH_SECTION_POLICY_UNLABELS = 0x554c5053u, /* "SPLU" le */};#define UPATCH_POLICY_LABELS_MAGIC 0x4c504853u /* "SHPL" le */#define UPATCH_POLICY_LABELS_VERSION 1u-#define UPATCH_POLICY_UNLABELS_VERSION 1u#define UPATCH_MAPS_MAX 64u#define UPATCH_POLICY_NAME_MAX 64u#define UPATCH_POLICY_PATH_MAX 4096udiff --git a/util/upatch.c b/util/upatch.cindex 2c1aaeaa..6029fd28 100644--- a/util/upatch.c+++ b/util/upatch.c@@ -121,49 +121,37 @@ static bool has_nul(const char *s, size_t n)}static bool parse_policy_labels(const __u8 *p, __u32 len, __u32 nr_maps,- bool bind_policy_maps, __u32 *map_idx,- __u32 *socket_map_idx)+ __u32 *map_idx, __u32 *socket_map_idx){- __u32 count, version, idx, socket_idx;struct upatch_policy_label_header h;struct upatch_policy_label_entry e;- __u32 header_len = bind_policy_maps ? sizeof(h) :- offsetof(struct upatch_policy_label_header,- socket_policy_map_idx);+ __u32 count, idx, socket_idx;- if (len < header_len)+ if (len < sizeof(h))return false;- memset(&h, 0, sizeof(h));- memcpy(&h, p, header_len);+ memcpy(&h, p, sizeof(h));count = le32_to_cpu(h.count);- version = le32_to_cpu(h.version);idx = le32_to_cpu(h.policy_map_idx);socket_idx = le32_to_cpu(h.socket_policy_map_idx);if (le32_to_cpu(h.magic) != UPATCH_POLICY_LABELS_MAGIC ||- version != (bind_policy_maps ?- UPATCH_POLICY_LABELS_VERSION :- UPATCH_POLICY_UNLABELS_VERSION) ||- (bind_policy_maps &&- (idx >= nr_maps || idx >= UPATCH_MAPS_MAX ||- socket_idx >= nr_maps ||- socket_idx >= UPATCH_MAPS_MAX || idx == socket_idx)) ||- (!bind_policy_maps && (idx || socket_idx)) || !count ||- size_add(header_len, size_mul(count, sizeof(e))) != len)+ le32_to_cpu(h.version) != UPATCH_POLICY_LABELS_VERSION ||+ idx >= nr_maps || idx >= UPATCH_MAPS_MAX ||+ socket_idx >= nr_maps || socket_idx >= UPATCH_MAPS_MAX ||+ idx == socket_idx || !count ||+ size_add(sizeof(h), size_mul(count, sizeof(e))) != len)return false;for (__u32 i = 0; i < count; i++) {__u64 bit;- memcpy(&e, p + header_len + i * sizeof(e), sizeof(e));+ memcpy(&e, p + sizeof(h) + i * sizeof(e), sizeof(e));bit = le64_to_cpu(e.bit);if (!bit || (bit & (bit - 1)) ||!has_nul(e.policy, sizeof(e.policy)) || !e.policy[0] ||!has_nul(e.path, sizeof(e.path)) || e.path[0] != '/')return false;}- if (bind_policy_maps) {- *map_idx = idx;- *socket_map_idx = socket_idx;- }+ *map_idx = idx;+ *socket_map_idx = socket_idx;return true;}@@ -235,8 +223,6 @@ static void forget_signed_sections(struct upatch *u)u->signed_policy_labels_len = 0;u->signed_policy_map_idx = 0;u->signed_socket_policy_map_idx = 0;- u->signed_policy_unlabels = NULL;- u->signed_policy_unlabels_len = 0;}/*@@ -308,21 +294,12 @@ static void parse_signed_sections(struct upatch *u)case UPATCH_SECTION_POLICY_LABELS:bit = 16;if (!parse_policy_labels(data + off, len, u->hdr.nr_maps,- true,&u->signed_policy_map_idx,&u->signed_socket_policy_map_idx))goto reject;u->signed_policy_labels = data + off;u->signed_policy_labels_len = len;break;- case UPATCH_SECTION_POLICY_UNLABELS:- bit = 32;- if (!parse_policy_labels(data + off, len, u->hdr.nr_maps,- false, NULL, NULL))- goto reject;- u->signed_policy_unlabels = data + off;- u->signed_policy_unlabels_len = len;- break;default:goto reject;}@@ -441,13 +418,6 @@ const void *upatch_signed_policy_labels(const struct upatch *u,return u->map ? u->signed_policy_labels : NULL;}-const void *upatch_signed_policy_unlabels(const struct upatch *u,- __u32 *len)-{- *len = u->map ? u->signed_policy_unlabels_len : 0;- return u->map ? u->signed_policy_unlabels : NULL;-}-const void *upatch_loader(const struct upatch *u){if (!u->map)diff --git a/util/upatch.h b/util/upatch.hindex 5b429be3..505bd9c9 100644--- a/util/upatch.h+++ b/util/upatch.h@@ -58,8 +58,6 @@ struct upatch {__u32 signed_policy_labels_len;__u32 signed_policy_map_idx;__u32 signed_socket_policy_map_idx;- const void *signed_policy_unlabels;- __u32 signed_policy_unlabels_len;};struct upatch_decoder_view {@@ -116,9 +114,6 @@ const __u8 *upatch_signed_unload_payload(const struct upatch *u);const void *upatch_signed_policy_labels(const struct upatch *u,__u32 *len);-const void *upatch_signed_policy_unlabels(const struct upatch *u,- __u32 *len);-/** Validate an externally-provided upatch name: non-empty, doesn't* start with '.', and matches [A-Za-z0-9._-]+. Rejects anything that