Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107169158
D13755.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D13755.diff
View Options
Index: head/sys/contrib/ipfilter/netinet/ip_state.c
===================================================================
--- head/sys/contrib/ipfilter/netinet/ip_state.c
+++ head/sys/contrib/ipfilter/netinet/ip_state.c
@@ -301,7 +301,33 @@
KFREE(softs);
}
+static void *
+ipf_state_seed_alloc(u_int state_size, u_int state_max)
+{
+ u_int i;
+ u_long *state_seed;
+ KMALLOCS(state_seed, u_long *, state_size * sizeof(*state_seed));
+ if (state_seed == NULL)
+ return NULL;
+ for (i = 0; i < state_size; i++) {
+ /*
+ * XXX - ipf_state_seed[X] should be a random number of sorts.
+ */
+#if FREEBSD_GE_REV(400000)
+ state_seed[i] = arc4random();
+#else
+ state_seed[i] = ((u_long)state_seed + i) * state_size;
+ state_seed[i] ^= 0xa5a55a5a;
+ state_seed[i] *= (u_long)state_seed;
+ state_seed[i] ^= 0x5a5aa5a5;
+ state_seed[i] *= state_max;
+#endif
+ }
+ return state_seed;
+}
+
+
/* ------------------------------------------------------------------------ */
/* Function: ipf_state_soft_init */
/* Returns: int - 0 == success, -1 == failure */
@@ -333,27 +359,11 @@
bzero((char *)softs->ipf_state_table,
softs->ipf_state_size * sizeof(ipstate_t *));
- KMALLOCS(softs->ipf_state_seed, u_long *,
- softs->ipf_state_size * sizeof(*softs->ipf_state_seed));
+ softs->ipf_state_seed = ipf_state_seed_alloc(softs->ipf_state_size,
+ softs->ipf_state_max);
if (softs->ipf_state_seed == NULL)
return -2;
- for (i = 0; i < softs->ipf_state_size; i++) {
- /*
- * XXX - ipf_state_seed[X] should be a random number of sorts.
- */
-#if FREEBSD_GE_REV(400000)
- softs->ipf_state_seed[i] = arc4random();
-#else
- softs->ipf_state_seed[i] = ((u_long)softs->ipf_state_seed + i) *
- softs->ipf_state_size;
- softs->ipf_state_seed[i] ^= 0xa5a55a5a;
- softs->ipf_state_seed[i] *= (u_long)softs->ipf_state_seed;
- softs->ipf_state_seed[i] ^= 0x5a5aa5a5;
- softs->ipf_state_seed[i] *= softs->ipf_state_max;
-#endif
- }
-
KMALLOCS(softs->ipf_state_stats.iss_bucketlen, u_int *,
softs->ipf_state_size * sizeof(u_int));
if (softs->ipf_state_stats.iss_bucketlen == NULL)
@@ -5259,6 +5269,7 @@
{
ipf_state_softc_t *softs = softc->ipf_state_soft;
ipstate_t **newtab, *is;
+ u_long *newseed;
u_int *bucketlens;
u_int maxbucket;
u_int newsize;
@@ -5285,6 +5296,14 @@
return ENOMEM;
}
+ newseed = ipf_state_seed_alloc(newsize, softs->ipf_state_max);
+ if (newseed == NULL) {
+ KFREES(bucketlens, newsize * sizeof(*bucketlens));
+ KFREES(newtab, newsize * sizeof(*newtab));
+ IPFERROR(100037);
+ return ENOMEM;
+ }
+
for (maxbucket = 0, i = newsize; i > 0; i >>= 1)
maxbucket++;
maxbucket *= 2;
@@ -5299,6 +5318,12 @@
softs->ipf_state_size * sizeof(*softs->ipf_state_table));
}
softs->ipf_state_table = newtab;
+
+ if (softs->ipf_state_seed != NULL) {
+ KFREES(softs->ipf_state_seed,
+ softs->ipf_state_size * sizeof(*softs->ipf_state_seed));
+ }
+ softs->ipf_state_seed = newseed;
if (softs->ipf_state_stats.iss_bucketlen != NULL) {
KFREES(softs->ipf_state_stats.iss_bucketlen,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 12, 4:33 AM (21 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15761177
Default Alt Text
D13755.diff (3 KB)
Attached To
Mode
D13755: Resolve ipfilter seed array size panic
Attached
Detach File
Event Timeline
Log In to Comment