Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1951125AbdDYPxA (ORCPT ); Tue, 25 Apr 2017 11:53:00 -0400 Received: from frisell.zx2c4.com ([192.95.5.64]:40145 "EHLO frisell.zx2c4.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1431618AbdDYPwf (ORCPT ); Tue, 25 Apr 2017 11:52:35 -0400 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" Subject: [PATCH v5 4/5] macsec: check return value of skb_to_sgvec always Date: Tue, 25 Apr 2017 17:52:14 +0200 Message-Id: <20170425155215.4835-4-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> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1150 Lines: 38 Signed-off-by: Jason A. Donenfeld --- drivers/net/macsec.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c index dbab05afcdbe..d846f42b99ec 100644 --- a/drivers/net/macsec.c +++ b/drivers/net/macsec.c @@ -733,7 +733,12 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb, macsec_fill_iv(iv, secy->sci, pn); sg_init_table(sg, MAX_SKB_FRAGS + 1); - skb_to_sgvec(skb, sg, 0, skb->len); + ret = skb_to_sgvec(skb, sg, 0, skb->len); + if (unlikely(ret < 0)) { + macsec_txsa_put(tx_sa); + kfree_skb(skb); + return ERR_PTR(ret); + } if (tx_sc->encrypt) { int len = skb->len - macsec_hdr_len(sci_present) - @@ -937,7 +942,11 @@ static struct sk_buff *macsec_decrypt(struct sk_buff *skb, macsec_fill_iv(iv, sci, ntohl(hdr->packet_number)); sg_init_table(sg, MAX_SKB_FRAGS + 1); - skb_to_sgvec(skb, sg, 0, skb->len); + ret = skb_to_sgvec(skb, sg, 0, skb->len); + if (unlikely(ret < 0)) { + kfree_skb(skb); + return ERR_PTR(ret); + } if (hdr->tci_an & MACSEC_TCI_E) { /* confidentiality: ethernet + macsec header -- 2.12.2