aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-02-28 22:25:18 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-02-29 09:48:21 +0100
commitf15be719b370ab694b933ab7ceb7fc3481687284 (patch)
tree724183bd198c19be95bd2957936768ef318b901c
parent3b59b9748aa13a244c173585dfbaf79dfff9ea8f (diff)
downloadpasst-f15be719b370ab694b933ab7ceb7fc3481687284.tar
passt-f15be719b370ab694b933ab7ceb7fc3481687284.tar.gz
passt-f15be719b370ab694b933ab7ceb7fc3481687284.tar.bz2
passt-f15be719b370ab694b933ab7ceb7fc3481687284.tar.lz
passt-f15be719b370ab694b933ab7ceb7fc3481687284.tar.xz
passt-f15be719b370ab694b933ab7ceb7fc3481687284.tar.zst
passt-f15be719b370ab694b933ab7ceb7fc3481687284.zip
tap: Disallow loopback addresses on tap interface
The "tap" interface, whether it's actually a tuntap device or a qemu socket, presents a virtual external link between different network hosts. Hence, loopback addresses make no sense there. However, nothing prevents the guest from putting bogus packets with loopback addresses onto the interface and it's not entirely clear what effect that will have on passt. Explicitly test for such packets and drop them. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tap.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tap.c b/tap.c
index 8a9a68b..3a66621 100644
--- a/tap.c
+++ b/tap.c
@@ -610,6 +610,16 @@ resume:
l4_len = htons(iph->tot_len) - hlen;
+ if (IN4_IS_ADDR_LOOPBACK(&iph->saddr) ||
+ IN4_IS_ADDR_LOOPBACK(&iph->daddr)) {
+ char sstr[INET_ADDRSTRLEN], dstr[INET_ADDRSTRLEN];
+
+ debug("Loopback address on tap interface: %s -> %s",
+ inet_ntop(AF_INET, &iph->saddr, sstr, sizeof(sstr)),
+ inet_ntop(AF_INET, &iph->daddr, dstr, sizeof(dstr)));
+ continue;
+ }
+
if (iph->saddr && c->ip4.addr_seen.s_addr != iph->saddr)
c->ip4.addr_seen.s_addr = iph->saddr;
@@ -766,6 +776,15 @@ resume:
if (!(l4h = ipv6_l4hdr(in, i, sizeof(*eh), &proto, &l4_len)))
continue;
+ if (IN6_IS_ADDR_LOOPBACK(saddr) || IN6_IS_ADDR_LOOPBACK(daddr)) {
+ char sstr[INET6_ADDRSTRLEN], dstr[INET6_ADDRSTRLEN];
+
+ debug("Loopback address on tap interface: %s -> %s",
+ inet_ntop(AF_INET6, saddr, sstr, sizeof(sstr)),
+ inet_ntop(AF_INET6, daddr, dstr, sizeof(dstr)));
+ continue;
+ }
+
if (IN6_IS_ADDR_LINKLOCAL(saddr)) {
c->ip6.addr_ll_seen = *saddr;