summaryrefslogtreecommitdiffstats
path: root/sys/netinet
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2011-04-18 20:07:08 +0000
committerglebius <glebius@FreeBSD.org>2011-04-18 20:07:08 +0000
commit53a0fd8ac354d0c7779815e2ef3aeeaec9ceee0f (patch)
treef4352a5958a7b8f9b17e2c8cf3b91ba8f8a3cda9 /sys/netinet
parent3ba2f4e3f25cf378d2dc011328cd7950c6af5b2f (diff)
downloadFreeBSD-src-53a0fd8ac354d0c7779815e2ef3aeeaec9ceee0f.zip
FreeBSD-src-53a0fd8ac354d0c7779815e2ef3aeeaec9ceee0f.tar.gz
LibAliasInit() should allocate memory with M_WAITOK flag. Modify it
and its callers.
Diffstat (limited to 'sys/netinet')
-rw-r--r--sys/netinet/ipfw/ip_fw_nat.c21
-rw-r--r--sys/netinet/libalias/alias_db.c5
2 files changed, 12 insertions, 14 deletions
diff --git a/sys/netinet/ipfw/ip_fw_nat.c b/sys/netinet/ipfw/ip_fw_nat.c
index 6f223ed..f5f1374 100644
--- a/sys/netinet/ipfw/ip_fw_nat.c
+++ b/sys/netinet/ipfw/ip_fw_nat.c
@@ -359,28 +359,17 @@ ipfw_nat_cfg(struct sockopt *sopt)
IPFW_WLOCK(chain);
ptr = lookup_nat(&chain->nat, ser_n->id);
if (ptr == NULL) {
+ IPFW_WUNLOCK(chain);
/* New rule: allocate and init new instance. */
- ptr = malloc(sizeof(struct cfg_nat),
- M_IPFW, M_NOWAIT | M_ZERO);
- if (ptr == NULL) {
- IPFW_WUNLOCK(chain);
- free(buf, M_IPFW);
- return (ENOSPC);
- }
+ ptr = malloc(sizeof(struct cfg_nat), M_IPFW, M_WAITOK | M_ZERO);
ptr->lib = LibAliasInit(NULL);
- if (ptr->lib == NULL) {
- IPFW_WUNLOCK(chain);
- free(ptr, M_IPFW);
- free(buf, M_IPFW);
- return (EINVAL);
- }
LIST_INIT(&ptr->redir_chain);
} else {
/* Entry already present: temporarly unhook it. */
LIST_REMOVE(ptr, _next);
flush_nat_ptrs(chain, ser_n->id);
+ IPFW_WUNLOCK(chain);
}
- IPFW_WUNLOCK(chain);
/*
* Basic nat configuration.
@@ -407,6 +396,10 @@ ipfw_nat_cfg(struct sockopt *sopt)
add_redir_spool_cfg(&buf[(sizeof(struct cfg_nat))], ptr);
free(buf, M_IPFW);
IPFW_WLOCK(chain);
+ /*
+ * XXXGL race here: another ipfw_nat_cfg() may already inserted
+ * entry with the same ser_n->id.
+ */
LIST_INSERT_HEAD(&chain->nat, ptr, _next);
IPFW_WUNLOCK(chain);
return (0);
diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c
index 09b8513..9b30793 100644
--- a/sys/netinet/libalias/alias_db.c
+++ b/sys/netinet/libalias/alias_db.c
@@ -2490,9 +2490,14 @@ LibAliasInit(struct libalias *la)
#endif
if (la == NULL) {
+#ifdef _KERNEL
+#undef malloc /* XXX: ugly */
+ la = malloc(sizeof *la, M_ALIAS, M_WAITOK | M_ZERO);
+#else
la = calloc(sizeof *la, 1);
if (la == NULL)
return (la);
+#endif
#ifndef _KERNEL /* kernel cleans up on module unload */
if (LIST_EMPTY(&instancehead))
OpenPOWER on IntegriCloud