Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1960103imm; Thu, 24 May 2018 03:37:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrJSszvcRAOT0zS43Cfd3GdrpjHXq2yD62W6lr64+Z0dwVXn8Kz1mdTQRbPHynwtydh5sQ/ X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr6696793plt.378.1527158278202; Thu, 24 May 2018 03:37:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158278; cv=none; d=google.com; s=arc-20160816; b=NfsLThaDwuJuIM1NRtmY7r0Cw/tWa5W3yUBHLC5jUgj69WnJ7WFS5+CwRdcw0wpTUj XUcVh8XnDEv3gJQu2hVkLmkSd5jia0bE7Shs0rX6FcQWSuo34AjFEB1puS/hcG7nFxBK 4hpqjTb7f5AT4x593xX89OE4lGH8Yyq1UChp1KEGaUKb+CoZH2Mui1+dSpkZh1IsDvb4 QfRyAcoVpu3h54k+vV4wWeLyAW2WoTRAjUWYMlf5r0nlA3PR1W1rL8hzpm7dHiH8xRgJ 2zo62Wtxo2xobAG341ZlCtE60BwB7y+COqzVDA/7j4c0Za2lwCXe8qsWsGrWjeoK9trD l86w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=/UsMwv1tDO6lEPIV5BmeOG/T7/X3+BPvO+Lr/aNT/6Q=; b=K3GjDKWhV9raME75OUiyLwVgT1OzrAbSD03Q4EdmYVyoR436mPUrg4q/zAUSk+kSGf ZMnQCa++rviJaQHrvnsgXUhdT73NK+fOiSv6h3lRaI4M598m6EeGV06E1pIeSQf4DR8Z eBxeJfA1oRoqjJyWZUgXyDBCErJrL7MIsjPqZiNEp08Oi/OQgF2RZP6w/wU+uCHklCoH UMNVKEfMncfgWO2pLDFS4Xnyi1+vhaUO4XMaGsbOGlYrYjm4/H+6DhmhtyJCJu2XMWY8 MLLlab2vRTjkC84UM/+UwHCoEovlWZpEPO1EpaS/HoPvwUKUNAnyENp4Ap3gL/iIwDbN gsPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j2n1vO8e; 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 p11-v6si20926806pfj.294.2018.05.24.03.37.43; Thu, 24 May 2018 03:37:58 -0700 (PDT) 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=j2n1vO8e; 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 S968504AbeEXKhI (ORCPT + 99 others); Thu, 24 May 2018 06:37:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:41452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030798AbeEXJ77 (ORCPT ); Thu, 24 May 2018 05:59:59 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 69BFE20870; Thu, 24 May 2018 09:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155998; bh=qgNZ0whzbuNDnsYmTVupaY/EexWmMemv8LbA+uLStAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2n1vO8eEsJYOCeK+xr4C7rohUAqWnseRz7D/LbQlEN72qPqy3ugWTgzEkPZB8S0d 5nkv3xp+jwtqjuG/JpL8b+kkCH8+oXMA5tjf4khVE3ex5LAe2uB+bVj9o/gm63fvdM 7f5nNTDOys4/ghq4T+RccLHPQW7W4HVLomyHttkI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+71d74a5406d02057d559@syzkaller.appspotmail.com, Willem de Bruijn , "David S. Miller" Subject: [PATCH 4.16 008/161] packet: in packet_snd start writing at link layer allocation Date: Thu, 24 May 2018 11:37:13 +0200 Message-Id: <20180524093019.375532134@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn [ Upstream commit b84bbaf7a6c8cca24f8acf25a2c8e46913a947ba ] Packet sockets allow construction of packets shorter than dev->hard_header_len to accommodate protocols with variable length link layer headers. These packets are padded to dev->hard_header_len, because some device drivers interpret that as a minimum packet size. packet_snd reserves dev->hard_header_len bytes on allocation. SOCK_DGRAM sockets call skb_push in dev_hard_header() to ensure that link layer headers are stored in the reserved range. SOCK_RAW sockets do the same in tpacket_snd, but not in packet_snd. Syzbot was able to send a zero byte packet to a device with massive 116B link layer header, causing padding to cross over into skb_shinfo. Fix this by writing from the start of the llheader reserved range also in the case of packet_snd/SOCK_RAW. Update skb_set_network_header to the new offset. This also corrects it for SOCK_DGRAM, where it incorrectly double counted reserve due to the skb_push in dev_hard_header. Fixes: 9ed988cd5915 ("packet: validate variable length ll headers") Reported-by: syzbot+71d74a5406d02057d559@syzkaller.appspotmail.com Signed-off-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2903,13 +2903,15 @@ static int packet_snd(struct socket *soc if (skb == NULL) goto out_unlock; - skb_set_network_header(skb, reserve); + skb_reset_network_header(skb); err = -EINVAL; if (sock->type == SOCK_DGRAM) { offset = dev_hard_header(skb, dev, ntohs(proto), addr, NULL, len); if (unlikely(offset < 0)) goto out_free; + } else if (reserve) { + skb_push(skb, reserve); } /* Returns -EFAULT on error */