Project

General

Profile

Actions

Bug #3518

closed

Incorrect hostid calculation

Added by Garrett D'Amore about 10 years ago. Updated over 9 years ago.

Status:
Resolved
Priority:
Urgent
Category:
kernel
Start date:
2013-02-01
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

During some additional testing on some other hardware, we found a sign extension bug that I introduced when I committed the fix for 3359. This is a regression, and it expresses itself as an incorrectly formatted value of hw_serial, resulting in HW_INVALID_HOSTID.

Actions #1

Updated by Garrett D'Amore about 10 years ago

Here's the fix for my bug. Rather than switching to unsigned values throughout, I think masking off the sign bit is best, as other consumers of hostids may be ill-prepared for negative values there.

--- a/usr/src/uts/i86pc/os/startup.c
+++ b/usr/src/uts/i86pc/os/startup.c
@@ -2781,7 +2781,7 @@ uuid_to_hostid(const uint8_t *uuid)
         * generate 32-bit vaue by xor'ing the various sequences together,
         * which ensures that the enire UUID contributes to the hostid.
         */
-       int32_t id = 0;
+       uint32_t        id = 0;

        /* first check against the blacklist */
        for (int i = 0; i < (sizeof (smbios_uuid_blacklist) / 16); i++) {
@@ -2795,7 +2795,8 @@ uuid_to_hostid(const uint8_t *uuid)
        for (int i = 0; i < 16; i++)
                id ^= ((uuid[i]) << (8 * (i % sizeof (id))));

-       return (id);
+       /* Make sure return value is positive */
+       return (id & 0x7fffffff);
 }
Actions #2

Updated by Garrett D'Amore over 9 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100
  • Tags deleted (needs-triage)

commit 2df37efa12a69b067c7197296dd802eb4b8a9e85
Author: Garrett D'Amore <>
Date: Fri Feb 1 12:04:34 2013 -0800

3518 Incorrect hostid calculation
Reviewed by: Gordon Ross &lt;&gt;
Reviewed by: Richard Elling &lt;&gt;
Reviewed by: Andy Giles &lt;&gt;
Reviewed by: Dan McDonald &lt;&gt;
Approved by: Dan McDonald &lt;&gt;
Actions

Also available in: Atom PDF