···613613extern void audit_log_key(struct audit_buffer *ab,614614 char *key);615615extern void audit_log_lost(const char *message);616616+#ifdef CONFIG_SECURITY617617+extern void audit_log_secctx(struct audit_buffer *ab, u32 secid);618618+#else619619+#define audit_log_secctx(b,s) do { ; } while (0)620620+#endif621621+616622extern int audit_update_lsm_rules(void);617623618624 /* Private API (for audit.c only) */···641635#define audit_log_untrustedstring(a,s) do { ; } while (0)642636#define audit_log_d_path(b, p, d) do { ; } while (0)643637#define audit_log_key(b, k) do { ; } while (0)638638+#define audit_log_secctx(b,s) do { ; } while (0)644639#define audit_enabled 0645640#endif646641#endif
+72-36
include/linux/netfilter/ipset/ip_set_ahash.h
···2828/* Number of elements to store in an initial array block */2929#define AHASH_INIT_SIZE 43030/* Max number of elements to store in an array block */3131-#define AHASH_MAX_SIZE (3*4)3131+#define AHASH_MAX_SIZE (3*AHASH_INIT_SIZE)3232+3333+/* Max number of elements can be tuned */3434+#ifdef IP_SET_HASH_WITH_MULTI3535+#define AHASH_MAX(h) ((h)->ahash_max)3636+3737+static inline u83838+tune_ahash_max(u8 curr, u32 multi)3939+{4040+ u32 n;4141+4242+ if (multi < curr)4343+ return curr;4444+4545+ n = curr + AHASH_INIT_SIZE;4646+ /* Currently, at listing one hash bucket must fit into a message.4747+ * Therefore we have a hard limit here.4848+ */4949+ return n > curr && n <= 64 ? n : curr;5050+}5151+#define TUNE_AHASH_MAX(h, multi) \5252+ ((h)->ahash_max = tune_ahash_max((h)->ahash_max, multi))5353+#else5454+#define AHASH_MAX(h) AHASH_MAX_SIZE5555+#define TUNE_AHASH_MAX(h, multi)5656+#endif32573358/* A hash bucket */3459struct hbucket {···8560 u32 timeout; /* timeout value, if enabled */8661 struct timer_list gc; /* garbage collection when timeout enabled */8762 struct type_pf_next next; /* temporary storage for uadd */6363+#ifdef IP_SET_HASH_WITH_MULTI6464+ u8 ahash_max; /* max elements in an array block */6565+#endif8866#ifdef IP_SET_HASH_WITH_NETMASK8967 u8 netmask; /* netmask value for subnets to store */9068#endif···239211 set->data = NULL;240212}241213242242-#define HKEY(data, initval, htable_bits) \243243-(jhash2((u32 *)(data), sizeof(struct type_pf_elem)/sizeof(u32), initval) \244244- & jhash_mask(htable_bits))245245-246214#endif /* _IP_SET_AHASH_H */215215+216216+#ifndef HKEY_DATALEN217217+#define HKEY_DATALEN sizeof(struct type_pf_elem)218218+#endif219219+220220+#define HKEY(data, initval, htable_bits) \221221+(jhash2((u32 *)(data), HKEY_DATALEN/sizeof(u32), initval) \222222+ & jhash_mask(htable_bits))247223248224#define CONCAT(a, b, c) a##b##c249225#define TOKEN(a, b, c) CONCAT(a, b, c)···307275/* Add an element to the hash table when resizing the set:308276 * we spare the maintenance of the internal counters. */309277static int310310-type_pf_elem_add(struct hbucket *n, const struct type_pf_elem *value)278278+type_pf_elem_add(struct hbucket *n, const struct type_pf_elem *value,279279+ u8 ahash_max)311280{312281 if (n->pos >= n->size) {313282 void *tmp;314283315315- if (n->size >= AHASH_MAX_SIZE)284284+ if (n->size >= ahash_max)316285 /* Trigger rehashing */317286 return -EAGAIN;318287···368335 for (j = 0; j < n->pos; j++) {369336 data = ahash_data(n, j);370337 m = hbucket(t, HKEY(data, h->initval, htable_bits));371371- ret = type_pf_elem_add(m, data);338338+ ret = type_pf_elem_add(m, data, AHASH_MAX(h));372339 if (ret < 0) {373340 read_unlock_bh(&set->lock);374341 ahash_destroy(t);···392359 return 0;393360}394361395395-static void362362+static inline void396363type_pf_data_next(struct ip_set_hash *h, const struct type_pf_elem *d);397364398365/* Add an element to a hash and update the internal counters when succeeded,···405372 const struct type_pf_elem *d = value;406373 struct hbucket *n;407374 int i, ret = 0;408408- u32 key;375375+ u32 key, multi = 0;409376410377 if (h->elements >= h->maxelem)411378 return -IPSET_ERR_HASH_FULL;···415382 key = HKEY(value, h->initval, t->htable_bits);416383 n = hbucket(t, key);417384 for (i = 0; i < n->pos; i++)418418- if (type_pf_data_equal(ahash_data(n, i), d)) {385385+ if (type_pf_data_equal(ahash_data(n, i), d, &multi)) {419386 ret = -IPSET_ERR_EXIST;420387 goto out;421388 }422422-423423- ret = type_pf_elem_add(n, value);389389+ TUNE_AHASH_MAX(h, multi);390390+ ret = type_pf_elem_add(n, value, AHASH_MAX(h));424391 if (ret != 0) {425392 if (ret == -EAGAIN)426393 type_pf_data_next(h, d);···448415 struct hbucket *n;449416 int i;450417 struct type_pf_elem *data;451451- u32 key;418418+ u32 key, multi = 0;452419453420 key = HKEY(value, h->initval, t->htable_bits);454421 n = hbucket(t, key);455422 for (i = 0; i < n->pos; i++) {456423 data = ahash_data(n, i);457457- if (!type_pf_data_equal(data, d))424424+ if (!type_pf_data_equal(data, d, &multi))458425 continue;459426 if (i != n->pos - 1)460427 /* Not last one */···495462 struct hbucket *n;496463 const struct type_pf_elem *data;497464 int i, j = 0;498498- u32 key;465465+ u32 key, multi = 0;499466 u8 host_mask = SET_HOST_MASK(set->family);500467501468 pr_debug("test by nets\n");502502- for (; j < host_mask && h->nets[j].cidr; j++) {469469+ for (; j < host_mask && h->nets[j].cidr && !multi; j++) {503470 type_pf_data_netmask(d, h->nets[j].cidr);504471 key = HKEY(d, h->initval, t->htable_bits);505472 n = hbucket(t, key);506473 for (i = 0; i < n->pos; i++) {507474 data = ahash_data(n, i);508508- if (type_pf_data_equal(data, d))475475+ if (type_pf_data_equal(data, d, &multi))509476 return 1;510477 }511478 }···523490 struct hbucket *n;524491 const struct type_pf_elem *data;525492 int i;526526- u32 key;493493+ u32 key, multi = 0;527494528495#ifdef IP_SET_HASH_WITH_NETS529496 /* If we test an IP address and not a network address,···536503 n = hbucket(t, key);537504 for (i = 0; i < n->pos; i++) {538505 data = ahash_data(n, i);539539- if (type_pf_data_equal(data, d))506506+ if (type_pf_data_equal(data, d, &multi))540507 return 1;541508 }542509 return 0;···693660694661static int695662type_pf_elem_tadd(struct hbucket *n, const struct type_pf_elem *value,696696- u32 timeout)663663+ u8 ahash_max, u32 timeout)697664{698665 struct type_pf_elem *data;699666700667 if (n->pos >= n->size) {701668 void *tmp;702669703703- if (n->size >= AHASH_MAX_SIZE)670670+ if (n->size >= ahash_max)704671 /* Trigger rehashing */705672 return -EAGAIN;706673···805772 for (j = 0; j < n->pos; j++) {806773 data = ahash_tdata(n, j);807774 m = hbucket(t, HKEY(data, h->initval, htable_bits));808808- ret = type_pf_elem_tadd(m, data,775775+ ret = type_pf_elem_tadd(m, data, AHASH_MAX(h),809776 type_pf_data_timeout(data));810777 if (ret < 0) {811778 read_unlock_bh(&set->lock);···836803 const struct type_pf_elem *d = value;837804 struct hbucket *n;838805 struct type_pf_elem *data;839839- int ret = 0, i, j = AHASH_MAX_SIZE + 1;806806+ int ret = 0, i, j = AHASH_MAX(h) + 1;840807 bool flag_exist = flags & IPSET_FLAG_EXIST;841841- u32 key;808808+ u32 key, multi = 0;842809843810 if (h->elements >= h->maxelem)844811 /* FIXME: when set is full, we slow down here */···852819 n = hbucket(t, key);853820 for (i = 0; i < n->pos; i++) {854821 data = ahash_tdata(n, i);855855- if (type_pf_data_equal(data, d)) {822822+ if (type_pf_data_equal(data, d, &multi)) {856823 if (type_pf_data_expired(data) || flag_exist)857824 j = i;858825 else {859826 ret = -IPSET_ERR_EXIST;860827 goto out;861828 }862862- } else if (j == AHASH_MAX_SIZE + 1 &&829829+ } else if (j == AHASH_MAX(h) + 1 &&863830 type_pf_data_expired(data))864831 j = i;865832 }866866- if (j != AHASH_MAX_SIZE + 1) {833833+ if (j != AHASH_MAX(h) + 1) {867834 data = ahash_tdata(n, j);868835#ifdef IP_SET_HASH_WITH_NETS869836 del_cidr(h, data->cidr, HOST_MASK);···873840 type_pf_data_timeout_set(data, timeout);874841 goto out;875842 }876876- ret = type_pf_elem_tadd(n, d, timeout);843843+ TUNE_AHASH_MAX(h, multi);844844+ ret = type_pf_elem_tadd(n, d, AHASH_MAX(h), timeout);877845 if (ret != 0) {878846 if (ret == -EAGAIN)879847 type_pf_data_next(h, d);···899865 struct hbucket *n;900866 int i;901867 struct type_pf_elem *data;902902- u32 key;868868+ u32 key, multi = 0;903869904870 key = HKEY(value, h->initval, t->htable_bits);905871 n = hbucket(t, key);906872 for (i = 0; i < n->pos; i++) {907873 data = ahash_tdata(n, i);908908- if (!type_pf_data_equal(data, d))874874+ if (!type_pf_data_equal(data, d, &multi))909875 continue;910876 if (type_pf_data_expired(data))911877 return -IPSET_ERR_EXIST;···945911 struct type_pf_elem *data;946912 struct hbucket *n;947913 int i, j = 0;948948- u32 key;914914+ u32 key, multi = 0;949915 u8 host_mask = SET_HOST_MASK(set->family);950916951951- for (; j < host_mask && h->nets[j].cidr; j++) {917917+ for (; j < host_mask && h->nets[j].cidr && !multi; j++) {952918 type_pf_data_netmask(d, h->nets[j].cidr);953919 key = HKEY(d, h->initval, t->htable_bits);954920 n = hbucket(t, key);955921 for (i = 0; i < n->pos; i++) {956922 data = ahash_tdata(n, i);957957- if (type_pf_data_equal(data, d))923923+ if (type_pf_data_equal(data, d, &multi))958924 return !type_pf_data_expired(data);959925 }960926 }···970936 struct type_pf_elem *data, *d = value;971937 struct hbucket *n;972938 int i;973973- u32 key;939939+ u32 key, multi = 0;974940975941#ifdef IP_SET_HASH_WITH_NETS976942 if (d->cidr == SET_HOST_MASK(set->family))···980946 n = hbucket(t, key);981947 for (i = 0; i < n->pos; i++) {982948 data = ahash_tdata(n, i);983983- if (type_pf_data_equal(data, d))949949+ if (type_pf_data_equal(data, d, &multi))984950 return !type_pf_data_expired(data);985951 }986952 return 0;···10881054 IPSET_GC_PERIOD(h->timeout));10891055}1090105610571057+#undef HKEY_DATALEN10581058+#undef HKEY10911059#undef type_pf_data_equal10921060#undef type_pf_data_isnull10931061#undef type_pf_data_copy
···88 NFQNL_MSG_PACKET, /* packet from kernel to userspace */99 NFQNL_MSG_VERDICT, /* verdict from userspace to kernel */1010 NFQNL_MSG_CONFIG, /* connect to a particular queue */1111+ NFQNL_MSG_VERDICT_BATCH, /* batchv from userspace to kernel */11121213 NFQNL_MSG_MAX1314};
+29
kernel/audit.c
···5555#include <net/sock.h>5656#include <net/netlink.h>5757#include <linux/skbuff.h>5858+#ifdef CONFIG_SECURITY5959+#include <linux/security.h>6060+#endif5861#include <linux/netlink.h>5962#include <linux/freezer.h>6063#include <linux/tty.h>···15041501 audit_log_end(ab);15051502 }15061503}15041504+15051505+#ifdef CONFIG_SECURITY15061506+/**15071507+ * audit_log_secctx - Converts and logs SELinux context15081508+ * @ab: audit_buffer15091509+ * @secid: security number15101510+ *15111511+ * This is a helper function that calls security_secid_to_secctx to convert15121512+ * secid to secctx and then adds the (converted) SELinux context to the audit15131513+ * log by calling audit_log_format, thus also preventing leak of internal secid15141514+ * to userspace. If secid cannot be converted audit_panic is called.15151515+ */15161516+void audit_log_secctx(struct audit_buffer *ab, u32 secid)15171517+{15181518+ u32 len;15191519+ char *secctx;15201520+15211521+ if (security_secid_to_secctx(secid, &secctx, &len)) {15221522+ audit_panic("Cannot convert secid to context");15231523+ } else {15241524+ audit_log_format(ab, " obj=%s", secctx);15251525+ security_release_secctx(secctx, len);15261526+ }15271527+}15281528+EXPORT_SYMBOL(audit_log_secctx);15291529+#endif1507153015081531EXPORT_SYMBOL(audit_log_start);15091532EXPORT_SYMBOL(audit_log_end);