Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6262145imu; Mon, 21 Jan 2019 06:03:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN7lrwZA7uxViw++idWjCPCluhu+3szxUPrkZ8NEdCFNSHstWpxy2imbXR4asJu+3ICeSz8s X-Received: by 2002:a63:4e41:: with SMTP id o1mr28827703pgl.282.1548079388041; Mon, 21 Jan 2019 06:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079388; cv=none; d=google.com; s=arc-20160816; b=J4OG3EJ0IAop3/0Iof7KglsHB6p5RSwS7cvsIVo/B0CqZ0hBrqeYTM62ljlAKlmaQ4 Naj13rhIjFc/wairjV0UPW+pXJxjoJZK4WazE/gXnlL09J84uAsBBaiGoWOjqiWlIbUt VBXebwRsNXwZ/xoTa+9Bp68rRRUhcAEYQSIqKhQ0/ITaVOWARCa+FvX8ZOj+V5w1TlTf W1jGC4GbK66H9obpbmpkEP4cVvdPNIFQOQynWVQMYLXnKEAo/hmr8mrkiIithmXAISDh 1/Vsq4WRqdZU9rbno6dSNZtXYOmW7pXKKINtDoszZglWrRtYeJsVSdbnqt5wO7I6M4ak uEdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=T8xiyEsAEFdjqsiezb1I9HlckiJa8Tw/DTHdqY//BNs=; b=YLWK5Ewa4Urf4XtzMaIotgTpC7UcPiEkmsnm/9wX7tjINW1Eo7Af1rtmwK0NoCRfEj z3Fl11GLYso51fef4tfxS+P5YLKywWE+0dSzffMZm/IY+Kg/mJRBpgr8vinIAFzE4Ir5 WFrxPP7AAQIUnp5IY1WRIN8mUwzjfLldpY9DAcL0QS54mL8CrpssirsJdHEpsOljYyir vqoo8Nv3e93LjAz97AjXc8qyDaaVyBbtIqEclN9kLhzVcE3DRuV8yWfTi6k2rp6zPm4h AeCN8hO59tjZiICSluCHDKkPWwt01LBy/CXGJ+l3Z2aXBnBC1bHZGSl+4sdqQCr4fQJ5 zPyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1LHNHujw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a28si12601265pgl.530.2019.01.21.06.02.47; Mon, 21 Jan 2019 06:03:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1LHNHujw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732174AbfAUN7Y (ORCPT + 99 others); Mon, 21 Jan 2019 08:59:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:45346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731776AbfAUN7W (ORCPT ); Mon, 21 Jan 2019 08:59:22 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E85442084C; Mon, 21 Jan 2019 13:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079161; bh=wL86xlASy9Gn8LwvMPz4tLpbEAjFTPh8SmI/dC1KvE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1LHNHujwTSTiw2xnUpm7rFRBRjot3PE6S7IPgPMulNrEcDQf679VLI/uAYmkBEWdl TfJo5O+sM3RZwnM5WS6w9M7xpCAqPqvZvpTqibTJOidqNUQMsoY/t+C2rGE4lUCVEX eSVBFPG4HxSEYvXc/nF10lWjFA+4MvfODmB3sEIg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Eric Dumazet , Willem de Bruijn , "David S. Miller" Subject: [PATCH 4.19 29/99] ip: on queued skb use skb_header_pointer instead of pskb_may_pull Date: Mon, 21 Jan 2019 14:48:21 +0100 Message-Id: <20190121134915.009484349@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn [ Upstream commit 4a06fa67c4da20148803525151845276cdb995c1 ] Commit 2efd4fca703a ("ip: in cmsg IP(V6)_ORIGDSTADDR call pskb_may_pull") avoided a read beyond the end of the skb linear segment by calling pskb_may_pull. That function can trigger a BUG_ON in pskb_expand_head if the skb is shared, which it is when when peeking. It can also return ENOMEM. Avoid both by switching to safer skb_header_pointer. Fixes: 2efd4fca703a ("ip: in cmsg IP(V6)_ORIGDSTADDR call pskb_may_pull") Reported-by: syzbot Suggested-by: Eric Dumazet Signed-off-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/ip_sockglue.c | 12 +++++------- net/ipv6/datagram.c | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -148,19 +148,17 @@ static void ip_cmsg_recv_security(struct static void ip_cmsg_recv_dstaddr(struct msghdr *msg, struct sk_buff *skb) { + __be16 _ports[2], *ports; struct sockaddr_in sin; - __be16 *ports; - int end; - - end = skb_transport_offset(skb) + 4; - if (end > 0 && !pskb_may_pull(skb, end)) - return; /* All current transport protocols have the port numbers in the * first four bytes of the transport header and this function is * written with this assumption in mind. */ - ports = (__be16 *)skb_transport_header(skb); + ports = skb_header_pointer(skb, skb_transport_offset(skb), + sizeof(_ports), &_ports); + if (!ports) + return; sin.sin_family = AF_INET; sin.sin_addr.s_addr = ip_hdr(skb)->daddr; --- a/net/ipv6/datagram.c +++ b/net/ipv6/datagram.c @@ -701,17 +701,15 @@ void ip6_datagram_recv_specific_ctl(stru } if (np->rxopt.bits.rxorigdstaddr) { struct sockaddr_in6 sin6; - __be16 *ports; - int end; + __be16 _ports[2], *ports; - end = skb_transport_offset(skb) + 4; - if (end <= 0 || pskb_may_pull(skb, end)) { + ports = skb_header_pointer(skb, skb_transport_offset(skb), + sizeof(_ports), &_ports); + if (ports) { /* All current transport protocols have the port numbers in the * first four bytes of the transport header and this function is * written with this assumption in mind. */ - ports = (__be16 *)skb_transport_header(skb); - sin6.sin6_family = AF_INET6; sin6.sin6_addr = ipv6_hdr(skb)->daddr; sin6.sin6_port = ports[1];