Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp669785ybg; Mon, 1 Jun 2020 11:14:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxAY3nrsPL1Tl7MPZ2wwIo8ejPkLDOgwfBsJ9CU6dqWAldfxZeYa0tuPnlb9krFgkoLwN6 X-Received: by 2002:a17:906:9243:: with SMTP id c3mr20251679ejx.400.1591035275090; Mon, 01 Jun 2020 11:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591035275; cv=none; d=google.com; s=arc-20160816; b=tedtKDIY01bHZxK3LOSLk9j0JAufGh0Q+3eRLHDB72+bTYHP8hVWVApGWEPSkqcx8Q Jjk+gf8jUG3pbpfJeOGv0k2Wk/4vCXjQeHra0BtQFUDU60GFpXV6NrvdwfHCK4V4JksW jv8I2GT2TLD6/U+pZrw+mT7uy1qo00UQuu7uJndJ1pMlCEt9hw1QROZN1rix5z5sQYTH pNkz0x52nd+9Ae66dd+QL2/D0GeLGuFtnUBGzXUKHc9wuROSnpJ6a5cTlKMGL4UMx8cH UN2d8h5EaImlggPj7HarQ4hIOmZfFqTmD3VHHACMNiW5xpjXQrvncZSFvIzBq6PWnsdg OgXQ== 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=E416xQum5jO0K09qjrpdbbS83c7ig7uD+16tzEacgIg=; b=zlVVBXP5kkrlYGKcLXVfHqu6bwZIT4KM6ASbARr0bfMYXoYcPp9q/P9yszXZE+0rEb li3hqdKDZlIyqfEd26A8bEX9aij7Z5H6HQ0NHKvdaVREcJq5TwXdlWYQSFWll2CmN/BR CwdsQZMBJew0C4do5Cdr088aLNpHmkh2RlrIuJEbVWM6BQkoMLPBSzyRwbkn9mZa5Lpo V+L7wp7hSyyQ9Owp3nNX6ffH1UUALPMSEnJLcx8KR0ulMSYAKuGvTsNtgYeMzIJiMdZP BqKplsmw86IVhDg9BBh+2AawbFXKLboEXvbGLdxvIdHI25E+siklA5Y1Nac85AU7+0VD Pqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=15uE7JdI; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si85810edr.468.2020.06.01.11.14.12; Mon, 01 Jun 2020 11:14:35 -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=@kernel.org header.s=default header.b=15uE7JdI; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731007AbgFASKe (ORCPT + 99 others); Mon, 1 Jun 2020 14:10:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730980AbgFASKU (ORCPT ); Mon, 1 Jun 2020 14:10:20 -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 523582065C; Mon, 1 Jun 2020 18:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591035019; bh=IOw+J8XmQdEWpk3fJCeMAQfnTr/XR0y/8woKI1j5Bks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=15uE7JdIybq0LPsLYyvdX8bulTieTxA+h7DFFtfmSjdGvo/fwwFLUkaNnFUDaOUut GbEVsVtaa4wlZ9YDiOipfTuUIUNBAEU2iiQhuW/AGIUNCA5+cc0hK9gXWLMkdrvULb axgZHPpXkDNdAlgiQOtj4/Lu9PoLuaTHoabxyjMU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiumei Mu , Xin Long , Steffen Klassert Subject: [PATCH 5.4 117/142] xfrm: fix a warning in xfrm_policy_insert_list Date: Mon, 1 Jun 2020 19:54:35 +0200 Message-Id: <20200601174049.979542925@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200601174037.904070960@linuxfoundation.org> References: <20200601174037.904070960@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: Xin Long commit ed17b8d377eaf6b4a01d46942b4c647378a79bdd upstream. This waring can be triggered simply by: # ip xfrm policy update src 192.168.1.1/24 dst 192.168.1.2/24 dir in \ priority 1 mark 0 mask 0x10 #[1] # ip xfrm policy update src 192.168.1.1/24 dst 192.168.1.2/24 dir in \ priority 2 mark 0 mask 0x1 #[2] # ip xfrm policy update src 192.168.1.1/24 dst 192.168.1.2/24 dir in \ priority 2 mark 0 mask 0x10 #[3] Then dmesg shows: [ ] WARNING: CPU: 1 PID: 7265 at net/xfrm/xfrm_policy.c:1548 [ ] RIP: 0010:xfrm_policy_insert_list+0x2f2/0x1030 [ ] Call Trace: [ ] xfrm_policy_inexact_insert+0x85/0xe50 [ ] xfrm_policy_insert+0x4ba/0x680 [ ] xfrm_add_policy+0x246/0x4d0 [ ] xfrm_user_rcv_msg+0x331/0x5c0 [ ] netlink_rcv_skb+0x121/0x350 [ ] xfrm_netlink_rcv+0x66/0x80 [ ] netlink_unicast+0x439/0x630 [ ] netlink_sendmsg+0x714/0xbf0 [ ] sock_sendmsg+0xe2/0x110 The issue was introduced by Commit 7cb8a93968e3 ("xfrm: Allow inserting policies with matching mark and different priorities"). After that, the policies [1] and [2] would be able to be added with different priorities. However, policy [3] will actually match both [1] and [2]. Policy [1] was matched due to the 1st 'return true' in xfrm_policy_mark_match(), and policy [2] was matched due to the 2nd 'return true' in there. It caused WARN_ON() in xfrm_policy_insert_list(). This patch is to fix it by only (the same value and priority) as the same policy in xfrm_policy_mark_match(). Thanks to Yuehaibing, we could make this fix better. v1->v2: - check policy->mark.v == pol->mark.v only without mask. Fixes: 7cb8a93968e3 ("xfrm: Allow inserting policies with matching mark and different priorities") Reported-by: Xiumei Mu Signed-off-by: Xin Long Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/xfrm/xfrm_policy.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1433,12 +1433,7 @@ static void xfrm_policy_requeue(struct x 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 == pol->mark.v && policy->priority == pol->priority) return true;