freebsd-skq/sys/compat/freebsd32
bde 8bff5fd956 Fix the encoding of major and minor numbers in 64-bit dev_t by restoring
the old encodings for the lower 16 and 32 bits and only using the
higher 32 bits for unusually large major and minor numbers.  This
change breaks compatibility with the previous encoding (which was only
used in -current).

Fix truncation to (essentially) 16-bit dev_t in newnfs v3.

Any encoding of device numbers gives an ABI, so it can't be changed
without translations for compatibility.  Extra bits give the much
larger complication that the translations need to compress into fewer
bits.  Fortunately, more than 32 bits are rarely needed, so
compression is rarely needed except for 16-bit linux dev_t where it
was always needed but never done.

The previous encoding moved the major number into the top 32 bits.
Almost no translation code handled this, so the major number was blindly
truncated away in most 32-bit encodings.  E.g., for ffs, mknod(8) with
major = 1 and minor = 2 gave dev_t = 0x10000002; ffs cannot represent
this and blindly truncated it to 2.  But if this mknod was run on any
released version of FreeBSD, it gives dev_t = 0x102.  ffs can represent
this, but in the previous encoding it was not decoded, giving major = 0,
minor = 0x102.

The presence of bugs was most obvious for exporting dev_t's from an
old system to -current, since bugs in newnfs augment them.  I fixed
oldnfs to support 32-bit dev_t in 1996 (r16634), but this regressed
to 16-bit dev_t in newnfs, first to the old 16-bit encoding and then
further in -current.  E.g., old ad0 with major = 234, minor = 0x10002
had the correct (major, minor) number on the wire, but newnfs truncated
this to (234, 2) and then the previous encoding shifted the major
number into oblivion as seen by ffs or old applications.

I first tried to fix this by translating on every ABI/API boundary, but
there are too many boundaries and too many sloppy translations by blind
truncation.  So use the old encoding for the low 32 bits so that sloppy
translations work no worse than before provided the high 32 bits are
not set.  Add some error checking for when bits are lost.  Keep not
doing any error checking for translations for almost everything in
compat/linux.

compat/freebsd32/freebsd32_misc.c:
Optionally check for losing bits after possibly-truncating assignments as
before.

compat/linux/linux_stats.c:
Depend on the representation being compatible with Linux's (or just with
itself for local use) and spell some of the translations as assignments in
a macro that hides the details.

fs/nfsclient/nfs_clcomsubs.c:
Essentially the same fix as in 1996, except there is now no possible
truncation in makedev() itself.  Also fix nearby style bugs.

kern/vfs_syscalls.c:
As for freebsd32.  Also update the sysctl description to include file
numbers, and change it to describe device ids as device numbers.

sys/types.h:
Use inline functions (wrapped by macros) since the expressions are now
a bit too complicated for plain macros.  Describe the encoding and
some of the reasons for it.  16-bit compatibility didn't leave many
reasonable choices for the 32-bit encoding, and 32-bit compatibility
doesn't leave many reasonable choices for the 64-bit encoding.  My
choice is to put the 8 new minor bits in the low 8 bits of the top 32
bits.  This minimizes discontiguities.

Reviewed by:	kib (except for rewrite of the comment in linux_stats.c)
2018-06-13 12:22:00 +00:00
..
capabilities.conf allow posix_fallocate in 32-bit compat capability mode 2017-10-12 18:30:54 +00:00
freebsd32_capability.c sys/compat: further adoption of SPDX licensing ID tags. 2017-11-27 15:13:23 +00:00
freebsd32_ioctl.c Move most of the contents of opt_compat.h to opt_global.h. 2018-04-06 17:35:35 +00:00
freebsd32_ioctl.h Move 32-bit compat for md(4) ioctls into the md code. 2018-03-27 16:07:54 +00:00
freebsd32_ipc.h Rename kernel-only members of semid_ds and msgid_ds. 2018-03-02 22:10:48 +00:00
freebsd32_misc.c Fix the encoding of major and minor numbers in 64-bit dev_t by restoring 2018-06-13 12:22:00 +00:00
freebsd32_misc.h sys/compat: further adoption of SPDX licensing ID tags. 2017-11-27 15:13:23 +00:00
freebsd32_proto.h Regen after r329322. 2018-02-15 18:32:11 +00:00
freebsd32_signal.h sys/compat: further adoption of SPDX licensing ID tags. 2017-11-27 15:13:23 +00:00
freebsd32_syscall.h Regen after r334223: make vadvise compat freebsd11. 2018-05-25 20:41:26 +00:00
freebsd32_syscalls.c Regen after r334223: make vadvise compat freebsd11. 2018-05-25 20:41:26 +00:00
freebsd32_sysent.c Regen after r334223: make vadvise compat freebsd11. 2018-05-25 20:41:26 +00:00
freebsd32_systrace_args.c Regen after r334626. 2018-06-04 19:36:47 +00:00
freebsd32_util.h Reduce duplication in dynamic syscall registration code. 2018-02-20 18:08:57 +00:00
freebsd32.h sys/compat: further adoption of SPDX licensing ID tags. 2017-11-27 15:13:23 +00:00
Makefile Don't use an .OBJDIR for 'make sysent'. 2018-01-29 19:14:15 +00:00
syscalls.conf
syscalls.master Reimplement brk() and sbrk() to avoid the use of _end. 2018-06-04 19:35:15 +00:00