]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.9/fib_rules-return-0-directly-if-an-exactly-same-rule-exists-when-nlm_f_excl-not-supplied.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.9 / fib_rules-return-0-directly-if-an-exactly-same-rule-exists-when-nlm_f_excl-not-supplied.patch
1 From foo@baz Wed 15 May 2019 09:45:15 AM CEST
2 From: Hangbin Liu <liuhangbin@gmail.com>
3 Date: Tue, 7 May 2019 17:11:18 +0800
4 Subject: fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied
5
6 From: Hangbin Liu <liuhangbin@gmail.com>
7
8 [ Upstream commit e9919a24d3022f72bcadc407e73a6ef17093a849 ]
9
10 With commit 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to
11 fib_nl_newrule") we now able to check if a rule already exists. But this
12 only works with iproute2. For other tools like libnl, NetworkManager,
13 it still could add duplicate rules with only NLM_F_CREATE flag, like
14
15 [localhost ~ ]# ip rule
16 0: from all lookup local
17 32766: from all lookup main
18 32767: from all lookup default
19 100000: from 192.168.7.5 lookup 5
20 100000: from 192.168.7.5 lookup 5
21
22 As it doesn't make sense to create two duplicate rules, let's just return
23 0 if the rule exists.
24
25 Fixes: 153380ec4b9 ("fib_rules: Added NLM_F_EXCL support to fib_nl_newrule")
26 Reported-by: Thomas Haller <thaller@redhat.com>
27 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
28 Signed-off-by: David S. Miller <davem@davemloft.net>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 ---
31 net/core/fib_rules.c | 6 +++---
32 1 file changed, 3 insertions(+), 3 deletions(-)
33
34 --- a/net/core/fib_rules.c
35 +++ b/net/core/fib_rules.c
36 @@ -429,9 +429,9 @@ int fib_nl_newrule(struct sk_buff *skb,
37 if (rule->l3mdev && rule->table)
38 goto errout_free;
39
40 - if ((nlh->nlmsg_flags & NLM_F_EXCL) &&
41 - rule_exists(ops, frh, tb, rule)) {
42 - err = -EEXIST;
43 + if (rule_exists(ops, frh, tb, rule)) {
44 + if (nlh->nlmsg_flags & NLM_F_EXCL)
45 + err = -EEXIST;
46 goto errout_free;
47 }
48