Commit ce4a7d0d48bbaed78ccbb0bafb9229651a40303a

Authored by Arnaldo Carvalho de Melo
Committed by David S. Miller
1 parent 45d465bc23

inet{6}_request_sock: Init ->opt and ->pktopts in the constructor

Wei Yongjun noticed that we may call reqsk_free on request sock objects where
the opt fields may not be initialized, fix it by introducing inet_reqsk_alloc
where we initialize ->opt to NULL and set ->pktopts to NULL in
inet6_reqsk_alloc.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 8 changed files with 16 additions and 9 deletions Side-by-side Diff

include/linux/ipv6.h
... ... @@ -396,8 +396,10 @@
396 396 {
397 397 struct request_sock *req = reqsk_alloc(ops);
398 398  
399   - if (req != NULL)
  399 + if (req != NULL) {
400 400 inet_rsk(req)->inet6_rsk_offset = inet6_rsk_offset(req);
  401 + inet6_rsk(req)->pktopts = NULL;
  402 + }
401 403  
402 404 return req;
403 405 }
include/net/inet_sock.h
... ... @@ -197,5 +197,15 @@
197 197 return skb->rtable->rt_iif;
198 198 }
199 199  
  200 +static inline struct request_sock *inet_reqsk_alloc(struct request_sock_ops *ops)
  201 +{
  202 + struct request_sock *req = reqsk_alloc(ops);
  203 +
  204 + if (req != NULL)
  205 + inet_rsk(req)->opt = NULL;
  206 +
  207 + return req;
  208 +}
  209 +
200 210 #endif /* _INET_SOCK_H */
... ... @@ -589,7 +589,7 @@
589 589 if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
590 590 goto drop;
591 591  
592   - req = reqsk_alloc(&dccp_request_sock_ops);
  592 + req = inet_reqsk_alloc(&dccp_request_sock_ops);
593 593 if (req == NULL)
594 594 goto drop;
595 595  
... ... @@ -605,7 +605,6 @@
605 605 ireq = inet_rsk(req);
606 606 ireq->loc_addr = ip_hdr(skb)->daddr;
607 607 ireq->rmt_addr = ip_hdr(skb)->saddr;
608   - ireq->opt = NULL;
609 608  
610 609 /*
611 610 * Step 3: Process LISTEN state
... ... @@ -421,7 +421,6 @@
421 421 ireq6 = inet6_rsk(req);
422 422 ipv6_addr_copy(&ireq6->rmt_addr, &ipv6_hdr(skb)->saddr);
423 423 ipv6_addr_copy(&ireq6->loc_addr, &ipv6_hdr(skb)->daddr);
424   - ireq6->pktopts = NULL;
425 424  
426 425 if (ipv6_opt_accepted(sk, skb) ||
427 426 np->rxopt.bits.rxinfo || np->rxopt.bits.rxoinfo ||
net/ipv4/syncookies.c
... ... @@ -285,7 +285,7 @@
285 285 cookie_check_timestamp(&tcp_opt);
286 286  
287 287 ret = NULL;
288   - req = reqsk_alloc(&tcp_request_sock_ops); /* for safety */
  288 + req = inet_reqsk_alloc(&tcp_request_sock_ops); /* for safety */
289 289 if (!req)
290 290 goto out;
291 291  
... ... @@ -301,7 +301,6 @@
301 301 ireq->rmt_port = th->source;
302 302 ireq->loc_addr = ip_hdr(skb)->daddr;
303 303 ireq->rmt_addr = ip_hdr(skb)->saddr;
304   - ireq->opt = NULL;
305 304 ireq->snd_wscale = tcp_opt.snd_wscale;
306 305 ireq->rcv_wscale = tcp_opt.rcv_wscale;
307 306 ireq->sack_ok = tcp_opt.sack_ok;
... ... @@ -1285,7 +1285,7 @@
1285 1285 if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1)
1286 1286 goto drop;
1287 1287  
1288   - req = reqsk_alloc(&tcp_request_sock_ops);
  1288 + req = inet_reqsk_alloc(&tcp_request_sock_ops);
1289 1289 if (!req)
1290 1290 goto drop;
1291 1291  
net/ipv6/syncookies.c
... ... @@ -198,7 +198,6 @@
198 198 ireq = inet_rsk(req);
199 199 ireq6 = inet6_rsk(req);
200 200 treq = tcp_rsk(req);
201   - ireq6->pktopts = NULL;
202 201  
203 202 if (security_inet_conn_request(sk, skb, req)) {
204 203 reqsk_free(req);
... ... @@ -1299,7 +1299,6 @@
1299 1299 treq = inet6_rsk(req);
1300 1300 ipv6_addr_copy(&treq->rmt_addr, &ipv6_hdr(skb)->saddr);
1301 1301 ipv6_addr_copy(&treq->loc_addr, &ipv6_hdr(skb)->daddr);
1302   - treq->pktopts = NULL;
1303 1302 if (!want_cookie)
1304 1303 TCP_ECN_create_request(req, tcp_hdr(skb));
1305 1304