Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1336681imm; Thu, 23 Aug 2018 01:03:14 -0700 (PDT) X-Google-Smtp-Source: AA+uWPymwd40ElR5munId7lpZ0+4gB9D5bgf2dtzVxXTs/ODh31C3u/jouctrB9kay5Pxf9nhj1S X-Received: by 2002:a63:3642:: with SMTP id d63-v6mr19763365pga.231.1535011394630; Thu, 23 Aug 2018 01:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535011394; cv=none; d=google.com; s=arc-20160816; b=smp827gz9P0Ia7u94ZSUS2L601FxjSrNoNVxMk/DDiV6mu80NWr67Bt0NL4qtCdI/l AeinBhonauTzRepucnYM6y+tcG1C3uWlGaSHgNyN+aq5KNC+Ik3jDEHl/3DqmxC53IOm CqbSKl3cMuG3gZhvi8lufidcmGdaCtBhQRDPHr8S0Y/c/Nqvo5P3ZPsFG3P6QfX3NCVs UVVzNmUXvP1syEwRSyEWbL2J+7n1DHaNlo+bAbffRxHZNjqS0WUffGlNt1g6+ZTEXMer Zj6I1e9mwohC5T9wiOgLk8mPSCEXN0xvkj7V/JhR4CGF2pogjjhrKfPhALGDjQUYjDUe f2oA== 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 :arc-authentication-results; bh=LrsK7Xt/dpB1hODa5VdIy/CCMAYuYwfbwR1S0JtMQiI=; b=Xd+kVGwMNjxj683gS7sVRh6FF8WVdK5O1xL4zxXVs7GiuWq9yFTOpUU6QVffu8pWGE qb3ya/I9Sq4agLqKZAxvldF0mhvMUdZhsC8ddp2fuzb9nCf5RMS/QcmuZIy8OIWNf2Tp otlaDkOQ8Y3L26St6wAq4t5BAA2B+s5hlJAH0lfIK77ritPFqLwx6+dqPdvMw8bca5JA GV1uEBBawLJpxUEmPOjiY03VCj7aM8OJDxgMvkYeMMj4Pu/ZY8UGDPChsdQnTSQugEtN wiU4ijrDXJKXXNU1/SwTgJ5pdYMolPc91uCQraerxn0IfrNUOb9ScjgdOrph8kv2JdvZ JvvA== ARC-Authentication-Results: i=1; mx.google.com; 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 p1-v6si3666586plk.294.2018.08.23.01.02.59; Thu, 23 Aug 2018 01:03:14 -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; 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 S1728734AbeHWL26 (ORCPT + 99 others); Thu, 23 Aug 2018 07:28:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43644 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728706AbeHWL25 (ORCPT ); Thu, 23 Aug 2018 07:28:57 -0400 Received: from localhost (5355525A.cm-6-6b.dynamic.ziggo.nl [83.85.82.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D1939C5C; Thu, 23 Aug 2018 08:00:28 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Willem de Bruijn , "David S. Miller" Subject: [PATCH 4.4 72/79] packet: refine ring v3 block size test to hold one frame Date: Thu, 23 Aug 2018 09:53:48 +0200 Message-Id: <20180823074923.877356466@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180823074918.641878835@linuxfoundation.org> References: <20180823074918.641878835@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Willem de Bruijn commit 4576cd469d980317c4edd9173f8b694aa71ea3a3 upstream. TPACKET_V3 stores variable length frames in fixed length blocks. Blocks must be able to store a block header, optional private space and at least one minimum sized frame. Frames, even for a zero snaplen packet, store metadata headers and optional reserved space. In the block size bounds check, ensure that the frame of the chosen configuration fits. This includes sockaddr_ll and optional tp_reserve. Syzbot was able to construct a ring with insuffient room for the sockaddr_ll in the header of a zero-length frame, triggering an out-of-bounds write in dev_parse_header. Convert the comparison to less than, as zero is a valid snap len. This matches the test for minimum tp_frame_size immediately below. Fixes: f6fb8f100b80 ("af-packet: TPACKET_V3 flexible buffer implementation.") Fixes: eb73190f4fbe ("net/packet: refine check for priv area size") Reported-by: syzbot Signed-off-by: Willem de Bruijn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4176,6 +4176,8 @@ static int packet_set_ring(struct sock * } if (req->tp_block_nr) { + unsigned int min_frame_size; + /* Sanity tests and some calculations */ err = -EBUSY; if (unlikely(rb->pg_vec)) @@ -4198,12 +4200,12 @@ static int packet_set_ring(struct sock * goto out; if (unlikely(!PAGE_ALIGNED(req->tp_block_size))) goto out; + min_frame_size = po->tp_hdrlen + po->tp_reserve; if (po->tp_version >= TPACKET_V3 && - req->tp_block_size <= - BLK_PLUS_PRIV((u64)req_u->req3.tp_sizeof_priv) + sizeof(struct tpacket3_hdr)) + req->tp_block_size < + BLK_PLUS_PRIV((u64)req_u->req3.tp_sizeof_priv) + min_frame_size) goto out; - if (unlikely(req->tp_frame_size < po->tp_hdrlen + - po->tp_reserve)) + if (unlikely(req->tp_frame_size < min_frame_size)) goto out; if (unlikely(req->tp_frame_size & (TPACKET_ALIGNMENT - 1))) goto out;