Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2918102ybx; Fri, 8 Nov 2019 11:15:28 -0800 (PST) X-Google-Smtp-Source: APXvYqwTkUhez3ggyN3Xw8tHqt9F1rv59X6/gbESQWwKd6illSM0luSSc0pwOtwMHMeuLhEJ1Wi6 X-Received: by 2002:a17:906:6043:: with SMTP id p3mr3539226ejj.103.1573240528797; Fri, 08 Nov 2019 11:15:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573240528; cv=none; d=google.com; s=arc-20160816; b=0e0CrWfOCnToMO0cVb1ekVmnJ07NNlogBg/C49oWcHTuNPAw/OanzjbngovfNeUkI2 uREuSFBGmM/7yIyf8m/HXJ5cGraF1wpOaHOgInAPiegvoeyIkU0tHxFUgsJrIaWnhPhM Li1UyvtH/4DyyFBQSi9k2UMFIv5IJj/MbUJd8SAkGWbLCB8Fz9z81pCKnvcoocRk5k07 Wl6uqu6RZ3P0DKeKZlesBIKviWFeO5OEU7qctSeNKSX0/hPON3+Zo26YPZgj19E6Kd4M pffcnWJD/ZnsPMn496x4B4n6pDTfv73nzxHfxsRhX/HZ4ko87ax9WN3zdYW9B20T6/km mfvA== 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=HCpEdIF9vqWHHqtlRi6NJxXWyK1itmNRlyo+TLp/Q2U=; b=ke0vbeAQmX3RbaReSSrwhMm6QGUPWTuR87WHCjSeuBWuAQIU0+aomDkiH86rqj47i2 ZcdfgMfEGvKgtPMu6SqrJCnVKwc3CS9rkFywnA1KL673I+58mMdIIsgRFs9/BPXcrxE1 1aHYvZNKWPUV9Xtk9kpxkdCEeFP+k8VmD4gDvidA+kPhPpfDrw4RPGOxgEibx7OG92ZF FWJX5FhO8zeI7ltXIBUz3dZPSv2CgGpzjH3aF93g/GYpqlRqeEPAFAJrZuaZVu/Ijx+/ zXTtoJqfIXjUdOEhps80LYsJIRedlfXnJcWDMwWTR4qo/zH3ruOEGLJ3bY/Ff3bEl/R2 n+2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pAqPo4OD; 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 x21si4845017eda.366.2019.11.08.11.15.05; Fri, 08 Nov 2019 11:15:28 -0800 (PST) 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=pAqPo4OD; 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 S2403780AbfKHTJI (ORCPT + 99 others); Fri, 8 Nov 2019 14:09:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:40542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391738AbfKHTJG (ORCPT ); Fri, 8 Nov 2019 14:09:06 -0500 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 1117420673; Fri, 8 Nov 2019 19:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573240145; bh=gXIrIpHgfxXzKWXdKVXOIuIfmFXJaHKIE9oR2oniOSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pAqPo4ODirEJkxmpkWSsQX9xaBSc3h5Td+9koOCQzXk3Y93zPPt/ZKTmVbHO3XhkV z8X0JvWF4ZHjNygtn+sZ6eEWnO/ve6zPrIcJY/onIy1Kt9/q0992T73ldkFAvGvart dnicRJHuSWnSMCcJPmdzCD7qvb0FpFKXoydYQpl8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Abeni , David Ahern , "David S. Miller" , Beniamino Galvani Subject: [PATCH 5.3 103/140] ipv4: fix route update on metric change. Date: Fri, 8 Nov 2019 19:50:31 +0100 Message-Id: <20191108174911.442423763@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191108174900.189064908@linuxfoundation.org> References: <20191108174900.189064908@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: Paolo Abeni [ Upstream commit 0b834ba00ab5337e938c727e216e1f5249794717 ] Since commit af4d768ad28c ("net/ipv4: Add support for specifying metric of connected routes"), when updating an IP address with a different metric, the associated connected route is updated, too. Still, the mentioned commit doesn't handle properly some corner cases: $ ip addr add dev eth0 192.168.1.0/24 $ ip addr add dev eth0 192.168.2.1/32 peer 192.168.2.2 $ ip addr add dev eth0 192.168.3.1/24 $ ip addr change dev eth0 192.168.1.0/24 metric 10 $ ip addr change dev eth0 192.168.2.1/32 peer 192.168.2.2 metric 10 $ ip addr change dev eth0 192.168.3.1/24 metric 10 $ ip -4 route 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.0 192.168.2.2 dev eth0 proto kernel scope link src 192.168.2.1 192.168.3.0/24 dev eth0 proto kernel scope link src 192.168.2.1 metric 10 Only the last route is correctly updated. The problem is the current test in fib_modify_prefix_metric(): if (!(dev->flags & IFF_UP) || ifa->ifa_flags & (IFA_F_SECONDARY | IFA_F_NOPREFIXROUTE) || ipv4_is_zeronet(prefix) || prefix == ifa->ifa_local || ifa->ifa_prefixlen == 32) Which should be the logical 'not' of the pre-existing test in fib_add_ifaddr(): if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) && (prefix != addr || ifa->ifa_prefixlen < 32)) To properly negate the original expression, we need to change the last logical 'or' to a logical 'and'. Fixes: af4d768ad28c ("net/ipv4: Add support for specifying metric of connected routes") Reported-and-suggested-by: Beniamino Galvani Signed-off-by: Paolo Abeni Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/fib_frontend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c @@ -1147,7 +1147,7 @@ void fib_modify_prefix_metric(struct in_ if (!(dev->flags & IFF_UP) || ifa->ifa_flags & (IFA_F_SECONDARY | IFA_F_NOPREFIXROUTE) || ipv4_is_zeronet(prefix) || - prefix == ifa->ifa_local || ifa->ifa_prefixlen == 32) + (prefix == ifa->ifa_local && ifa->ifa_prefixlen == 32)) return; /* add the new */