Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2028152imm; Thu, 24 May 2018 04:46:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpvEiGla4WoLxEQH/FCBDi6a1Y3greAgmEST3w/tWLDbTLjZkGSiItbVHgbuffs7CsdkELq X-Received: by 2002:a63:43c6:: with SMTP id q189-v6mr5765567pga.123.1527162407078; Thu, 24 May 2018 04:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527162407; cv=none; d=google.com; s=arc-20160816; b=UJqMEY04E/J5uUOv9mE7zY/fIySsqMIu3VHX7drV2V0GrYNRDc3V6UddegjDx7M+QM ioZetC71Inyi9ICT0Y9YbDl+Crx8M5fKNwZ5LRi18Inl5JrUdxRVUKHBAzjwfi5xBISn KAkKwF14/jaA3pLxAz7K2WSNpA9Fjhu/S9D2rMJb0/IJ91Vq9wO34s2xwzF7Oe4daNEB coBS1aRlNuh+QrcAMDEa6iH5T8IaLj4S5kochLzakx8o91TLJC6ruAIEjYWQsLPR/di+ 1p0p0MaAXPeiRqvaMigfpp0R6NZDlWqRNUAm1ovV29YNbTkUMHRdZVyNEyHc8ysLhvf6 jkvw== 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=hrGxuQnlmOPUiZN3oM5vVjN7LT1BFyBqiGHtmidAWTA=; b=cPhwAuuXZ1GDss82RLy5Zd6HMEKTpba+5eD+JwnWkDsHZnFiCJCNHdr+h1WhPL+T1K wkwMfMmKiMlO6XwxJblQrIrxAih/1A1wetKjkg5o6TCG/J6M8fBsYgykxNQIvTceoFTH bxSny0SqcZZD5U0NXOgaeY5dOD5rDwywm5Vg4EcbHei0V1O9lc9Z8Hj0gSf/+5ZPXLJP P8cDF7LdzN/c7yeN4eQB0yKPbzwExJkihF+wNgeL1XXnz/VRK5Iewp9Gl+JcRd4yvvjK 6GBRPTu6W7Z/DFbhdq/5uci7EPUF0BH7F161fKuaiPxSe1X4ruvD2hMdFUS6Yqw+LTnn 0oOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QUPlclp7; 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 p67-v6si20167667pfp.72.2018.05.24.04.46.32; Thu, 24 May 2018 04:46:47 -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=QUPlclp7; 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 S967136AbeEXJr4 (ORCPT + 99 others); Thu, 24 May 2018 05:47:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:60666 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967106AbeEXJrr (ORCPT ); Thu, 24 May 2018 05:47:47 -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 5F8F2208C4; Thu, 24 May 2018 09:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155266; bh=s12XRrvEtLtzZbgWNz05NXRltUY19PFoHCBBsdmnlN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QUPlclp7CFJQMBqvAsWdihMAeHGOZGH0FbzNiIaYPIW9jsWTA5LiYilerbFKjXELZ Zpttlc3Rlm3xLikEHGLSr3sCz4iYfrn4GBB9PIgA0+Hs7nXrTw61LIe/8WWYn1vSPL mW/hEz347JHLX7K9qnng98dSbRFW8SXwWXs20SCc= 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.9 03/96] packet: in packet_snd start writing at link layer allocation Date: Thu, 24 May 2018 11:37:46 +0200 Message-Id: <20180524093605.846607760@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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.9-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 @@ -2910,13 +2910,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 */