From patchwork Thu Nov 3 03:30:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 690655 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3t8VqV0cQ4z9tl4 for ; Thu, 3 Nov 2016 14:31:02 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=FTPJOizY; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751346AbcKCDax (ORCPT ); Wed, 2 Nov 2016 23:30:53 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33366 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbcKCDaw (ORCPT ); Wed, 2 Nov 2016 23:30:52 -0400 Received: by mail-pf0-f194.google.com with SMTP id a136so3448023pfa.0; Wed, 02 Nov 2016 20:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :mime-version:content-transfer-encoding; bh=yla/OVk0vrb/sQ3fBveSCf+UPm4wnJqgeXdqJBcAUH8=; b=FTPJOizYR0FCNwy2J01t9WARdcGA2AeGo9lgAL7jCiN1ByQo3dCzgdW2kFvRYkk7Q7 Kizf5PX0tb6AE3z6LSKfQo3qVmWHFeJtiK8XDuOuKBtVEEX50B/oLAOvqnul+KVqwpdK foa7G9MezDXgpTkrB9hkUMzZOFlAyPQ077CsCqZzBqvPFBRx9u+rrkEBGps96VBOp8nG 53ICh7vZFye3tY+Aq+sblX66Ht/YlLiWMbIvjSFzhwsFmi6V4X9+ABhOwedzV9Si3Mfr x5m8a9jVyt2QJh/bh+UvC8THvyoksccemYwmsCnkQR5xpOR44rkGo3WexvrtEuw7zAwZ i3dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=yla/OVk0vrb/sQ3fBveSCf+UPm4wnJqgeXdqJBcAUH8=; b=WUbRn7sFElVHqkRUlS+ho6xR4oo7NV8WmE2miuDFsVhoy5TpIgjE7r2G8rqmhr8fXu ZWXw45i2M3kh3IkLcCsGHYbAXtTq/Uodunstw1LxTmEf/OBbQNiBIuf0VWXP3mvFbVWf Di9d8W1qMFTGMpWLddoDq7q0TfJjnpwN93byqTTFxlvAMCVRT5sNiIP6lQQACWRpbT/p TN9yttt2KgUKcIxeQXVP5j9oi/XwZ6u/eiSXzm50EkQGFTMflPO6q9VA7hFwGZYPwVGU FN++hiDhC7KmMJ3K/JdYFOPXQT5f/W0zd6D34QUFqffuxY/NeZIrFF9zgJikAhKFLZg9 HNtg== X-Gm-Message-State: ABUngveBrN9ddZLFjpO6Mr6Dpj+o8rJQ7B383wHwFsCEjhdwFSe10z4eMd3MRPwIW6/k0w== X-Received: by 10.99.144.65 with SMTP id a62mr10846364pge.103.1478143850738; Wed, 02 Nov 2016 20:30:50 -0700 (PDT) Received: from [172.29.161.156] ([172.29.161.156]) by smtp.googlemail.com with ESMTPSA id b79sm7972813pfd.49.2016.11.02.20.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 20:30:50 -0700 (PDT) Message-ID: <1478143848.7065.429.camel@edumazet-glaptop3.roam.corp.google.com> Subject: [PATCH net] ipv6: dccp: fix out of bound access in dccp_v6_err() From: Eric Dumazet To: David Miller Cc: netdev , Gerrit Renker , dccp@vger.kernel.org Date: Wed, 02 Nov 2016 20:30:48 -0700 In-Reply-To: <1478138440.7065.419.camel@edumazet-glaptop3.roam.corp.google.com> References: <1478138440.7065.419.camel@edumazet-glaptop3.roam.corp.google.com> X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet dccp_v6_err() does not use pskb_may_pull() and might access garbage. We only need 4 bytes at the beginning of the DCCP header, like TCP, so the 8 bytes pulled in icmpv6_notify() are more than enough. Signed-off-by: Eric Dumazet --- net/dccp/ipv6.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c index 3828f94b234c..3d35277a0b41 100644 --- a/net/dccp/ipv6.c +++ b/net/dccp/ipv6.c @@ -70,7 +70,7 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, u8 type, u8 code, int offset, __be32 info) { const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; - const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset); + const struct dccp_hdr *dh; struct dccp_sock *dp; struct ipv6_pinfo *np; struct sock *sk; @@ -78,12 +78,13 @@ static void dccp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, __u64 seq; struct net *net = dev_net(skb->dev); - if (skb->len < offset + sizeof(*dh) || - skb->len < offset + __dccp_basic_hdr_len(dh)) { - __ICMP6_INC_STATS(net, __in6_dev_get(skb->dev), - ICMP6_MIB_INERRORS); - return; - } + /* Only need dccph_dport & dccph_sport which are the first + * 4 bytes in dccp header. + * Our caller (icmpv6_notify()) already pulled 8 bytes for us. + */ + BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_sport) > 8); + BUILD_BUG_ON(offsetofend(struct dccp_hdr, dccph_dport) > 8); + dh = (struct dccp_hdr *)(skb->data + offset); sk = __inet6_lookup_established(net, &dccp_hashinfo, &hdr->daddr, dh->dccph_dport,