diff options
author | ae <ae@FreeBSD.org> | 2015-04-27 00:55:56 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2015-04-27 00:55:56 +0000 |
commit | 5a6412a276aa9e59126f47bf366d7cff42bddcd5 (patch) | |
tree | 69ed8ff32c5ce1941c4e9992ae2fdae2769906bb /sys/netinet6/ip6_ipsec.c | |
parent | e38c3c47b06f715b9776382e7402247822243212 (diff) | |
download | FreeBSD-src-5a6412a276aa9e59126f47bf366d7cff42bddcd5.zip FreeBSD-src-5a6412a276aa9e59126f47bf366d7cff42bddcd5.tar.gz |
Fix possible use after free due to security policy deletion.
When we are passing mbuf to IPSec processing via ipsec[46]_process_packet(),
we hold one reference to security policy and release it just after return
from this function. But IPSec processing can be deffered and when we release
reference to security policy after ipsec[46]_process_packet(), user can
delete this security policy from SPDB. And when IPSec processing will be
done, xform's callback function will do access to already freed memory.
To fix this move KEY_FREESP() into callback function. Now IPSec code will
release reference to SP after processing will be finished.
Differential Revision: https://reviews.freebsd.org/D2324
No objections from: #network
Sponsored by: Yandex LLC
Diffstat (limited to 'sys/netinet6/ip6_ipsec.c')
-rw-r--r-- | sys/netinet6/ip6_ipsec.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/sys/netinet6/ip6_ipsec.c b/sys/netinet6/ip6_ipsec.c index 0a416cd..c5f7a82 100644 --- a/sys/netinet6/ip6_ipsec.c +++ b/sys/netinet6/ip6_ipsec.c @@ -213,7 +213,9 @@ ip6_ipsec_output(struct mbuf **m, struct inpcb *inp, int *error) /* NB: callee frees mbuf */ *error = ipsec6_process_packet(*m, sp->req); - + /* Release SP if an error occured */ + if (*error != 0) + KEY_FREESP(&sp); if (*error == EJUSTRETURN) { /* * We had a SP with a level of 'use' and no SA. We @@ -253,9 +255,7 @@ done: KEY_FREESP(&sp); return 0; reinjected: - if (sp != NULL) - KEY_FREESP(&sp); - return -1; + return (-1); bad: if (sp != NULL) KEY_FREESP(&sp); |