From patchwork Mon Jun 5 15:44:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Haines X-Patchwork-Id: 9766397 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 520756034B for ; Mon, 5 Jun 2017 15:51:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45F891FFB2 for ; Mon, 5 Jun 2017 15:51:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AAE2283C4; Mon, 5 Jun 2017 15:51:26 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71671FFB2 for ; Mon, 5 Jun 2017 15:51:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751284AbdFEPvT (ORCPT ); Mon, 5 Jun 2017 11:51:19 -0400 Received: from rgout0301.bt.lon5.cpcloud.co.uk ([65.20.0.207]:63861 "EHLO rgout03.bt.lon5.cpcloud.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751194AbdFEPvT (ORCPT ); Mon, 5 Jun 2017 11:51:19 -0400 X-Greylist: delayed 388 seconds by postgrey-1.27 at vger.kernel.org; Mon, 05 Jun 2017 11:51:18 EDT X-OWM-Source-IP: 81.132.44.109 (GB) X-OWM-Env-Sender: richard_c_haines@btinternet.com Received: from localhost.localdomain (81.132.44.109) by rgout03.bt.lon5.cpcloud.co.uk (9.0.019.13-1) (authenticated as richard_c_haines@btinternet.com) id 58A82A5C0C14AAEF; Mon, 5 Jun 2017 16:44:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com; s=btcpcloud; t=1496677878; bh=3nwd7d9hTQi5VrwNTH5jz01bb7hmHM9T97T64lw7imA=; h=From:To:Cc:Subject:Date:Message-Id:X-Mailer; b=f8uym5SoBG1SUBoRbPwO9S25uNC7ESDr3TmrIIpwiaJkVi7FplQHCLvWk5BwxJDRSt/L6TW0trGL1qpbM66A3kvYCM8n1HOe2bLLld1u4v/qWc7MJvSPs0Fm1OKLC/BIBFHQQIBuEZZhdGx6cr0Qg1PLbas0lZPrE9p3CH0Y1x8= From: Richard Haines To: paul@paul-moore.com Cc: netdev@vger.kernel.org, selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, Richard Haines Subject: [PATCH] net/ipv6: Fix CALIPSO causing GPF with datagram support Date: Mon, 5 Jun 2017 16:44:40 +0100 Message-Id: <20170605154440.2434-1-richard_c_haines@btinternet.com> X-Mailer: git-send-email 2.9.4 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP When using CALIPSO with IPPROTO_UDP it is possible to trigger a GPF as the IP header may have moved. Also update the payload length after adding the CALIPSO option. Signed-off-by: Richard Haines Acked-by: Paul Moore Signed-off-by: Huw Davies --- net/ipv6/calipso.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index 37ac9de..8d772fe 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -1319,7 +1319,7 @@ static int calipso_skbuff_setattr(struct sk_buff *skb, struct ipv6hdr *ip6_hdr; struct ipv6_opt_hdr *hop; unsigned char buf[CALIPSO_MAX_BUFFER]; - int len_delta, new_end, pad; + int len_delta, new_end, pad, payload; unsigned int start, end; ip6_hdr = ipv6_hdr(skb); @@ -1346,6 +1346,8 @@ static int calipso_skbuff_setattr(struct sk_buff *skb, if (ret_val < 0) return ret_val; + ip6_hdr = ipv6_hdr(skb); /* Reset as skb_cow() may have moved it */ + if (len_delta) { if (len_delta > 0) skb_push(skb, len_delta); @@ -1355,6 +1357,8 @@ static int calipso_skbuff_setattr(struct sk_buff *skb, sizeof(*ip6_hdr) + start); skb_reset_network_header(skb); ip6_hdr = ipv6_hdr(skb); + payload = ntohs(ip6_hdr->payload_len); + ip6_hdr->payload_len = htons(payload + len_delta); } hop = (struct ipv6_opt_hdr *)(ip6_hdr + 1);