Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp474398yba; Wed, 15 May 2019 04:47:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/jgR3Qo61Dp8z8Fd6lKDkohPaBIEt0bt3zgtv7uSjs/yxpY9daBdDg6K7Qkx/kV/vuzOv X-Received: by 2002:a17:902:5910:: with SMTP id o16mr42576265pli.289.1557920832916; Wed, 15 May 2019 04:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920832; cv=none; d=google.com; s=arc-20160816; b=uwJItkhHC8ADay9AMAP+N9Kv8KpONI9kUHOCNdKQTFlbuxD/73Z8eoosahvjRQTfU6 6h6crpEHUHzFKKuDL5MjDShpbLThP5YPmrxO7+V3Pf0qGhDmquWVDw44JZWhBgv779H2 pq4O2w3FLxbpM8MCIuqV/rCtmvlA1qk+xRPlaU6WI+F9ZLlNUhGpqiG1LVeVVuX8+Hns c4Nmx4LM166p2KcGA9grwE7r3SAjyKDWCklWhtYpYtYXXqnWIRacwU2Qlr0aGrDYDSpM EUQYR4MfrYQHg4jMNnW4YBBBX4sR8Bceo0Oe39+zQIdLQWNfimj8lOH9EzTyEqICqcPA lcGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=18IIsuTQBxl+esXsWZ9axA0YyUaigshw9ycYvNVu7cw=; b=EzQT1kyI6H2j0QEzGMYFjGBFJ9GytD0eqSRqv+BfbKVwPNUDYHrRO+Rv2aIJbFAOoC WyVsABvXGIzEU6Ha7zzETnoVoxt3BH+YFn5pZYRtqcxPhcnqfTY3MZXooPpqbCBVXmDE UVOZXpbihE+SGL/g4nEp6Pm+tAQfbP4V4zIs6O6SGMZPGHF8aV+4HkfYocD3px5WmR+P 24uU6SBgGMseOWvl3W0GR39BH+g3S07D/KVLYCC9dn1ipD9VQ70ZboaYqFOXYRepINJA zQF0B20g7zCewXuD8Ww9h/g54f1ijq4MSG3dt7ued0PAjJq+qeACTGu+Y81IdxpZ/XOx z8FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rrVGil3f; 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 ay3si1547797plb.298.2019.05.15.04.46.58; Wed, 15 May 2019 04:47:12 -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=rrVGil3f; 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 S1731696AbfEOLp6 (ORCPT + 99 others); Wed, 15 May 2019 07:45:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:36566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732038AbfEOLZr (ORCPT ); Wed, 15 May 2019 07:25:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 CCBFC20818; Wed, 15 May 2019 11:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919546; bh=kndu8SAtUtlE6O5XFX8Lvk1NrcXtcxLc7hvEAE7f7uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rrVGil3f0xxXfuHmiHR/UnBzhU5L2qSZxHM8STjL3nO3pHCiCxpu1wxO1XzcMhark Hq+saB1mK0OYYwg+97ZDpxC5N1bfHdJGZR01PKgIrI5R4slNTLZ5+VDu/LsnQuMnnF P9px8e88EQAXHUkO16HBs3JXC/qgnftaXr0PF4GQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Haller , Hangbin Liu , "David S. Miller" Subject: [PATCH 4.19 091/113] fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied Date: Wed, 15 May 2019 12:56:22 +0200 Message-Id: <20190515090700.540421230@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090652.640988966@linuxfoundation.org> References: <20190515090652.640988966@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hangbin Liu [ Upstream commit e9919a24d3022f72bcadc407e73a6ef17093a849 ] With commit 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule") we now able to check if a rule already exists. But this only works with iproute2. For other tools like libnl, NetworkManager, it still could add duplicate rules with only NLM_F_CREATE flag, like [localhost ~ ]# ip rule 0: from all lookup local 32766: from all lookup main 32767: from all lookup default 100000: from 192.168.7.5 lookup 5 100000: from 192.168.7.5 lookup 5 As it doesn't make sense to create two duplicate rules, let's just return 0 if the rule exists. Fixes: 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule") Reported-by: Thomas Haller Signed-off-by: Hangbin Liu Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/fib_rules.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -756,9 +756,9 @@ int fib_nl_newrule(struct sk_buff *skb, if (err) goto errout; - if ((nlh->nlmsg_flags & NLM_F_EXCL) && - rule_exists(ops, frh, tb, rule)) { - err = -EEXIST; + if (rule_exists(ops, frh, tb, rule)) { + if (nlh->nlmsg_flags & NLM_F_EXCL) + err = -EEXIST; goto errout_free; }