Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Apr 2004 16:15:10 +0100 (BST)
From:      Gavin Atkinson <gavin@ury.york.ac.uk>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        gavin@ury.york.ac.uk
Subject:   kern/65627: Patch to store P3 serial number in sysctl
Message-ID:  <200404161515.i3GFFAfM011325@buffy.york.ac.uk>
Resent-Message-ID: <200404161520.i3GFKLK7094374@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         65627
>Category:       kern
>Synopsis:       Patch to store P3 serial number in sysctl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Apr 16 08:20:21 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Gavin Atkinson
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:
System: FreeBSD buffy.york.ac.uk 5.2-CURRENT FreeBSD 5.2-CURRENT #7: Tue Apr 13 19:45:13 BST 2004 root@buffy.york.ac.uk:/usr/obj/usr/src/sys/GENERIC i386

>Description:
	Pentium III processors have a serial number stored within them.
If not disabled, this can be used to license software against, etc.
This patch provides userland access to the serial number. It also includes
a printf to show the serial number when bootverbose is set, but it may be
preferable to not include that.

>How-To-Repeat:
	n/a
>Fix:

	(Patch also at http://www.devrandom.co.uk/freebsd/psn.diff)

--- sys/i386/i386/identcpu.c.old	Fri Apr  9 18:00:03 2004
+++ sys/i386/i386/identcpu.c	Tue Apr 13 22:17:50 2004
@@ -94,6 +94,13 @@
 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, 
     cpu_model, 0, "Machine model");
 
+SYSCTL_NODE(_hw, OID_AUTO, cpu0, CTLFLAG_RD,
+    0, "CPU 0 Information");
+
+static char cpu_serial[32];
+SYSCTL_STRING(_hw_cpu0, OID_AUTO, serial, CTLFLAG_RD, 
+    cpu_serial, 0, "CPU serial number");
+
 static int hw_clockrate;
 SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD, 
     &hw_clockrate, 0, "CPU instruction clock rate");
@@ -695,6 +702,21 @@
 			    (cpu_procinfo & CPUID_HTT_CORES) >> 16 > 1)
 				printf("\n  Hyperthreading: %d logical CPUs",
 				    (cpu_procinfo & CPUID_HTT_CORES) >> 16);
+			/*
+			 * Obtain the serial number if the CPU supports it
+			 */
+			if (cpu_feature & CPUID_PSN) {
+				do_cpuid(3, regs);
+				snprintf(cpu_serial,
+				    sizeof(cpu_serial),
+				    "%04x-%04x-%04x-%04x-%04x-%04x",
+				    (cpu_id >> 16), (cpu_id & 0xffff),
+				    (regs[3] >> 16), (regs[3] & 0xffff),
+				    (regs[2] >> 16), (regs[2] & 0xffff));
+				if (bootverbose)
+					printf("\n  Processor Serial Number: %s",
+					    cpu_serial);
+			}
 		}
 		if (strcmp(cpu_vendor, "AuthenticAMD") == 0 &&
 		    cpu_exthigh >= 0x80000001)


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200404161515.i3GFFAfM011325>