From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 54EAE5A0274 for ; Wed, 28 Jun 2023 07:11:24 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4QrV6Z3z3Mz4wvw; Wed, 28 Jun 2023 15:11:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1687929078; bh=Or2SsfcG+KInnCz8snNzqwxA3WBtBEtebIofzz40Gys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrkrQTiVjKaEibKsYloBm/2m7ym4mFjwsLstXzxKCR7w/wueGrRjz3AuURd+HBFmW MwgTmAIY/cqLc9zZC97eOJHLeZvLu084dcO4TpMIYejrCkWnWolkqcDTFnYsR8K6Ir ev+Zkx/Gqa0dxjNaDmkXbw5Yor7pyt2AIw3gkDmw= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] conf: Correct length checking of interface names in conf_ports() Date: Wed, 28 Jun 2023 15:11:15 +1000 Message-ID: <20230628051115.3692777-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628051115.3692777-1-david@gibson.dropbear.id.au> References: <20230628051115.3692777-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: YLN6364GDTB5C72EPMMAGYZR5ILXMXQL X-Message-ID-Hash: YLN6364GDTB5C72EPMMAGYZR5ILXMXQL X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: When interface names are specified in forwarding specs, we need to check the length of the given interface name against the limit of IFNAMSIZ - 1 (15) characters. However, we managed to have 3 separate off-by-one errors here meaning we only accepted interface names up to 12 characters. 1. At the point of the check 'ifname' was still on the '%' character, not the first character of the name, meaning we overestimated the length by one 2. At the point of the check 'spec' had been advanced one character past the '/' which terminates the interface name, meaning we overestimated the length by another one 3. We checked if the (miscalculated) length was >= IFNAMSIZ - 1, that is >= 15, whereas lengths equal to 15 should be accepted. Correct all 3 errors. Bugzilla: https://bugs.passt.top/show_bug.cgi?id=61 Signed-off-by: David Gibson --- conf.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/conf.c b/conf.c index 19064368..78eaf2d1 100644 --- a/conf.c +++ b/conf.c @@ -256,11 +256,16 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg, goto bad; if ((ifname = strchr(buf, '%'))) { - if (spec - ifname >= IFNAMSIZ - 1) - goto bad; - *ifname = 0; ifname++; + + /* spec is already advanced one past the '/', + * so the length of the given ifname is: + * (spec - ifname - 1) + */ + if (spec - ifname - 1 >= IFNAMSIZ) + goto bad; + } if (ifname == buf + 1) /* Interface without address */ -- 2.41.0