From patchwork Tue Apr 25 15:52:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 9698699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1CBAD60224 for ; Tue, 25 Apr 2017 15:53:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BB722862A for ; Tue, 25 Apr 2017 15:53:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 007F628630; Tue, 25 Apr 2017 15:53:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id BF0D72862A for ; Tue, 25 Apr 2017 15:53:03 +0000 (UTC) Received: (qmail 31788 invoked by uid 550); 25 Apr 2017 15:52:44 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 30002 invoked from network); 25 Apr 2017 15:52:33 -0000 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=zx2c4.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=mail; bh=RvxL +p0FjbH6peJoFN9Z7x4OFPA=; b=qZXDyUQ8h2EBtmgRBt11w3AIcjvZ0MYrhN4j 3PiMd7YwQY8j5YHfHQWBQphVG/iEg/i06plc91Moqh95EA2evPgPwpm2TgJUBe/W yeL0a5tdX0FVN16vzsMxXMPgaefDSEcVRTdBg1mdFuxsvipVPk5nzD01BAnq8zZi /JfLdnTHC7cKL/nu2ggmc0PNhryV7s4bYqJz6vXps7UealaYfmApMQbjS4xQlKTi 3wpE1JL0CidgMIZcJnlZcidReBJKjze6M0pL8XwSbLIvBckGTwYVqGhkv2c8arD1 806S+SAh5u3lVEtvuwgiG6h5LVJKDhs9uJm8BEqUqhPwiN/rwQ== From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, David.Laight@aculab.com, kernel-hardening@lists.openwall.com, davem@davemloft.net Cc: "Jason A. Donenfeld" Date: Tue, 25 Apr 2017 17:52:12 +0200 Message-Id: <20170425155215.4835-2-Jason@zx2c4.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170425155215.4835-1-Jason@zx2c4.com> References: <20170425.111717.1973239615715123840.davem@davemloft.net> <20170425155215.4835-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH v5 2/5] ipsec: check return value of skb_to_sgvec always X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jason A. Donenfeld --- net/ipv4/ah4.c | 8 ++++++-- net/ipv4/esp4.c | 30 ++++++++++++++++++++---------- net/ipv6/ah6.c | 8 ++++++-- net/ipv6/esp6.c | 31 +++++++++++++++++++++---------- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c index 22377c8ff14b..e8f862358518 100644 --- a/net/ipv4/ah4.c +++ b/net/ipv4/ah4.c @@ -220,7 +220,9 @@ static int ah_output(struct xfrm_state *x, struct sk_buff *skb) ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low); sg_init_table(sg, nfrags + sglists); - skb_to_sgvec_nomark(skb, sg, 0, skb->len); + err = skb_to_sgvec_nomark(skb, sg, 0, skb->len); + if (unlikely(err < 0)) + goto out_free; if (x->props.flags & XFRM_STATE_ESN) { /* Attach seqhi sg right after packet payload */ @@ -393,7 +395,9 @@ static int ah_input(struct xfrm_state *x, struct sk_buff *skb) skb_push(skb, ihl); sg_init_table(sg, nfrags + sglists); - skb_to_sgvec_nomark(skb, sg, 0, skb->len); + err = skb_to_sgvec_nomark(skb, sg, 0, skb->len); + if (unlikely(err < 0)) + goto out_free; if (x->props.flags & XFRM_STATE_ESN) { /* Attach seqhi sg right after packet payload */ diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index b1e24446e297..42cb09cc8533 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -360,9 +360,13 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) esph = esp_output_set_extra(skb, esph, extra); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, sg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); + if (unlikely(err < 0)) { + spin_unlock_bh(&x->lock); + goto error; + } allocsize = ALIGN(skb->data_len, L1_CACHE_BYTES); @@ -381,11 +385,13 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) pfrag->offset = pfrag->offset + allocsize; sg_init_table(dsg, skb_shinfo(skb)->nr_frags + 1); - skb_to_sgvec(skb, dsg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, dsg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); spin_unlock_bh(&x->lock); + if (unlikely(err < 0)) + goto error; goto skip_cow2; } @@ -422,9 +428,11 @@ static int esp_output(struct xfrm_state *x, struct sk_buff *skb) esph = esp_output_set_extra(skb, esph, extra); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, sg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); + if (unlikely(err < 0)) + goto error; skip_cow2: if ((x->props.flags & XFRM_STATE_ESN)) @@ -658,7 +666,9 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb) esp_input_set_header(skb, seqhi); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, 0, skb->len); + err = skb_to_sgvec(skb, sg, 0, skb->len); + if (unlikely(err < 0)) + goto out; skb->ip_summed = CHECKSUM_NONE; diff --git a/net/ipv6/ah6.c b/net/ipv6/ah6.c index dda6035e3b84..755f38271dd5 100644 --- a/net/ipv6/ah6.c +++ b/net/ipv6/ah6.c @@ -423,7 +423,9 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb) ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output.low); sg_init_table(sg, nfrags + sglists); - skb_to_sgvec_nomark(skb, sg, 0, skb->len); + err = skb_to_sgvec_nomark(skb, sg, 0, skb->len); + if (unlikely(err < 0)) + goto out_free; if (x->props.flags & XFRM_STATE_ESN) { /* Attach seqhi sg right after packet payload */ @@ -606,7 +608,9 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb) ip6h->hop_limit = 0; sg_init_table(sg, nfrags + sglists); - skb_to_sgvec_nomark(skb, sg, 0, skb->len); + err = skb_to_sgvec_nomark(skb, sg, 0, skb->len); + if (unlikely(err < 0)) + goto out_free; if (x->props.flags & XFRM_STATE_ESN) { /* Attach seqhi sg right after packet payload */ diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index ff54faa75631..017e2c2d36e1 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -339,9 +339,13 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) esph = esp_output_set_esn(skb, esph, seqhi); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, sg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); + if (unlikely(err < 0)) { + spin_unlock_bh(&x->lock); + goto error; + } allocsize = ALIGN(skb->data_len, L1_CACHE_BYTES); @@ -360,12 +364,15 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) pfrag->offset = pfrag->offset + allocsize; sg_init_table(dsg, skb_shinfo(skb)->nr_frags + 1); - skb_to_sgvec(skb, dsg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, dsg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); spin_unlock_bh(&x->lock); + if (unlikely(err < 0)) + goto error; + goto skip_cow2; } } @@ -403,9 +410,11 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb) esph = esp_output_set_esn(skb, esph, seqhi); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, - (unsigned char *)esph - skb->data, - assoclen + ivlen + clen + alen); + err = skb_to_sgvec(skb, sg, + (unsigned char *)esph - skb->data, + assoclen + ivlen + clen + alen); + if (unlikely(err < 0)) + goto error; skip_cow2: if ((x->props.flags & XFRM_STATE_ESN)) @@ -600,7 +609,9 @@ static int esp6_input(struct xfrm_state *x, struct sk_buff *skb) esp_input_set_header(skb, seqhi); sg_init_table(sg, nfrags); - skb_to_sgvec(skb, sg, 0, skb->len); + ret = skb_to_sgvec(skb, sg, 0, skb->len); + if (unlikely(ret < 0)) + goto out; skb->ip_summed = CHECKSUM_NONE;