From patchwork Sun Jun 4 02:16:24 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: 9764593 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 D1DCD6032D for ; Sun, 4 Jun 2017 02:17:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C233223E64 for ; Sun, 4 Jun 2017 02:17:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B70052582C; Sun, 4 Jun 2017 02:17:30 +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 CD7B323E64 for ; Sun, 4 Jun 2017 02:17:29 +0000 (UTC) Received: (qmail 5313 invoked by uid 550); 4 Jun 2017 02:17:09 -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 3395 invoked from network); 4 Jun 2017 02:17:00 -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=jojh j6O8fQpWkEpE0yBAw9DBc/M=; b=o4dNL7K5nXVFyoraLHBStXQQiVJIoFuNjykx owGiuSQ4CxarJ4sKJ2uQZgdcF4zqaBR/7oa7UvFblFKQ35tk0aQa+wwc3nzn6O/9 /LiUvxGPM3ilW5rrURybvEJ3VK51039bgiHLv6a2Ni+D6fJu7rpyiaPY5h3aTb6k qyOK5qAUzjtmjizO9K0dpA3wxA0XmJeWdmnnpOcSPMifqCqePb49f6NO51afkVFo Ecltwc1V2/8y2iDLnZHppJl4MYrmJrrlv46hj/eZRINpBVYVIKZkom53kJ36bC2s YjZjDd4hkiS0rlTcFUZsnRbwqH5yu1yLWb4CS996xeOzaVIAtw== From: "Jason A. Donenfeld" To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net, kernel-hardening@lists.openwall.com Cc: "Jason A. Donenfeld" Date: Sun, 4 Jun 2017 04:16:24 +0200 Message-Id: <20170604021626.11968-4-Jason@zx2c4.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170604021626.11968-1-Jason@zx2c4.com> References: <20170604021626.11968-1-Jason@zx2c4.com> Subject: [kernel-hardening] [PATCH net-next v10 3/5] rxrpc: check return value of skb_to_sgvec always X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jason A. Donenfeld Acked-by: David Howells --- net/rxrpc/rxkad.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index 1bb9b2ccc267..29fe20ad04aa 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c @@ -227,7 +227,9 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call, len &= ~(call->conn->size_align - 1); sg_init_table(sg, nsg); - skb_to_sgvec(skb, sg, 0, len); + err = skb_to_sgvec(skb, sg, 0, len); + if (unlikely(err < 0)) + goto out; skcipher_request_set_crypt(req, sg, sg, len, iv.x); crypto_skcipher_encrypt(req); @@ -324,7 +326,7 @@ static int rxkad_verify_packet_1(struct rxrpc_call *call, struct sk_buff *skb, bool aborted; u32 data_size, buf; u16 check; - int nsg; + int nsg, ret; _enter(""); @@ -342,7 +344,9 @@ static int rxkad_verify_packet_1(struct rxrpc_call *call, struct sk_buff *skb, goto nomem; sg_init_table(sg, nsg); - skb_to_sgvec(skb, sg, offset, 8); + ret = skb_to_sgvec(skb, sg, offset, 8); + if (unlikely(ret < 0)) + return ret; /* start the decryption afresh */ memset(&iv, 0, sizeof(iv)); @@ -409,7 +413,7 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb, bool aborted; u32 data_size, buf; u16 check; - int nsg; + int nsg, ret; _enter(",{%d}", skb->len); @@ -434,7 +438,12 @@ static int rxkad_verify_packet_2(struct rxrpc_call *call, struct sk_buff *skb, } sg_init_table(sg, nsg); - skb_to_sgvec(skb, sg, offset, len); + ret = skb_to_sgvec(skb, sg, offset, len); + if (unlikely(ret < 0)) { + if (sg != _sg) + kfree(sg); + return ret; + } /* decrypt from the session key */ token = call->conn->params.key->payload.data[0];