From patchwork Tue Mar 28 14:00:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 744295 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 3vssy64XTWz9s7N for ; Wed, 29 Mar 2017 01:01:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="VcWLv88L"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752900AbdC1OB2 (ORCPT ); Tue, 28 Mar 2017 10:01:28 -0400 Received: from mail-lf0-f46.google.com ([209.85.215.46]:36788 "EHLO mail-lf0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752746AbdC1OBW (ORCPT ); Tue, 28 Mar 2017 10:01:22 -0400 Received: by mail-lf0-f46.google.com with SMTP id x137so38882247lff.3 for ; Tue, 28 Mar 2017 07:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FNuHPVAXKNID/ZRzFWnGKJsuYUyyIkMktHnFltWccUU=; b=VcWLv88Le9HkvUbccxQq/swkkFvio0U+X/KJjeQDTlRtpOhiW4fHMJWIb3BA86+WX5 cyn2b0BmVBxhpWLVRlnFN+8PvRfO/IGQVzTYsIKEWsx9PQcCqtl3fiLdaGU8V9KUKVz+ vSDuGe0EDpc1mE1sGbspUobxFOCj+Ec94iCe4L+mbzWIth9xXhnSLs3lnVoEXksfPr3/ 2mLyBuckeA6Tkpcwo1tpE0Wn5BdhLz/gJfQEBPD2o8vDbViYZ9G9pN5bswxsgO7r3bSU +WZTk1IYGnqII3DSW1Zi0WlLF9HabaThjzG56fqP6rJqoZgBAms8jhksoAckSaiVasRV 8h5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=FNuHPVAXKNID/ZRzFWnGKJsuYUyyIkMktHnFltWccUU=; b=n2oh7lRsNuBmZPFlPRYQMFnh1iPolN6fKrU8e1rAGEzylRk/iZfT/NXVFswmHVrfOo GoJuSkd30850wJKjsdmF3fzhc5Yyfg9tvXO8l1perLAiUrUqtiXGFFZrbkmgu2nXIkSc aa46PHq8Sx3HXN2dyaoQ84L7+jF0LROCG0haJEtxurfpAfth2Rpa2BSBeEwrpI/1LDGd 9NiklWekQT3+wH5MshyfQbK7qNXTJ6IHtsFPPforyL3kPP0UQGbsIG3XpJnPonmDdq2x fmfJpWA5RscjMCONfLIqBBTRTpvSEJN8N+zhevlB0/JnuaXm80WFPl8fN6iAMzDhAVqu 9ghw== X-Gm-Message-State: AFeK/H3kcAvLJJE7pe2TDMewXQhmYx6+RCJP30NcII3x12NdJU+NAUbPmyWhWeFtDvoTdo2r X-Received: by 10.28.172.7 with SMTP id v7mr14417295wme.29.1490709660462; Tue, 28 Mar 2017 07:01:00 -0700 (PDT) Received: from andreyknvl0.muc.corp.google.com ([100.105.12.17]) by smtp.gmail.com with ESMTPSA id g41sm4981900wrg.53.2017.03.28.07.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2017 07:00:59 -0700 (PDT) Received: by andreyknvl0.muc.corp.google.com (Postfix, from userid 206546) id 3E377180271; Tue, 28 Mar 2017 16:00:55 +0200 (CEST) From: Andrey Konovalov To: "David S . Miller" , Eric Dumazet , Willem de Bruijn , Craig Gallek Cc: netdev@vger.kernel.org, Dmitry Vyukov , Kostya Serebryany , Andrey Konovalov Subject: [PATCH 2/5] net/packet: add explicit checks for tp_frame_size Date: Tue, 28 Mar 2017 16:00:44 +0200 Message-Id: <2ee83356bdfba1242ce5d3190fbe9f312f6a7fda.1490709552.git.andreyknvl@google.com> X-Mailer: git-send-email 2.12.2.564.g063fe858b8-goog In-Reply-To: References: In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org tp_frame_size can't be 0 or be larger than tp_block_size. As a result the check for frames_per_block == 0 is not needed any more. Also do explicit checks for tp_block_size, instead of casting to int. Signed-off-by: Andrey Konovalov --- net/packet/af_packet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 2323ee35dc09..506348abdf2f 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4188,8 +4188,16 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, } err = -EINVAL; - if (unlikely((int)req->tp_block_size <= 0)) + + if (unlikely(req->tp_block_size > INT_MAX)) + goto out; + if (unlikely(req->tp_block_size == 0)) + goto out; + if (unlikely(req->tp_frame_size > req->tp_block_size)) goto out; + if (unlikely(req->tp_frame_size == 0)) + goto out; + if (unlikely(!PAGE_ALIGNED(req->tp_block_size))) goto out; if (po->tp_version >= TPACKET_V3 && @@ -4203,8 +4211,6 @@ static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, goto out; rb->frames_per_block = req->tp_block_size / req->tp_frame_size; - if (unlikely(rb->frames_per_block == 0)) - goto out; if (unlikely((rb->frames_per_block * req->tp_block_nr) != req->tp_frame_nr)) goto out;