Bug 230120 - capsicum: cap_ftruncate_rights doesn't work in 32-bit emulation
Summary: capsicum: cap_ftruncate_rights doesn't work in 32-bit emulation
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-28 18:24 UTC by Alan Somers
Modified: 2018-09-06 13:36 UTC (History)
4 users (show)

See Also:


Attachments
Correct the line in compat32 capabilities.conf for ftruncate(2). (381 bytes, patch)
2018-08-18 10:31 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer freebsd_triage 2018-07-28 18:24:20 UTC
I don't know why, but cap_ftruncate_rights doesn't appear to work in 32-bit emulation.  The bug can be reproduced by running i386's dd binary on a 64-bit kernel:

$ /bin/dd if=/dev/zero of=1.file bs=1 count=1 oseek=1 conv=sparse
1+0 records in
1+0 records out
1 bytes transferred in 0.000235 secs (4263 bytes/sec)

$ /root32/bin/dd if=/dev/zero of=1.file bs=1 count=1 oseek=1 conv=sparse
dd: truncating 1.file: Not permitted in capability mode
1+0 records in
1+0 records out
1 bytes transferred in 0.000111 secs (9035 bytes/sec)

There doesn't appear to be anything obviously wrong with the code in either dd or kern_ftruncate, so I think it's a deeper capsicum bug.
Comment 1 Conrad Meyer freebsd_committer freebsd_triage 2018-07-28 20:26:29 UTC
What's the return value of cap_rights_limit?  Does truss support 32 bit binaries?
Comment 2 Conrad Meyer freebsd_committer freebsd_triage 2018-07-28 20:28:37 UTC
Hm.  There are compat32 versions of cap_ioctls_limit and cap_ioctls_get, but not cap_rights_limit, cap_rights_get, or cap_fcntls*.
Comment 3 Alan Somers freebsd_committer freebsd_triage 2018-07-28 20:40:14 UTC
cap_rights_limit must've exited 0, because otherwise dd would've aborted.  I don't know about truss, but I tried both ktrace and dtrace.  Dtracing syscalls::cap_rights_limit:enter showed the same value for the capabilities in both 64 and 32 bit mode.

Why do you say that cap_rights_limit has no 32-bit version?  I see it in line 1033 of sys/compat/freebsd32/syscalls.master.
Comment 4 Conrad Meyer freebsd_committer freebsd_triage 2018-07-28 21:12:41 UTC
(In reply to Alan Somers from comment #3)
> Why do you say that cap_rights_limit has no 32-bit version?

I mean no compat32-specific definition, e.g., see the difference between that line and the cap_ioctl* definitions in that file.
Comment 5 Antoine Brodin freebsd_committer freebsd_triage 2018-08-18 09:42:19 UTC
Maybe freebsd32_ftruncate needs to be added to compat/freebsd32/capabilities.conf
 ?
Comment 6 Antoine Brodin freebsd_committer freebsd_triage 2018-08-18 09:59:29 UTC
By the way, it seems the freebsd6_* and freebsd11_* in compat/freebsd32/capabilities.conf are unused by makesyscalls.sh
Comment 7 Konstantin Belousov freebsd_committer freebsd_triage 2018-08-18 10:31:08 UTC
(In reply to Antoine Brodin from comment #5)
Yes, you are almost right.  The entry should be corrected, it is errnonously called 'ftruncate' in compat32 capabilities.conf.
Comment 8 Konstantin Belousov freebsd_committer freebsd_triage 2018-08-18 10:31:42 UTC
Created attachment 196317 [details]
Correct the line in compat32 capabilities.conf for ftruncate(2).
Comment 9 Antoine Brodin freebsd_committer freebsd_triage 2018-08-18 22:46:36 UTC
The ftruncate in compat32 capabilities.conf enables capability for 130 = old ftruncate
Comment 10 commit-hook freebsd_committer freebsd_triage 2018-08-28 18:50:08 UTC
A commit references this bug:

Author: kib
Date: Tue Aug 28 18:49:40 UTC 2018
New revision: 338357
URL: https://svnweb.freebsd.org/changeset/base/338357

Log:
  Fix compat32 ftruncate cap mode after ino64.

  Reported by:    asomers
  PR:     230120
  Sponsored by:   The FreeBSD Foundation
  Approved by:	re (gjb)

Changes:
  head/sys/compat/freebsd32/capabilities.conf
Comment 11 Ed Maste freebsd_committer freebsd_triage 2018-09-05 13:29:09 UTC
MFC?
Comment 12 commit-hook freebsd_committer freebsd_triage 2018-09-05 21:15:46 UTC
A commit references this bug:

Author: kib
Date: Wed Sep  5 21:15:23 UTC 2018
New revision: 338480
URL: https://svnweb.freebsd.org/changeset/base/338480

Log:
  MFC r338357:
  Fix compat32 ftruncate cap mode.

  PR:	230120

Changes:
_U  stable/11/
  stable/11/sys/compat/freebsd32/capabilities.conf