From patchwork Mon Jun 24 13:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13709450 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f100.google.com (mail-lf1-f100.google.com [209.85.167.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 918C613D51D for ; Mon, 24 Jun 2024 13:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; cv=none; b=sUAcqQNt/PztnKB8pQnR72T9uC1mbBUxrsDhjtDc3KSBy47VzIo2mT33tRVUBrw25U1MwcVNK92Im+TMddaJyp0Dwf+EO5OQYm3pgbEa7kErEXw1OnkK5Dz1vLJk8ABD/KuAYh8YBga7HkuEtKDQjaWUxJgAhIBhdQmypAnDhpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; c=relaxed/simple; bh=F18MNQqMgi2s1pXAA8VazUOW/a2/fCiXeYMprACDpHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ur2EEa1kC9orMNs9XsohodroW9WGo87AhQ6gyxty3IGT3RjU5p5WRBzSmtFR5I9cIbnUVdvtCqr1F6qXZvGpL50mp9sq6WXnkOtYTsxOputCT8HYfdxKTjbDFPz4fLq+jVHmXM5GaKq8k9C7H3AeW+8VmruKRcRIpWn6bafh8go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com; spf=pass smtp.mailfrom=6wind.com; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b=VQpIOSZ5; arc=none smtp.client-ip=209.85.167.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b="VQpIOSZ5" Received: by mail-lf1-f100.google.com with SMTP id 2adb3069b0e04-52cd9f9505cso3166589e87.0 for ; Mon, 24 Jun 2024 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1719234543; x=1719839343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cua0A6GEdu0iOk0GUptHeWMm27awSaljV0LV/Qv+59A=; b=VQpIOSZ5DnV8YzmSsUKwgl6J/svEeSgdfs33Vnl1dKAGSCpcDhvo0bbZcLpBt7ScEm JgFpfEnJeDYRZKliXsOhYcloninrfxjy8D2KMGmI8ruu+E6O1LhJvDaeB7cNtllcxxD4 iQz13uY0TKPTYwxAPsK3ES1oKdli8TS9szqVMHzH3JO4jS6LG1TivJpcmjC3vOGJ8uXC qY5YoYb0JNPV/ZxH6HPCMCezC3mkPu5PHXyAb/pGel6/bIyObKgATVx5WTBRkCNSmoDx H8+JqPvMVBNoPvV6UC51QVvZ5XuiP5tBoGgaGN3zLrhVlu6cPinxy+EF5oORSHeyekmc ZkgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234543; x=1719839343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cua0A6GEdu0iOk0GUptHeWMm27awSaljV0LV/Qv+59A=; b=XDZHzw8zpzJfYRnrqey5PQWBgbx3wwTOGGrc5G8aMch3pXRn4f2ROrCIXAjxzuP7h8 JxG8MZxCEhthSToSLxFoF7TywAzHMruzYQyTL3HbHZnIkhfWjpVwc8ZqtdUFcRVTS8eX xwSx480V9vZIg2O1+TJCNnC0TLM+158/XbnxPiW6iHOlvr9ec80aA9at/MJ2qi0JRbyw WmlrKoNTvUCzgwy1GyaEf66KvmcPZV3LCDSbN8n/1RSduRA1+KsQqsixQMD27xUSZYZU //Xmh3dk0cXBvmNk/IaPi5AEhrzP6S/mkJLF0OJxEtyko/uo6pqPjV+Aepz/lhFRyvkC FwEw== X-Forwarded-Encrypted: i=1; AJvYcCXPHzxMFdArTjaK61L+B1948JAfMu8IK1YSJH7KNvQqDBzP8G1xC29JjqHVd25pDE3QD/e0jxV9SjamK0C1e1jktnvRbFFS X-Gm-Message-State: AOJu0YyN4cFJKPzMgw4WPNJ682EHkvwiKuNgY9Vv4IwgbuxmrnCoUev2 s3q5kNZM2RWgOW7QyVl2GLjv/vZhBb3ZbhdXTNkshdTNw20QbP37luzzqWIvMWXExXCFpD2kN6W RTuVbbz/Iah4kNRNz2A//2c1mK2HagjpD X-Google-Smtp-Source: AGHT+IEBpaCODeI242sIP+AcMfTXd1Z+51gSpsbjgQUQQht0K2WifHxuQsjBq8JFYi/VigFtbtGnLlvQoPKX X-Received: by 2002:ac2:5f63:0:b0:52c:a002:1afc with SMTP id 2adb3069b0e04-52cdf7f66f2mr3244175e87.34.1719234542615; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id 5b1f17b1804b1-424817fcc5esm3530725e9.41.2024.06.24.06.09.02; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) X-Relaying-Domain: 6wind.com Received: from bretzel (bretzel.dev.6wind.com [10.17.1.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 495B86036F; Mon, 24 Jun 2024 15:09:02 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sLjRO-004067-03; Mon, 24 Jun 2024 15:09:02 +0200 From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, Nicolas Dichtel , stable@vger.kernel.org Subject: [PATCH net 1/4] ipv4: fix source address selection with route leak Date: Mon, 24 Jun 2024 15:07:53 +0200 Message-ID: <20240624130859.953608-2-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240624130859.953608-1-nicolas.dichtel@6wind.com> References: <20240624130859.953608-1-nicolas.dichtel@6wind.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org By default, an address assigned to the output interface is selected when the source address is not specified. This is problematic when a route, configured in a vrf, uses an interface from another vrf (aka route leak). The original vrf does not own the selected source address. Let's add a check against the output interface and call the appropriate function to select the source address. CC: stable@vger.kernel.org Fixes: 8cbb512c923d ("net: Add source address lookup op for VRF") Signed-off-by: Nicolas Dichtel --- net/ipv4/fib_semantics.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index f669da98d11d..459082f4936d 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2270,6 +2270,13 @@ void fib_select_path(struct net *net, struct fib_result *res, fib_select_default(fl4, res); check_saddr: - if (!fl4->saddr) - fl4->saddr = fib_result_prefsrc(net, res); + if (!fl4->saddr) { + struct net_device *l3mdev = dev_get_by_index_rcu(net, fl4->flowi4_l3mdev); + + if (!l3mdev || + l3mdev_master_dev_rcu(FIB_RES_DEV(*res)) == l3mdev) + fl4->saddr = fib_result_prefsrc(net, res); + else + fl4->saddr = inet_select_addr(l3mdev, 0, RT_SCOPE_LINK); + } }