Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oQuJB-0006yh-GF for mharc-grub-devel@gnu.org; Wed, 24 Aug 2022 13:36:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQuJ6-0006kP-7r for grub-devel@gnu.org; Wed, 24 Aug 2022 13:36:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:44897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQuJ2-0004Qz-5N for grub-devel@gnu.org; Wed, 24 Aug 2022 13:36:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661362603; 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=WNXpYsAXgG1jS5P3tExkXsTeikg3iHYXQ7FYQyIs72o=; b=dfQByyAWyRrfIk7Hn4Y+OF68jRpXqYQXS5wVPjyexJtnxit+cs+GKLawHfHkXMOTDiJtHG 4f9ZknrLyHR0nK6x4XKlWLO7I0x14FpXVnNDp4wu7WZyAjXihV3wzh/Tq/Tg3Dhcl9WL7O 8/tnMwXZgQfZQYkmtI5uIcMJLtUmR44= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-rngOudDQOTWBYMTGCIcuhA-1; Wed, 24 Aug 2022 13:36:41 -0400 X-MC-Unique: rngOudDQOTWBYMTGCIcuhA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50EFA85A58E; Wed, 24 Aug 2022 17:36:41 +0000 (UTC) Received: from eesha.redhat.com (unknown [10.22.34.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23031492CA6; Wed, 24 Aug 2022 17:36:41 +0000 (UTC) From: Robbie Harwood To: grub-devel@gnu.org Cc: phcoder@gmail.com, Masahiro Matsuya , Robbie Harwood Subject: [PATCH v2] net/drivers/ieee1275/ofnet: fix incorrect netmask Date: Wed, 24 Aug 2022 13:36:37 -0400 Message-Id: <20220824173637.31425-2-rharwood@redhat.com> In-Reply-To: <20220824173637.31425-1-rharwood@redhat.com> References: <20220824173637.31425-1-rharwood@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.129.124; envelope-from=rharwood@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2022 17:36:48 -0000 From: Masahiro Matsuya The netmask configured in firmware is not respected on ppc64 (big endian). When 255.255.252.0 is set as netmask in firmware, the following is the value of bootpath string in grub_ieee1275_parse_bootpath(): /vdevice/l-lan@30000002:speed=auto,duplex=auto,192.168.88.10,,192.168.89.113,192.168.88.1,5,5,255.255.252.0,512 The netmask in this bootpath is no problem, since it's a value specified in firmware. But the value of 'subnet_mask.ipv4' was set with 0xfffffc00, and __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4)) returned 16 (not 22). As a result, 16 was used for netmask wrongly: 1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) 1111 1111 0000 0011 0000 0000 0000 0000 # ~grub_le_to_cpu32 (subnet_mask.ipv4) and the count of zero with __builtin_ctz can be 16. This patch changes it as below: 1111 1111 1111 1111 1111 1100 0000 0000 # subnet_mask.ipv4 (=0xfffffc00) 0000 0000 1111 1100 1111 1111 1111 1111 # grub_le_to_cpu32 (subnet_mask.ipv4) 1111 1111 1111 1111 1111 1100 0000 0000 # grub_be_to_cpu32 (subnet_mask.ipv4) 0000 0000 0000 0000 0000 0011 1111 1111 # ~grub_be_to_cpu32 (subnet_mask.ipv4) The count of zero with __builtin_clz can be 22. (clz counts the number of one bits preceding the most significant zero bit) Signed-off-by: Masahiro Matsuya Signed-off-by: Robbie Harwood --- grub-core/net/drivers/ieee1275/ofnet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grub-core/net/drivers/ieee1275/ofnet.c b/grub-core/net/drivers/ieee1275/ofnet.c index 8c8398948b..78f03df8e2 100644 --- a/grub-core/net/drivers/ieee1275/ofnet.c +++ b/grub-core/net/drivers/ieee1275/ofnet.c @@ -220,8 +220,7 @@ grub_ieee1275_parse_bootpath (const char *devpath, char *bootpath, flags); inter->vlantag = vlantag; grub_net_add_ipv4_local (inter, - __builtin_ctz (~grub_le_to_cpu32 (subnet_mask.ipv4))); - + __builtin_clz (~grub_be_to_cpu32 (subnet_mask.ipv4))); } if (gateway_addr.ipv4 != 0) -- 2.35.1