From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=J4BzE0NM; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id ECEA95A0262 for ; Fri, 10 Jul 2026 15:40:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783690807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ir96cw7wAbT0/6cJZU7B4kVrVl68YRZAjivwtDrn+co=; b=J4BzE0NMX13PclHITE2wJO40fQwY6grVSqwGwbcIu+FwWZyugEYnEyoBJFSZtQPs9oei13 x+fRyVhivpRxIVSuEfLzgo5vP6hR76wxvK/GlVJQfqMwwDwEYJ1SGnVb/+rCmUXWuJKnvG gmWKcPfBO27x8LHERpAtn+3nSJwh5Bk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-Q25YV85cOBerBsa43IdsSg-1; Fri, 10 Jul 2026 09:40:06 -0400 X-MC-Unique: Q25YV85cOBerBsa43IdsSg-1 X-Mimecast-MFC-AGG-ID: Q25YV85cOBerBsa43IdsSg_1783690806 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-92e9a2b95b5so203706685a.2 for ; Fri, 10 Jul 2026 06:40:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783690806; x=1784295606; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Ir96cw7wAbT0/6cJZU7B4kVrVl68YRZAjivwtDrn+co=; b=nXvUjeQdx40n9IqC/rDvZowzRxbq1f7IlMnXgtGXXQkinEI1ynwDDIqVuPrD9pHvmi AA8TSosMgKlp+jYdaWl8iRAlVCQWpbotzK5N/2AsPUg4of3wVJYt2iSKjSKwQzEYjlhC ZM1U4kUeDXfPVziIk5DJVS6WqWUTajiBLnlwpPVR9jyIHeK+vuUHlsoLCW9Pu+dflsHQ sToOIWKPZRlEVPt7tS01a6LixqjT6dNyw+lt5t8f1B5wrNMKFK186c89sbRUe7EUPJfl wwqPW/hD6GEPg3Cd/rdaI1axhfbZaEJ8fGCuZehghvvCGJAjAZKSOkNbnN/GwcYPH5hv IJFg== X-Forwarded-Encrypted: i=1; AHgh+RpIfKioiln02+asvtZp5RxzdBJoa9MFXIqz4WtrZr/LtJf/8h5KOfhKkoiizcChH0Zz2l+5F0FPH/0=@passt.top X-Gm-Message-State: AOJu0YzILjTA5FcJgm2mmAZ6fN+btxFhaiEhb5UOEpP57SYdY2kVLOpw oLFm8SQZJmffDvaX/XvFt+ZaHiBZti6/LWZCs87/PzdFWwZ7CVUQTjO2lyu4LkOklUoXZiEhs9Z 3Ib6ObZYmVL7W8NwQdNS8t+WGDueFU59YXRP2SYbLarux0Dew+Hma4w== X-Gm-Gg: AfdE7cmzcA/Rbfq4zQDh3lp+ksR4VThh6uCQHSnMWoUSI4JFnrzjuTkGASs7jqMtXHf WF6efo/nMyqRyaS6/KcX9nT3zqfbLm3JsxVMmWwrVBa7LP/NDc5qiH4VURtiyK/WM4Wbtf3pD2T edtv0ncuKakJJ9zWGzYZYghpRV3ohmggfGnCBBZMK+r/dvn7krX1mtX/hTHbcIlNGds7M4MFe9C XwwMpQ5KHIHpetTWJuOWkZ/dgiRL9ba963UIxirM7oZhz4/miL5TinEFxJfjm+xyIUs1zdzoKT0 j9svTU4wSdEaPIcgYJcIsYwqlR5T/3u2cV7p0u86NReBSIhSwNSuntkpY/PLOWboqz3dfoKAKk/ eMk6mgfODYzxFohikr0pNbaTCNXfMzRdkux2KUloMUVreNPxOkvTxfeaPRwX2OTk5EJ1N15hMnk w+Pc0= X-Received: by 2002:a05:620a:618d:b0:92e:c118:1898 with SMTP id af79cd13be357-92ecf8ec64fmr1259692785a.75.1783690805694; Fri, 10 Jul 2026 06:40:05 -0700 (PDT) X-Received: by 2002:a05:620a:618d:b0:92e:c118:1898 with SMTP id af79cd13be357-92ecf8ec64fmr1259685685a.75.1783690805053; Fri, 10 Jul 2026 06:40:05 -0700 (PDT) Received: from [192.168.2.15] (lnsm6-montreal02-142-122-43-198.internet.virginmobile.ca. [142.122.43.198]) by smtp.gmail.com with ESMTPSA id af79cd13be357-92ee5d68e5fsm192925285a.43.2026.07.10.06.40.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jul 2026 06:40:04 -0700 (PDT) Message-ID: <88c01537-385f-40ed-821c-ef02f4c742b8@redhat.com> Date: Fri, 10 Jul 2026 09:40:03 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/6] tap: Guard IPv6 tail size subtraction against underflow To: David Gibson References: <20260709215656.1351549-1-jmaloy@redhat.com> <20260709215656.1351549-4-jmaloy@redhat.com> From: Jon Maloy In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Gv3nCe2wOnU8Ab__MHQy6JKVl9y5C3E_I1dEVE3FZbE_1783690806 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: AMVLEXT2V3PCKK5GEW7ERXOUE36N6RVK X-Message-ID-Hash: AMVLEXT2V3PCKK5GEW7ERXOUE36N6RVK X-MailFrom: jmaloy@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: sbrivio@redhat.com, passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2026-07-09 21:36, David Gibson wrote: > On Thu, Jul 09, 2026 at 05:56:53PM -0400, Jon Maloy wrote: >> In tap6_handler(), iov_tail_size(&data) - sizeof(*ip6h) computes >> the expected payload length. IOV_PEEK_HEADER() guarantees at least >> sizeof(*ip6h) bytes, but add an explicit check to guard the unsigned >> subtraction. A too-small tail would indicate a malformed packet, so >> skip it. >> >> Signed-off-by: Jon Maloy >> >> --- >> v2: Use if-guard instead of assert(), to avoid runtime cost in >> per-packet path and to let the static checker follow the logic. I had the idea that the compiler may be smart enough to optimize it out, since it is logically redundant, as you note. /jon > > Why would the if be cheaper than an assert()? The IOV_PEEK_HEADER() > already checks the length, so this check is definitely redundant - it > exists only for the benefit of static checkers. > >> --- >> tap.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/tap.c b/tap.c >> index 6d93c7ce..6fd5f595 100644 >> --- a/tap.c >> +++ b/tap.c >> @@ -986,7 +986,10 @@ resume: >> if (!ip6h) >> continue; >> >> - check = iov_tail_size(&data) - sizeof(*ip6h); >> + check = iov_tail_size(&data); >> + if (check < sizeof(*ip6h)) >> + continue; >> + check -= sizeof(*ip6h); >> >> saddr = &ip6h->saddr; >> daddr = &ip6h->daddr; >> -- >> 2.52.0 >> >