Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1961130imm; Thu, 24 May 2018 03:38:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoV3N1TGQENPmTDbJpoeI1p6ApN8KZqWY+KsRGRieiLrQHo/7PGL4gPHuqfL8egirJOVKjp X-Received: by 2002:a62:df4c:: with SMTP id u73-v6mr6658953pfg.10.1527158330004; Thu, 24 May 2018 03:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158329; cv=none; d=google.com; s=arc-20160816; b=FZrN24lrQN5AIr8zXl89xX+RWQbxVTFdGURLTKjPr2rS1XR8dNr5fX5x4e9uQ7rG+q pZp9dP5sJGmU3K+sKjMZvXWcrqgOzJZDfRvqPouX9hS0ndHj6nwaYAGHezTtaAvEo2K1 kmX9FYo2w3vAVsnK7LIkwSaaULD/Hd8bI4M8EauzOMvasrAqWiR5VZffu8H72zYAPIhq w94L4r1pX7nyT1XEthbLV8xAJxu9/T925EMkledek5ul1V9gt+T3OLLzEek4RnBZT9+5 9G3gDqEc7WzPUpqvcBceD8WTMHTD+ZjBk148MpZ842Zj0TK78b/E+py69R+5cP4l584m rh4Q== 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=18sQh9m0ViInMOrPOvtn0tlSHEzJAyPPxDfEKH3T/9s=; b=CllgR0hGCXfmtGgq67F5EN7rGDrZ8jCTLWSaGaHbQ3wWZmUqXQqxtIJmcuxbmQ2ICV sF+lEYaf8OKaEYZwlOncyode9O4z7M208Lb6SvtVjEEWOyV4XUJIC+trIlTYMufxEg2o 4bj2tmTPQjZga3i4JS5oEWRWbqn22EIs28RXbzD6eG9AsQE43mhuRd4vOxBZwvmWeO7u sSxuK7nqqODAH1EPNtNN8/JDZQGEyqbn8qd3RlkWnBKryQDKFY3NJxFOuA+hBECjSNGs 61bGrQ8sBnO+71Q929Z19eZ5N+qm01p5wvZr3mCIcv9OQLgi+/71xSwZkJUk/PeUH4Oq 5HDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sDK+Skhk; 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 i125-v6si11573409pgc.88.2018.05.24.03.38.34; Thu, 24 May 2018 03:38:49 -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=sDK+Skhk; 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 S1030795AbeEXJ7j (ORCPT + 99 others); Thu, 24 May 2018 05:59:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:40360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030763AbeEXJ70 (ORCPT ); Thu, 24 May 2018 05:59:26 -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 5A95D20891; Thu, 24 May 2018 09:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155965; bh=5fvmFGK2BFvjsGb/E9XznAw2h/K1fh1+9aq1YrphSOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDK+SkhkY1osB/3Oi1+LIszrA4R+70gBR/GbFn+D/8hA0tUHUemfBo6hY9GvW05ks oV7BRhHU3IMmM5CvtWl6qZ1YLDf4bdoVz5NidNjq7UtlhFZ20n1InN2tzG15xUPWYc oP0g92hMwWJmacRExBZVPuZ143blf5LVLnUbpEOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Florian Fainelli , "David S. Miller" Subject: [PATCH 4.16 016/161] net: dsa: bcm_sf2: Fix IPv6 rules and chain ID Date: Thu, 24 May 2018 11:37:21 +0200 Message-Id: <20180524093020.306140545@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: Florian Fainelli [ Upstream commit 6c05561c541843b2bec2189f680bed6d20afc25b ] We had several issues that would make the programming of IPv6 rules both inconsistent and error prone: - the chain ID that we would be asking the hardware to put in the packet's Broadcom tag would be off by one, it would return one of the two indexes, but not the one user-space specified - when an user specified a particular location to insert a CFP rule at, we would not be returning the same index, which would be confusing if nothing else - finally, like IPv4, it would be possible to overflow the last entry by re-programming it Fix this by swapping the usage of rule_index[0] and rule_index[1] where relevant in order to return a consistent and correct user-space experience. Fixes: ba0696c22e7c ("net: dsa: bcm_sf2: Add support for IPv6 CFP rules") Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/dsa/bcm_sf2_cfp.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) --- a/drivers/net/dsa/bcm_sf2_cfp.c +++ b/drivers/net/dsa/bcm_sf2_cfp.c @@ -565,19 +565,21 @@ static int bcm_sf2_cfp_ipv6_rule_set(str * first half because the HW search is by incrementing addresses. */ if (fs->location == RX_CLS_LOC_ANY) - rule_index[0] = find_first_zero_bit(priv->cfp.used, - bcm_sf2_cfp_rule_size(priv)); + rule_index[1] = find_first_zero_bit(priv->cfp.used, + priv->num_cfp_rules); else - rule_index[0] = fs->location; + rule_index[1] = fs->location; + if (rule_index[1] > bcm_sf2_cfp_rule_size(priv)) + return -ENOSPC; /* Flag it as used (cleared on error path) such that we can immediately * obtain a second one to chain from. */ - set_bit(rule_index[0], priv->cfp.used); + set_bit(rule_index[1], priv->cfp.used); - rule_index[1] = find_first_zero_bit(priv->cfp.used, - bcm_sf2_cfp_rule_size(priv)); - if (rule_index[1] > bcm_sf2_cfp_rule_size(priv)) { + rule_index[0] = find_first_zero_bit(priv->cfp.used, + priv->num_cfp_rules); + if (rule_index[0] > bcm_sf2_cfp_rule_size(priv)) { ret = -ENOSPC; goto out_err; } @@ -715,14 +717,14 @@ static int bcm_sf2_cfp_ipv6_rule_set(str /* Flag the second half rule as being used now, return it as the * location, and flag it as unique while dumping rules */ - set_bit(rule_index[1], priv->cfp.used); + set_bit(rule_index[0], priv->cfp.used); set_bit(rule_index[1], priv->cfp.unique); fs->location = rule_index[1]; return ret; out_err: - clear_bit(rule_index[0], priv->cfp.used); + clear_bit(rule_index[1], priv->cfp.used); return ret; }