Bug 250059 - ports-mgmt/pkg: Installing sample files broken on aarch64
Summary: ports-mgmt/pkg: Installing sample files broken on aarch64
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Many People
Assignee: freebsd-pkg (Nobody)
Depends on:
Reported: 2020-10-02 21:16 UTC by Christian Ullrich
Modified: 2020-10-12 06:52 UTC (History)
5 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Christian Ullrich 2020-10-02 21:16:13 UTC
Upgrading pkg from 1.15.6 to 1.15.8 on an aarch64 system (a Raspi 3) running 12.1-RELEASE-p6 results in a /usr/local/etc/pkg.conf file containing nothing but NULs:

# ls -l pkg.conf*
-rw-r--r--  1 root  wheel  2366 Oct  2 21:08 pkg.conf
-rw-r--r--  1 root  wheel  2366 Oct  2 20:40 pkg.conf.sample

# hd < pkg.conf
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

I have no clue about what exactly is going on, but the difference between my 1.15.6 and 1.15.8 packages (built locally with poudriere) is that in 1.15.6, the post-install script is sh, while in 1.15.8, it's lua. Also, there is this bit in the ktrace output from installing the 1.15.8 package:

 64549 pkg      CALL  fstatat(0xb,0x4182a809,0xffffffffc348,0x200<AT_SYMLINK_NOF
 64549 pkg      NAMI  "usr/local/etc/pkg.conf"
 64549 pkg      RET   fstatat -1 errno 2 No such file or directory
 64549 pkg      CALL  fstatat(0xb,0x4186efd9,0xffffffffc348,0x200<AT_SYMLINK_NOF
 64549 pkg      NAMI  "usr/local/etc/pkg.conf.sample"
 64549 pkg      STRU  struct stat {dev=88, ino=27515, mode=0100644, nlink=1, uid=0, gid=0, rdev=97055, atime=0, mtime=1601664004, ctime=1601664713.277981000, birthtime=1601664004, size=2366, blksize=32768, blocks=8, flags=0x0 }
 64549 pkg      RET   fstatat 0
 64549 pkg      CALL  openat(0xb,0x4186efd9,0<O_RDONLY>)
 64549 pkg      NAMI  "usr/local/etc/pkg.conf.sample"
 64549 pkg      RET   openat 12/0xc
 64549 pkg      CALL  openat(0xb,0x4182a809,0xe01<O_WRONLY|O_CREAT|O_TRUNC|O_EXCL>,0666<S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH>)
 64549 pkg      NAMI  "usr/local/etc/pkg.conf"
 64549 pkg      RET   openat 15/0xf
 64549 pkg      CALL  ftruncate(0xf,0x93e)
 64549 pkg      RET   ftruncate 0
 64549 pkg      CALL  mmap(0,0x93e,0x1<PROT_READ>,0x1<MAP_SHARED>,0xc,0)
 64549 pkg      RET   mmap 1100906496/0x419e8000
 64549 pkg      CALL  mmap(0,0x93e,0x2<PROT_WRITE>,0x1<MAP_SHARED>,0xf,0)
 64549 pkg      RET   mmap 1100910592/0x419e9000
 64547 pkg      RET   poll 1
 64547 pkg      CALL  fstat(0xc,0xffffffffd078)
 64547 pkg      STRU  struct stat {dev=18446744073709551615, ino=135317, mode=0140000, nlink=0, uid=0, gid=0, rdev=0, atime=0, mtime=0, ctime=0, birthtime=0, size=0, blksize=8192, blocks=0, flags=0x0 }
 64547 pkg      RET   fstat 0
 64547 pkg      CALL  read(0xc,0x41855000,0x2000)
 64547 pkg      GIO   fd 12 read 0 bytes
 64547 pkg      RET   read 0
 64547 pkg      CALL  close(0xc)
 64547 pkg      RET   close 0
 64547 pkg      CALL  wait4(0xfc25,0xffffffffd504,0,0)
 64549 pkg      PSIG  SIGSEGV SIG_DFL code=SEGV_ACCERR
 64549 pkg      CAP   restricted VFS lookup
 64547 pkg      RET   wait4 64549/0xfc25

I don't know which exact operation it was that caused capsicum to kill the process (64549) forked to copy pkg.conf.sample to pkg.conf, but this appears to be what happened. It finds that pkg.conf does not exist, determines the size of pkg.conf.sample, creates pkg.conf and ftruncate()s it to the same size full of NULs (where have I seen that before?), mmap()s the two---and suffers spontaneous existence failure. In contrast, the sh version of the script runs /bin/cp, which works perfectly fine.

The same behavior does not occur with 12.1-RELEASE-p10 on amd64. There do not appear to be changes between 12.1-RELEASE-p6 and current -p10 that might have fixed this.
Comment 1 Herbert J. Skuhra 2020-10-03 04:58:22 UTC
I have the same issue on arm64, but not on armv7 or amd64 running 12.2-STABLE (r366197). 

(Please assign to pkg@).
Comment 2 Herbert J. Skuhra 2020-10-04 14:46:50 UTC
Still happening with pkg 1.15.9.
Comment 3 chris 2020-10-09 11:58:58 UTC
Ditto, same problem here on aarc64 running on 12.1-p10, and pkg 1.15.9
Comment 4 commit-hook freebsd_committer 2020-10-11 13:00:53 UTC
A commit references this bug:

Author: manu
Date: Sun Oct 11 13:00:44 UTC 2020
New revision: 552059
URL: https://svnweb.freebsd.org/changeset/ports/552059

  ports-mgmt/pkg: Update to 1.15.10

  Add a workaround for https://bugs.freebsd.org/250271

  PR:		250059
  Approved by:	bapt (implicit)
  MFH:		2020Q4

Comment 5 commit-hook freebsd_committer 2020-10-12 06:52:25 UTC
A commit references this bug:

Author: bapt
Date: Mon Oct 12 06:51:55 UTC 2020
New revision: 552099
URL: https://svnweb.freebsd.org/changeset/ports/552099

  MFH: r551167 r551211 r551416 r552059

  ports-mgmt/pkg: Update to 1.15.7

  Changes from 1.15.6 to 1.15.7:
   - Fix %# expand in script

  Approved by:	bapt (implicit)

  Update to 1.15.8

  Fixes a typo which results in pkg ignoring some lua script in some particular
  circumpstancies: shell script also available in certain types

  ports-mgmt/pkg: Update to 1.15.9

  Changes from 1.15.8 to 1.15.9:
  - lua_pkg_copy when copying a symlink

  PR:		248314
  Approved by:	bapt (implicit)

  ports-mgmt/pkg: Update to 1.15.10

  Add a workaround for https://bugs.freebsd.org/250271

  PR:		250059
  Approved by:	bapt (implicit)

_U  branches/2020Q4/