From patchwork Mon Jul 8 18:15:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13726968 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f225.google.com (mail-lj1-f225.google.com [209.85.208.225]) (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 80803145A14 for ; Mon, 8 Jul 2024 18:15:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720462560; cv=none; b=QireWdtcPoGB0k0K1m0fIr1YmujYW4aFQv6oCdj6aA6kjYr5kVmnJsvqvWNYF2TRYU76R729gUNlnz/l3hqttZotjlNS432PLEAUjdJXz0G04NgBgssXy1VOWTmyYBggPI67LPykmooBhwFzM5cyMZpO+L1bopQUfx41rGAlNHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720462560; c=relaxed/simple; bh=zQwyXlH5ZVF5TCm9+O1XVJlW7UMrvHWYI4dVKxhljRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Eo2Fnt3hKdwtvIx8GFYFBDM7CNAyG0CF3hv9yaQC6iHAIIGvqOJEtHMBg96TQ5100h14k43LqFJQuLZrtPg4MlA7/5H0YkLBFe25zOq1dG7gDncgeZWlBCCOklx5Qzupis09FeAKvHGmsC6hTvzvQCJqfe9BXwgMkK/JeMEkAPE= 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=MAmAPM5Q; arc=none smtp.client-ip=209.85.208.225 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="MAmAPM5Q" Received: by mail-lj1-f225.google.com with SMTP id 38308e7fff4ca-2ee75ffce77so51914241fa.3 for ; Mon, 08 Jul 2024 11:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1720462557; x=1721067357; 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=dV6Uuuc+7CMJHWF96ycy0YXjsqaz4AJvsOhj3qX4WxM=; b=MAmAPM5QfEHe9avUBi6+goCNXPKYf+5BVDkj21WpxGXT6HaRQuNdIHDfGCtkS4LNMr eaUBrXkiwr7B4BbKBtpIxL6fCyBQuKDyXKbZ0VY7A3J3Lbtrz8TS9lUqAbGIHpC/q4Yx vugI2d/YFTIcoRjZmUbXVtnDma4NB2c5x585OQZhpi7efTyncH5zTTbIjyTESa4lgHPq KnIqk5QIuXGR5HgSOWxJC3zJRNn9erSGL4+wYrMS0dNpoe9UBuw4ss4jgxtGfNMpteFf 3TWr5SAywOgtvQWBjFKVPOvTCBqUXlUKm9jgtH8XzuzrfN+RWBQAz4W8AWh6aVChYMFR IV5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720462557; x=1721067357; 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=dV6Uuuc+7CMJHWF96ycy0YXjsqaz4AJvsOhj3qX4WxM=; b=Wn5eGQz/Zz4dMKi8Oq9XVtZ4ANRWAGiPYbHxJtye6Y/M9SE1ljrnp5FtjZYWmyHOcR CtC0Hi9Q9+IuvayXBhXRhZ00suxTYXKMPo2BG0LxY8/1UuOysxa/Jr393HFe4H5mb1gh R628/yVOL0Xq/UyqnJxnheaToz+f9Pqty6HAEVriPn4yodd8GUfOWbAFwVpoMD+1WNoL rXlAt9PHH2hjPJVHkSPm0zMUs4aHJmn/O5LOEd5hwTnKKo2bznIyp4DKtDzuHGEypQDx 4V3a+W87FJewcvqVVYQB/kiBWgSnNRkPWs6/cDlGaJNHukQU5TfhjgEdyzgClrT9PEFN vKNQ== X-Forwarded-Encrypted: i=1; AJvYcCXJruPSMJYenyumSlFUyXNTDfFImSKs/18i+zGA7vhE2+WZjK3LR/z5anhjFfUoIqLLaKty3xxC8of/fHvVASRgJz93PHYJ X-Gm-Message-State: AOJu0YyZi/cql0GgTQYWSjyA6iMOWEHWNJWzTtIJrHhP13ajH/RYxXrs 2o4ewvL/GWg7u/BO+9ZHvsgVTiW8yOC0UGByrMQXmDFcHP1SuG2/XO8ygwDwmYGI65X8eqUr4oS 1m0SDMQW8+NOYKixYM8H0R/pEfHsYgkeF X-Google-Smtp-Source: AGHT+IF64yl9851lVilnVXaQ+AdD7M4I2+bnbnXS9xoAOv5flEQNX8j2ts7iI74lanVnsU5A9aw4NR3O9yhI X-Received: by 2002:a2e:3306:0:b0:2ee:8454:1c25 with SMTP id 38308e7fff4ca-2eeb316b020mr3937671fa.34.1720462556722; Mon, 08 Jul 2024 11:15:56 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id 38308e7fff4ca-2eeb342d71dsm49451fa.20.2024.07.08.11.15.56; Mon, 08 Jul 2024 11:15:56 -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 21AC760310; Mon, 8 Jul 2024 20:15:56 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sQsu3-00HP8v-PE; Mon, 08 Jul 2024 20:15:55 +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 v3 1/4] ipv4: fix source address selection with route leak Date: Mon, 8 Jul 2024 20:15:07 +0200 Message-ID: <20240708181554.4134673-2-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240708181554.4134673-1-nicolas.dichtel@6wind.com> References: <20240708181554.4134673-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 Reviewed-by: David Ahern --- net/ipv4/fib_semantics.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index f669da98d11d..8956026bc0a2 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2270,6 +2270,15 @@ 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; + + 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); + } }