From patchwork Wed Jul 10 08:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13728991 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f99.google.com (mail-lf1-f99.google.com [209.85.167.99]) (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 D0E4284D29 for ; Wed, 10 Jul 2024 08:15:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720599327; cv=none; b=Jfs0vSRnf32LR7bNZXJbzm/BOgjRWYpFdWPSCZVoJGibr7UNJhBt/XgkiC0BA5pOm0dosragzKHlP5fSWi3GGL/j7+/1ELk2ZeNafMgnao2NbQtQ1AKVd5aWo/xNxsRDCvisrEzx6Gz48hXpJVHky74fdS39YiqCGwIOB/HjizI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720599327; c=relaxed/simple; bh=L9cYX0FZOqsEWUS6Dl4jXBnuh+p+V+nVGgMuCjsSSHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V4yEJzuiWAITxyJ1DlU9lLCmgMV+UL8ixUBsa82Kgoh4YYuoUzHQS7Q/Vg6/AOx0+otWdQmMIpdBKxzixbznkd0W/PatddiUwJDBDwkB5cxS2CgAAOweFE7ITckIXxU7kT39BcSll5nnBSIXE3PJ6WmzKJDYlpJcrz3pPVTMupM= 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=DnXLFb9h; arc=none smtp.client-ip=209.85.167.99 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="DnXLFb9h" Received: by mail-lf1-f99.google.com with SMTP id 2adb3069b0e04-52ea5dc3c66so8517410e87.3 for ; Wed, 10 Jul 2024 01:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1720599324; x=1721204124; 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=vHfy2kRUgaVp+I9p+R/nnBTbFpFOafOVt67JpL5cYvA=; b=DnXLFb9hPzDzRKcgU99mfhzZSYxsMYGUzKisZIt7nrzvimLnw38chgqDdyh9cCGgFN FUSMf6HM27LEZ7ICZoFxyhb4S1gXwN9FMTaWsME6AWPLWFPeTyw+WCduODLnqRWuevnt D+MmyInXNi/E5ZfhiedGhWpZu5YQIFj7QHrvoijcWz/5mON+MI3dBCBv6fuO2efF5oXn ezbMr5BV5L1cXQ9ix3Goi8DGEZUDts6ZHwPCzvldKjewHXJjpZQZJ2rupD7CnBFgHi4s TzrqwVOxUjJv2cfb74F+WiG9yTOZQLtb7rTrGCt5DKLQ0eArxImE3kfbIxrkYp2sVejw dm6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720599324; x=1721204124; 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=vHfy2kRUgaVp+I9p+R/nnBTbFpFOafOVt67JpL5cYvA=; b=ZqIlYFzQZeXW9bQwtllIb2c0SUtJBNNhsgxFUzBjZnhu5Xvi4+QBF3G1c+2aqB4g+x VaMJxJVffSAVRv+bexE7BGkbyqkTtk+Ncj53JTQAeyS9/86d+0axBL1dpj5MmFWkMi7U 5y0aJr3BSWXQPyJYSLVscJy/3PisO6O4TVmN6oU5iVx3W6VRC25DnWunbYPHZDzMaIR7 7+xv3ou4LkpmM7+k3Nl+1zfCB3UANzYQ+LUTRsX4uhS16tnaxjlPL5L9bOFJwmG9OWKs LTGo/R20BRTGxy6Ed7m2K/ap4rAp7FvgyAIdtlHdBp2grvE3SUuY7TqnxSnmbKtVy9KX pdew== X-Forwarded-Encrypted: i=1; AJvYcCUePM/Kfl9NaHA7IoHLQPLznkT2ZpzBe9kxV9yiTR6i6/o9zAHDiRumwfa8uPYlosqWc+Pxvft082q1cuB7J593MABlu0yr X-Gm-Message-State: AOJu0YwPDFBedh4geMp3Qft6/MOXaCCnA9ak9VnC0+JUG3LAtBgTTSYd ZdE8GRoPapYFV9X9wmVIwf0bi1cPCEPI6taWRomqT9WM4kMtLXcDxLNH08MnGRXxkMospX1a2z1 5AQdT9mVnWtfMnf88iFTaOBuilQJP0fZS X-Google-Smtp-Source: AGHT+IHtfnocm4ldsA4+yF3b0rhj3hqvP8B6rA8W27iPtRI7FPGB+HWm8fxx1/B2ysSk2iRIP5gO/ySptU45 X-Received: by 2002:a05:6512:3b90:b0:52c:76ac:329b with SMTP id 2adb3069b0e04-52eb99a35dfmr3905436e87.35.1720599323983; Wed, 10 Jul 2024 01:15:23 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id a640c23a62f3a-a780a8535a1sm694966b.224.2024.07.10.01.15.23; Wed, 10 Jul 2024 01:15:23 -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 8228560117; Wed, 10 Jul 2024 10:15:23 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sRSTz-00Fz6w-7h; Wed, 10 Jul 2024 10:15:23 +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 v4 1/4] ipv4: fix source address selection with route leak Date: Wed, 10 Jul 2024 10:14:27 +0200 Message-ID: <20240710081521.3809742-2-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240710081521.3809742-1-nicolas.dichtel@6wind.com> References: <20240710081521.3809742-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); + } }