Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F111525282
D31111.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D31111.diff
View Options
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -2878,6 +2878,8 @@
struct pf_kstate *s;
struct pf_state_export *pstore, *p;
int i, nr;
+ size_t slice_count = 16, count;
+ void *out;
if (ps->ps_req_version > PF_STATE_VERSION) {
error = ENOTSUP;
@@ -2890,38 +2892,60 @@
break;
}
- p = pstore = malloc(ps->ps_len, M_TEMP, M_WAITOK | M_ZERO);
+ out = ps->ps_states;
+ pstore = mallocarray(slice_count,
+ sizeof(struct pf_state_export), M_TEMP, M_WAITOK | M_ZERO);
nr = 0;
for (i = 0; i <= pf_hashmask; i++) {
struct pf_idhash *ih = &V_pf_idhash[i];
+DIOCGETSTATESV2_retry:
+ p = pstore;
+
if (LIST_EMPTY(&ih->states))
continue;
PF_HASHROW_LOCK(ih);
+ count = 0;
+ LIST_FOREACH(s, &ih->states, entry) {
+ if (s->timeout == PFTM_UNLINKED)
+ continue;
+ count++;
+ }
+
+ if (count > slice_count) {
+ PF_HASHROW_UNLOCK(ih);
+ free(pstore, M_TEMP);
+ slice_count = count * 2;
+ pstore = mallocarray(slice_count,
+ sizeof(struct pf_state_export), M_TEMP,
+ M_WAITOK | M_ZERO);
+ goto DIOCGETSTATESV2_retry;
+ }
+
+ if ((nr+count) * sizeof(*p) > ps->ps_len) {
+ PF_HASHROW_UNLOCK(ih);
+ goto DIOCGETSTATESV2_full;
+ }
+
LIST_FOREACH(s, &ih->states, entry) {
if (s->timeout == PFTM_UNLINKED)
continue;
- if ((nr+1) * sizeof(*p) > ps->ps_len) {
- PF_HASHROW_UNLOCK(ih);
- goto DIOCGETSTATESV2_full;
- }
pf_state_export(p, s);
p++;
nr++;
}
PF_HASHROW_UNLOCK(ih);
+ error = copyout(pstore, out,
+ sizeof(struct pf_state_export) * count);
+ if (error)
+ break;
+ out = ps->ps_states + nr;
}
DIOCGETSTATESV2_full:
- error = copyout(pstore, ps->ps_states,
- sizeof(struct pf_state_export) * nr);
- if (error) {
- free(pstore, M_TEMP);
- break;
- }
- ps->ps_len = sizeof(struct pf_state_export) * nr;
+ ps->ps_len = nr * sizeof(struct pf_state_export);
free(pstore, M_TEMP);
break;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Mar 5, 8:15 PM (17 h, 42 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16999638
Default Alt Text
D31111.diff (2 KB)
Attached To
Mode
D31111: pf: bound DIOCGETSTATESV2 memory use
Attached
Detach File
Event Timeline
Log In to Comment