From patchwork Sun May 10 12:27:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guilherme G. Piccoli" X-Patchwork-Id: 1287161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Kjyl58SWz9sRY; Sun, 10 May 2020 22:28:13 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jXl3t-0002Fb-Ps; Sun, 10 May 2020 12:28:05 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jXl3s-0002FV-RC for kernel-team@lists.ubuntu.com; Sun, 10 May 2020 12:28:04 +0000 Received: from mail-qv1-f70.google.com ([209.85.219.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jXl3s-000795-G9 for kernel-team@lists.ubuntu.com; Sun, 10 May 2020 12:28:04 +0000 Received: by mail-qv1-f70.google.com with SMTP id z14so6829239qvv.6 for ; Sun, 10 May 2020 05:28:04 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=8qfOOVLxGsgq0y6w0CMcWl86Hdv+0N79DRU+ggO1x+w=; b=VEDr96wvLEqQaAGoMCAY9AcUcLkp3yiiI/IoRNdej97pxxfERjlrp6hyn/dZdb/h9D AmRY9ytYyyDkFnrof0ZEP7oHGwR8qtc7zXoEUXieA4WGxBD44IcOFS2KfcUOnWgQopNN EGTXTcGV6LLWVtpzlhbJwIEAsR7eKDyV87mh/5ew/6/ePM3oX19bYk/6zyZxuZXfjIUn QC8WSMw1ylDAuHNtEg+UrULUrYvGCRdanEXumFBxVfcJrocuHH2qj+4OVev9osiI0Sto 3qR6YOMnKKH+YUbpTi9/b0sh96wAJfxXiTltAdjcIdWmSmAJp8njkjP1HVbjceqT5nxQ kOaQ== X-Gm-Message-State: AGi0PuaxkG5md7Mewi/kiQN6FC7tdxzFKItSNs6+IxEZKEV8TmhzThVw AmPj4l6rC4WRuPwQotqgYOU89sn7dGJOooGZwf9wZSroLkcqIjFXx+y6V6SBHMbIH4qqTTOIxUs EnBozzyBs25Pg4wqidRcNojzQfhjDtpPd5xFkGe4wzg== X-Received: by 2002:ad4:458a:: with SMTP id x10mr11022074qvu.199.1589113683280; Sun, 10 May 2020 05:28:03 -0700 (PDT) X-Google-Smtp-Source: APiQypJLtt4WUewGBNF2U860pQZsagZKvilw+43u8eV/m7W7QQb9TPmP47rD8viGHWpIBkQromcSxA== X-Received: by 2002:ad4:458a:: with SMTP id x10mr11022055qvu.199.1589113683047; Sun, 10 May 2020 05:28:03 -0700 (PDT) Received: from localhost ([152.254.147.183]) by smtp.gmail.com with ESMTPSA id d4sm6248381qtw.25.2020.05.10.05.28.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 May 2020 05:28:02 -0700 (PDT) From: "Guilherme G. Piccoli" To: kernel-team@lists.ubuntu.com Subject: [X/B][PATCH] ethtool: Ensure new ring parameters are within bounds during SRINGPARAM Date: Sun, 10 May 2020 09:27:59 -0300 Message-Id: <20200510122759.11774-1-gpiccoli@canonical.com> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ddstreet@canonical.com, gpiccoli@canonical.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Eugenia Emantayev BugLink: https://bugs.launchpad.net/bugs/1874444 Add a sanity check to ensure that all requested ring parameters are within bounds, which should reduce errors in driver implementation. Signed-off-by: Eugenia Emantayev Signed-off-by: Tariq Toukan Signed-off-by: David S. Miller (cherry picked from commit 37e2d99b59c4765112533a1d38174fea58d28a51) Signed-off-by: Guilherme G. Piccoli Acked-by: Kamal Mostafa Acked-by: Kleber Sacilotto de Souza --- Hi folks, this was tested by me in AWS instance, ena driver is affected by it (in other words, no ring validation in the driver), but many other drivers could suffer from this, hence I'd recommend of course to merge in all releases. Thanks in advance for reviews, Guilherme net/core/ethtool.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 3702a24a8cf5..86b4f474b46e 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -1705,14 +1705,23 @@ static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr) static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr) { - struct ethtool_ringparam ringparam; + struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM }; - if (!dev->ethtool_ops->set_ringparam) + if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam) return -EOPNOTSUPP; if (copy_from_user(&ringparam, useraddr, sizeof(ringparam))) return -EFAULT; + dev->ethtool_ops->get_ringparam(dev, &max); + + /* ensure new ring parameters are within the maximums */ + if (ringparam.rx_pending > max.rx_max_pending || + ringparam.rx_mini_pending > max.rx_mini_max_pending || + ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending || + ringparam.tx_pending > max.tx_max_pending) + return -EINVAL; + return dev->ethtool_ops->set_ringparam(dev, &ringparam); }