From: Yuehaibing <yuehaibing@huawei.com>
To: Xin Long <lucien.xin@gmail.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
davem <davem@davemloft.net>, <kuba@kernel.org>,
network dev <netdev@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xfrm: policy: Only use mark as policy lookup key
Date: Thu, 23 Apr 2020 10:25:58 +0800 [thread overview]
Message-ID: <02a56d2c-8d27-f53a-d9e3-c25bd03677c8@huawei.com> (raw)
In-Reply-To: <CADvbK_cEgKCEGRJU1v=FAdFNoh3TzD+cZLiKUtsMLHJh3JqOfg@mail.gmail.com>
On 2020/4/22 23:41, Xin Long wrote:
> On Wed, Apr 22, 2020 at 8:18 PM Yuehaibing <yuehaibing@huawei.com> wrote:
>>
>> On 2020/4/22 17:33, Steffen Klassert wrote:
>>> On Tue, Apr 21, 2020 at 10:31:49PM +0800, YueHaibing wrote:
>>>> While update xfrm policy as follow:
>>>>
>>>> ip -6 xfrm policy update src fd00::1/128 dst fd00::2/128 dir in \
>>>> priority 1 mark 0 mask 0x10
>>>> ip -6 xfrm policy update src fd00::1/128 dst fd00::2/128 dir in \
>>>> priority 2 mark 0 mask 0x00
>>>> ip -6 xfrm policy update src fd00::1/128 dst fd00::2/128 dir in \
>>>> priority 2 mark 0 mask 0x10
>>>>
>>>> We get this warning:
>>>>
>>>> WARNING: CPU: 0 PID: 4808 at net/xfrm/xfrm_policy.c:1548
>>>> Kernel panic - not syncing: panic_on_warn set ...
>>>> CPU: 0 PID: 4808 Comm: ip Not tainted 5.7.0-rc1+ #151
>>>> Call Trace:
>>>> RIP: 0010:xfrm_policy_insert_list+0x153/0x1e0
>>>> xfrm_policy_inexact_insert+0x70/0x330
>>>> xfrm_policy_insert+0x1df/0x250
>>>> xfrm_add_policy+0xcc/0x190 [xfrm_user]
>>>> xfrm_user_rcv_msg+0x1d1/0x1f0 [xfrm_user]
>>>> netlink_rcv_skb+0x4c/0x120
>>>> xfrm_netlink_rcv+0x32/0x40 [xfrm_user]
>>>> netlink_unicast+0x1b3/0x270
>>>> netlink_sendmsg+0x350/0x470
>>>> sock_sendmsg+0x4f/0x60
>>>>
>>>> Policy C and policy A has the same mark.v and mark.m, so policy A is
>>>> matched in first round lookup while updating C. However policy C and
>>>> policy B has same mark and priority, which also leads to matched. So
>>>> the WARN_ON is triggered.
>>>>
>>>> xfrm policy lookup should only be matched when the found policy has the
>>>> same lookup keys (mark.v & mark.m) no matter priority.
>>>>
>>>> Fixes: 7cb8a93968e3 ("xfrm: Allow inserting policies with matching mark and different priorities")
>>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>>> ---
>>>> net/xfrm/xfrm_policy.c | 16 +++++-----------
>>>> 1 file changed, 5 insertions(+), 11 deletions(-)
>>>>
>>>> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
>>>> index 297b2fd..67d0469 100644
>>>> --- a/net/xfrm/xfrm_policy.c
>>>> +++ b/net/xfrm/xfrm_policy.c
>>>> @@ -1436,13 +1436,7 @@ static void xfrm_policy_requeue(struct xfrm_policy *old,
>>>> static bool xfrm_policy_mark_match(struct xfrm_policy *policy,
>>>> struct xfrm_policy *pol)
>>>> {
>>>> - u32 mark = policy->mark.v & policy->mark.m;
>>>> -
>>>> - if (policy->mark.v == pol->mark.v && policy->mark.m == pol->mark.m)
>>>> - return true;
>>>> -
>>>> - if ((mark & pol->mark.m) == pol->mark.v &&
>>>> - policy->priority == pol->priority)
>>>
>>> If you remove the priority check, you can't insert policies with matching
>>> mark and different priorities anymore. This brings us back the old bug.
>>
>> Yes, this is true.
>>
>>>
>>> I plan to apply the patch from Xin Long, this seems to be the right way
>>> to address this problem.
>>
>> That still brings an issue, update like this:
>>
>> policy A (mark.v = 1, mark.m = 0, priority = 1)
>> policy B (mark.v = 1, mark.m = 0, priority = 1)
>>
>> A and B will all in the list.
> I think this is another issue even before:
> 7cb8a93968e3 ("xfrm: Allow inserting policies with matching mark and
> different priorities")
>
>>
>> So should do this:
>>
>> static bool xfrm_policy_mark_match(struct xfrm_policy *policy,
>> struct xfrm_policy *pol)
>> {
>> - u32 mark = policy->mark.v & policy->mark.m;
>> -
>> - if (policy->mark.v == pol->mark.v && policy->mark.m == pol->mark.m)
>> - return true;
>> -
>> - if ((mark & pol->mark.m) == pol->mark.v &&
>> + if ((policy->mark.v & policy->mark.m) == (pol->mark.v & pol->mark.m) &&
>> policy->priority == pol->priority)
>> return true;
> "mark.v & mark.m" looks weird to me, it should be:
> ((something & mark.m) == mark.v)
>
> So why should we just do this here?:
> (policy->mark.v == pol->mark.v && policy->mark.m == pol->mark.m &&
> policy->priority == pol->priority)
This leads to this issue:
ip -6 xfrm policy add src fd00::1/128 dst fd00::2/128 dir in mark 0x00000001 mask 0x00000005
ip -6 xfrm policy add src fd00::1/128 dst fd00::2/128 dir in mark 0x00000001 mask 0x00000003
the two policies will be in list, which should not be allowed.
>
>>
>>
>>
>>>
>>> .
>>>
>>
>
> .
>
next prev parent reply other threads:[~2020-04-23 2:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 14:31 [PATCH] xfrm: policy: Only use mark as policy lookup key YueHaibing
2020-04-22 9:33 ` Steffen Klassert
2020-04-22 12:18 ` Yuehaibing
2020-04-22 15:41 ` Xin Long
2020-04-22 15:54 ` Xin Long
2020-04-23 2:25 ` Yuehaibing [this message]
2020-04-23 6:37 ` Xin Long
2020-04-23 8:40 ` Yuehaibing
2020-04-23 9:43 ` Xin Long
2020-04-24 3:48 ` Yuehaibing
2020-04-30 6:30 ` Yuehaibing
2020-04-22 12:53 ` [PATCH v2] xfrm: policy: Fix xfrm policy match YueHaibing
2020-05-15 8:39 ` Yuehaibing
2020-05-19 8:53 ` Steffen Klassert
2020-05-21 6:49 ` Xin Long
2020-05-22 1:45 ` Yuehaibing
2020-05-22 5:49 ` Xin Long
2020-05-22 12:39 ` Yuehaibing
2020-05-23 9:02 ` Xin Long
2020-05-25 3:04 ` Yuehaibing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=02a56d2c-8d27-f53a-d9e3-c25bd03677c8@huawei.com \
--to=yuehaibing@huawei.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).