Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jun 2018 00:02:03 +0000 (UTC)
From:      Chuck Tuffli <chuck@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335515 - in head/sys: amd64/linux amd64/linux32 compat/linux i386/linux
Message-ID:  <201806220002.w5M023tW042162@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: chuck
Date: Fri Jun 22 00:02:03 2018
New Revision: 335515
URL: https://svnweb.freebsd.org/changeset/base/335515

Log:
  Fix the Linux kernel version number calculation
  
  The Linux compatibility code was converting the version number (e.g.
  2.6.32) in two different ways and then comparing the results.
  
  The linux_map_osrel() function converted MAJOR.MINOR.PATCH similar to
  what FreeBSD does natively. I.e. where major=v0, minor=v1, and patch=v2
      v = v0 * 1000000 + v1 * 1000 + v2;
  
  The LINUX_KERNVER() macro, on the other hand, converted the value with
  bit shifts. I.e. where major=a, minor=b, and patch=c
      v = (((a) << 16) + ((b) << 8) + (c))
  
  The Linux kernel uses the later format via the KERNEL_VERSION() macro in
  include/generated/uapi/linux/version.h
  
  Fix is to use the LINUX_KERNVER() macro in linux_map_osrel() as well as
  in the .trans_osrel functions.
  
  PR: 229209
  Reviewed by: emaste, cem, imp (mentor)
  Approved by: imp (mentor)
  Differential Revision: https://reviews.freebsd.org/D15952

Modified:
  head/sys/amd64/linux/linux_sysvec.c
  head/sys/amd64/linux32/linux32_sysvec.c
  head/sys/compat/linux/linux_mib.c
  head/sys/i386/linux/linux_sysvec.c

Modified: head/sys/amd64/linux/linux_sysvec.c
==============================================================================
--- head/sys/amd64/linux/linux_sysvec.c	Thu Jun 21 23:29:17 2018	(r335514)
+++ head/sys/amd64/linux/linux_sysvec.c	Fri Jun 22 00:02:03 2018	(r335515)
@@ -799,10 +799,11 @@ linux_trans_osrel(const Elf_Note *note, int32_t *osrel
 		return (false);
 
 	/*
-	 * For Linux we encode osrel as follows (see linux_mib.c):
-	 * VVVMMMIII (version, major, minor), see linux_mib.c.
+	 * For Linux we encode osrel using the Linux convention of
+	 * 	(version << 16) | (major << 8) | (minor)
+	 * See macro in linux_mib.h
 	 */
-	*osrel = desc[1] * 1000000 + desc[2] * 1000 + desc[3];
+	*osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
 
 	return (true);
 }

Modified: head/sys/amd64/linux32/linux32_sysvec.c
==============================================================================
--- head/sys/amd64/linux32/linux32_sysvec.c	Thu Jun 21 23:29:17 2018	(r335514)
+++ head/sys/amd64/linux32/linux32_sysvec.c	Fri Jun 22 00:02:03 2018	(r335515)
@@ -993,10 +993,11 @@ linux32_trans_osrel(const Elf_Note *note, int32_t *osr
 		return (false);
 
 	/*
-	 * For Linux we encode osrel as follows (see linux_mib.c):
-	 * VVVMMMIII (version, major, minor), see linux_mib.c.
+	 * For Linux we encode osrel using the Linux convention of
+	 * 	(version << 16) | (major << 8) | (minor)
+	 * See macro in linux_mib.h
 	 */
-	*osrel = desc[1] * 1000000 + desc[2] * 1000 + desc[3];
+	*osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
 
 	return (true);
 }

Modified: head/sys/compat/linux/linux_mib.c
==============================================================================
--- head/sys/compat/linux/linux_mib.c	Thu Jun 21 23:29:17 2018	(r335514)
+++ head/sys/compat/linux/linux_mib.c	Fri Jun 22 00:02:03 2018	(r335515)
@@ -149,8 +149,8 @@ linux_map_osrel(char *osrelease, int *osrel)
 	if (osrelease == sep || sep != eosrelease)
 		return (EINVAL);
 
-	v = v0 * 1000000 + v1 * 1000 + v2;
-	if (v < 1000000)
+	v = LINUX_KERNVER(v0, v1, v2);
+	if (v < LINUX_KERNVER(1, 0, 0))
 		return (EINVAL);
 
 	if (osrel != NULL)

Modified: head/sys/i386/linux/linux_sysvec.c
==============================================================================
--- head/sys/i386/linux/linux_sysvec.c	Thu Jun 21 23:29:17 2018	(r335514)
+++ head/sys/i386/linux/linux_sysvec.c	Fri Jun 22 00:02:03 2018	(r335515)
@@ -970,10 +970,11 @@ linux_trans_osrel(const Elf_Note *note, int32_t *osrel
 		return (false);
 
 	/*
-	 * For Linux we encode osrel as follows (see linux_mib.c):
-	 * VVVMMMIII (version, major, minor), see linux_mib.c.
+	 * For Linux we encode osrel using the Linux convention of
+	 * 	(version << 16) | (major << 8) | (minor)
+	 * See macro in linux_mib.h
 	 */
-	*osrel = desc[1] * 1000000 + desc[2] * 1000 + desc[3];
+	*osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
 
 	return (true);
 }



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