Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp825614ybz; Wed, 22 Apr 2020 08:39:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJkwNqX1gb2w+KrUzjakD/WiVQ3pMUV8En1cDwsPEHCQAw6XGD5yWN+nEieM4tY++zuCcIu X-Received: by 2002:a17:907:2711:: with SMTP id w17mr26216517ejk.116.1587569952613; Wed, 22 Apr 2020 08:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587569952; cv=none; d=google.com; s=arc-20160816; b=F9ym+zbpbLqBMrMshn9t8JwTWKGiV970sCkJhxtlQSGLQlNCREps3Es2p4k+htIVKN B3v/n4L6iaVCVoOMZewceXRr2yDyJ7EEmsE6OYDuaGaMerzKRA+aCgalJhodzKDDtWzH rd81WZFZBiQWVIFnqiG6QrvRz8Wf5lMD0yiYWm/HXzxXH9ZohhiHCqVl66FohVYk/jta i67hJfhw88aitAhIt6xm75yXqrf2ovcL+CF1zUA/sRj7/kQT4Xh5v0MD0rjZSFhHyWxB WZ2kYPJ0fKwewK7uJHfYh4FwyUuHn7zN8oY/v5V57No75KCkXazGP5zjK8izyhrvHF5m g7QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=6E0ZwMhEkyIOFS7vsF8aXBJ+5W1xoavdwFkr6dPgnvY=; b=k+kRu3xG0oAyisTOjepgRyzgvh/3jm6UhW68hCtjINcwZhAFIt/Lwd/pKzmbnE2sn4 8rkGpOgucWtgtd8EhwVBDKV0lvVNvIoSRZPloPLLqq2AHymSj/khybxiSRI9arQb64vp KES9PmiIIP8HhG1rZyPWv74cUpT1I4+P7ku8XYFIGXSetpbJOo3W4Uomu1PNHxb9MI18 TukC2AAnOVC89JFmWIHGD+2TvoR3dCe4+XmQgjFzR6QcegnKhv33tuZKG++dOo9iqQjv g77kvYlpRakDZeC69lUw8OZH4N0vZcdy64QVIATo9CUnKgHyx/hqpg8YMGcrHlLenR1+ E4uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q1Psnhoh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v2si3722996ejx.85.2020.04.22.08.38.44; Wed, 22 Apr 2020 08:39:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q1Psnhoh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbgDVPgq (ORCPT + 99 others); Wed, 22 Apr 2020 11:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgDVPgq (ORCPT ); Wed, 22 Apr 2020 11:36:46 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C02C03C1A9; Wed, 22 Apr 2020 08:36:45 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id b11so2941271wrs.6; Wed, 22 Apr 2020 08:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6E0ZwMhEkyIOFS7vsF8aXBJ+5W1xoavdwFkr6dPgnvY=; b=Q1PsnhohiFBFpKKgWU1XNjCS8/QSLVpwLf648QJrZ9zko1pqsTC+ttb8CdT3wAijk9 b1ufPO5uRaYRSkEiZVOlUUxk74qhvQ+SVQ0qexFMhZzEB6rPoJD0QWAlOOhL7HJvzr/f 9Q+ukWTYEZzN2HD/DtT8IO0mdCmAQH7zo29942pmikD9jVD0/An40u8RzGD0i5qwtrzJ RI4KbSdXqRWXnOLVdfgQ4gzU5P8c+OJC9wL6yU9MfDbP+fFUsYJckO7McwVx/+cB8kn4 RY+/Oc4afcNhR46DFI8JguIHT16eqOYBVxFbxRUIGCvqUOFeutuepWMKhh0nS88mB7hq cL1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6E0ZwMhEkyIOFS7vsF8aXBJ+5W1xoavdwFkr6dPgnvY=; b=HRQXvUbPviOsXYvHlKmO3z8FhqVN5xA7FSfhVl8hkUvTyFnTNGjUfKcU2im2Okc0yb yIZWvvU8Q5sE9/skQihdOOeuCC/hZIXRxSbbwh8wGk9zSLqeqLzgKOOHBP8DUX7P8zFn qKr0Il8/jq404Z8k/YfeC9/LsTdqUjv69yRHhLUGvUnscQDhVCx/X1aPvLMCNQuj5+xS 5AHUM5xyuANL9w/Z+EeWzMLo/glWMA4AzWRJGIZ7iYlAC/KBIxcAiBp3BK5574169H2b U+CzAwdiKndgRg7/jzbJbLrVbbN6NYF1J0g9FcSYFAJbfA+s9enN9wgon1itXAgYNB4/ a4gA== X-Gm-Message-State: AGi0PuaZwnB4273qzKEgbYOtrFFak52p/hVUcZviyFuTw6wwZKz7bGH1 9ZF1iOVyraKUTFuxP4UIVKsewne15XEF07Rekeg= X-Received: by 2002:adf:cd0a:: with SMTP id w10mr29732306wrm.404.1587569804501; Wed, 22 Apr 2020 08:36:44 -0700 (PDT) MIME-Version: 1.0 References: <20200421143149.45108-1-yuehaibing@huawei.com> <20200422093344.GY13121@gauss3.secunet.de> <1650fd55-dd70-f687-88b6-d32a04245915@huawei.com> In-Reply-To: <1650fd55-dd70-f687-88b6-d32a04245915@huawei.com> From: Xin Long Date: Wed, 22 Apr 2020 23:41:37 +0800 Message-ID: Subject: Re: [PATCH] xfrm: policy: Only use mark as policy lookup key To: Yuehaibing Cc: Steffen Klassert , Herbert Xu , davem , kuba@kernel.org, network dev , LKML 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 On Wed, Apr 22, 2020 at 8:18 PM Yuehaibing 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 > >> --- > >> 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) > > > > > > > . > > >