From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4532445BC5; Thu, 24 Oct 2024 17:20:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 547B7434CC; Thu, 24 Oct 2024 17:19:59 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id F34F5434DA for ; Thu, 24 Oct 2024 17:19:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729783195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/o8vz1Cn1hJLc89hgwKATch+jd1wC/EV1wwWe7CKVNo=; b=U2aWS7y0DYrNbY7vGaRY32fD6JgTWAWCxKPiqT7QBw9L8LogZRD0ifSBDvu7tFHh/02Th3 Knl4ZojZK/b0qPvVQHOkT/RzrchIQ14by8NL47dK1kFXLmwFA2kROgY4KhHYk4Xy4CtSSu IqmijKrJtpITtMqzP0v/0ZGjN/4mPdQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-iy4vlDX6OGOxA1tDA1eKEQ-1; Thu, 24 Oct 2024 11:19:54 -0400 X-MC-Unique: iy4vlDX6OGOxA1tDA1eKEQ-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CC8B18D65F2 for ; Thu, 24 Oct 2024 15:19:34 +0000 (UTC) Received: from ringo.home (unknown [10.39.208.32]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A95CC1955BC1; Thu, 24 Oct 2024 15:19:27 +0000 (UTC) From: Robin Jarry To: dev@dpdk.org Subject: [PATCH dpdk 2/2] net/ipv6: fix out-of-bounds read Date: Thu, 24 Oct 2024 17:19:22 +0200 Message-ID: <20241024151919.400878-6-rjarry@redhat.com> In-Reply-To: <20241024151919.400878-4-rjarry@redhat.com> References: <20241024151919.400878-4-rjarry@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Fix the following out-of-bounds read in rte_ipv6_addr_mask() reported by Coverity: 83 static inline void 84 rte_ipv6_addr_mask(struct rte_ipv6_addr *ip, uint8_t depth) 85 { 1. Condition depth < 128 /* 16 * 8 */, taking true branch. 2. cond_at_most: Checking depth < 128 implies that depth may be up to 127 on the true branch. 86 if (depth < RTE_IPV6_MAX_DEPTH) { 3. assignment: Assigning: d = depth / 8. The value of d may now be up to 15. 87 uint8_t d = depth / 8; 88 uint8_t mask = ~(UINT8_MAX >> (depth % 8)); 89 ip->a[d] &= mask; 4. incr: Incrementing d. The value of d may now be up to 16. 90 d++; CID 446754: (#1 of 1): Out-of-bounds read (OVERRUN) 5. overrun-local: Overrunning array of 16 bytes at byte offset 16 by dereferencing pointer &ip->a[d]. 91 memset(&ip->a[d], 0, sizeof(*ip) - d); 92 } 93 } Use a simple loop instead of memset. Coverity issue: 446754 Fixes: ca786def84ca ("net: add IPv6 address structure and utils") Signed-off-by: Robin Jarry --- lib/net/rte_ip6.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/net/rte_ip6.h b/lib/net/rte_ip6.h index c015c977573d..3843fb7c2fd6 100644 --- a/lib/net/rte_ip6.h +++ b/lib/net/rte_ip6.h @@ -88,7 +88,8 @@ rte_ipv6_addr_mask(struct rte_ipv6_addr *ip, uint8_t depth) uint8_t mask = ~(UINT8_MAX >> (depth % CHAR_BIT)); ip->a[d] &= mask; d++; - memset(&ip->a[d], 0, sizeof(*ip) - d); + while (d < sizeof(*ip)) + ip->a[d++] = 0; } } -- 2.47.0