From 345d410399350a11bb7ffde3dfb4abd192808983 Mon Sep 17 00:00:00 2001 From: Krishna Kumar Date: Mon, 8 Mar 2004 23:24:55 -0800 Subject: [PATCH] [IPV4/IPV6]: Add missing kmalloc failure checks. --- net/ipv4/esp4.c | 2 ++ net/ipv4/ip_output.c | 5 ++++- net/ipv6/esp6.c | 2 ++ net/ipv6/ip6_output.c | 5 ++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index ce9eb8a326f6f..b3287b88fae01 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -518,6 +518,8 @@ int esp_init_state(struct xfrm_state *x, void *args) esp->conf.padlen = 0; if (esp->conf.ivlen) { esp->conf.ivec = kmalloc(esp->conf.ivlen, GFP_KERNEL); + if (unlikely(esp->conf.ivec == NULL)) + goto error; get_random_bytes(esp->conf.ivec, esp->conf.ivlen); } crypto_cipher_setkey(esp->conf.tfm, esp->conf.key, esp->conf.key_len); diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 80558f7b1dc87..a962a811d4ef0 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -761,8 +761,11 @@ int ip_append_data(struct sock *sk, */ opt = ipc->opt; if (opt) { - if (inet->cork.opt == NULL) + if (inet->cork.opt == NULL) { inet->cork.opt = kmalloc(sizeof(struct ip_options) + 40, sk->sk_allocation); + if (unlikely(inet->cork.opt == NULL)) + return -ENOBUFS; + } memcpy(inet->cork.opt, opt, sizeof(struct ip_options)+opt->optlen); inet->cork.flags |= IPCORK_OPT; inet->cork.addr = ipc->addr; diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index db09e37225109..ca3685bafc061 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -422,6 +422,8 @@ int esp6_init_state(struct xfrm_state *x, void *args) esp->conf.padlen = 0; if (esp->conf.ivlen) { esp->conf.ivec = kmalloc(esp->conf.ivlen, GFP_KERNEL); + if (unlikely(esp->conf.ivec == NULL)) + goto error; get_random_bytes(esp->conf.ivec, esp->conf.ivlen); } crypto_cipher_setkey(esp->conf.tfm, esp->conf.key, esp->conf.key_len); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 0b960dd56621e..6665a7f9b7d24 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -816,9 +816,12 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to, int offse * setup for corking */ if (opt) { - if (np->cork.opt == NULL) + if (np->cork.opt == NULL) { np->cork.opt = kmalloc(opt->tot_len, sk->sk_allocation); + if (unlikely(np->cork.opt == NULL)) + return -ENOBUFS; + } memcpy(np->cork.opt, opt, opt->tot_len); inet->cork.flags |= IPCORK_OPT; /* need source address above miyazawa*/ -- 2.53.0