1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-02 12:20:51 +00:00

o Plug memory leak in syncache_add() on MAC label allocation failure.

o Simplify code flow with 'done' goto label.
o Remove mbuf argument from syncache_respond().  It doesn't make use
  of it.
This commit is contained in:
Andre Oppermann 2007-04-20 13:30:08 +00:00
parent dcac077f4b
commit c73f70b728
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=168900

View File

@ -160,7 +160,7 @@ static void syncache_drop(struct syncache *, struct syncache_head *);
static void syncache_free(struct syncache *); static void syncache_free(struct syncache *);
static void syncache_insert(struct syncache *, struct syncache_head *); static void syncache_insert(struct syncache *, struct syncache_head *);
struct syncache *syncache_lookup(struct in_conninfo *, struct syncache_head **); struct syncache *syncache_lookup(struct in_conninfo *, struct syncache_head **);
static int syncache_respond(struct syncache *, struct mbuf *); static int syncache_respond(struct syncache *);
static struct socket *syncache_socket(struct syncache *, struct socket *, static struct socket *syncache_socket(struct syncache *, struct socket *,
struct mbuf *m); struct mbuf *m);
static void syncache_timer(void *); static void syncache_timer(void *);
@ -403,7 +403,7 @@ syncache_timer(void *xsch)
continue; continue;
} }
(void) syncache_respond(sc, NULL); (void) syncache_respond(sc);
tcpstat.tcps_sc_retransmitted++; tcpstat.tcps_sc_retransmitted++;
SYNCACHE_TIMEOUT(sc, sch, 0); SYNCACHE_TIMEOUT(sc, sch, 0);
} }
@ -890,10 +890,9 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
#ifdef MAC #ifdef MAC
if (mac_init_syncache(&maclabel) != 0) { if (mac_init_syncache(&maclabel) != 0) {
*lsop = NULL;
INP_UNLOCK(inp); INP_UNLOCK(inp);
INP_INFO_WUNLOCK(&tcbinfo); INP_INFO_WUNLOCK(&tcbinfo);
return (1); goto done;
} else } else
mac_init_syncache_from_inpcb(maclabel, inp); mac_init_syncache_from_inpcb(maclabel, inp);
#endif #endif
@ -943,7 +942,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
KASSERT(sc->sc_label != NULL, KASSERT(sc->sc_label != NULL,
("%s: label not initialized", __func__)); ("%s: label not initialized", __func__));
#endif #endif
if (syncache_respond(sc, m) == 0) { if (syncache_respond(sc) == 0) {
SYNCACHE_TIMEOUT(sc, sch, 1); SYNCACHE_TIMEOUT(sc, sch, 1);
tcpstat.tcps_sndacks++; tcpstat.tcps_sndacks++;
tcpstat.tcps_sndtotal++; tcpstat.tcps_sndtotal++;
@ -1071,36 +1070,34 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th,
/* /*
* Do a standard 3-way handshake. * Do a standard 3-way handshake.
*/ */
if (syncache_respond(sc, m) == 0) { if (syncache_respond(sc) == 0) {
if (tcp_syncookies && tcp_syncookiesonly && sc != &scs) if (tcp_syncookies && tcp_syncookiesonly && sc != &scs)
syncache_free(sc); syncache_free(sc);
else if (sc != &scs) else if (sc != &scs)
syncache_insert(sc, sch); /* locks and unlocks sch */ syncache_insert(sc, sch); /* locks and unlocks sch */
#ifdef MAC
else
mac_destroy_syncache(&sc->sc_label);
#endif
tcpstat.tcps_sndacks++; tcpstat.tcps_sndacks++;
tcpstat.tcps_sndtotal++; tcpstat.tcps_sndtotal++;
} else { } else {
if (sc != &scs) if (sc != &scs)
syncache_free(sc); syncache_free(sc);
#ifdef MAC
else
mac_destroy_syncache(&sc->sc_label);
#endif
tcpstat.tcps_sc_dropped++; tcpstat.tcps_sc_dropped++;
} }
done: done:
#ifdef MAC
if (sc == &scs)
mac_destroy_syncache(&maclabel);
#endif
*lsop = NULL; *lsop = NULL;
m_freem(m);
return (1); return (1);
} }
static int static int
syncache_respond(struct syncache *sc, struct mbuf *m) syncache_respond(struct syncache *sc)
{ {
struct ip *ip = NULL; struct ip *ip = NULL;
struct mbuf *m;
struct tcphdr *th; struct tcphdr *th;
int optlen, error; int optlen, error;
u_int16_t hlen, tlen, mssopt; u_int16_t hlen, tlen, mssopt;
@ -1126,9 +1123,6 @@ syncache_respond(struct syncache *sc, struct mbuf *m)
("syncache: mbuf too small")); ("syncache: mbuf too small"));
/* Create the IP+TCP header from scratch. */ /* Create the IP+TCP header from scratch. */
if (m)
m_freem(m);
m = m_gethdr(M_DONTWAIT, MT_DATA); m = m_gethdr(M_DONTWAIT, MT_DATA);
if (m == NULL) if (m == NULL)
return (ENOBUFS); return (ENOBUFS);