Page MenuHomeFreeBSD

capsicum_helpers: Squash errors from closed fds
ClosedPublic

Authored by cem on Nov 28 2016, 7:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, May 5, 2:25 PM
Unknown Object (File)
Thu, Apr 11, 1:18 PM
Unknown Object (File)
Thu, Apr 11, 2:19 AM
Unknown Object (File)
Mar 10 2024, 7:45 AM
Unknown Object (File)
Mar 10 2024, 7:44 AM
Unknown Object (File)
Feb 23 2024, 10:46 PM
Unknown Object (File)
Jan 16 2024, 2:46 PM
Unknown Object (File)
Jan 15 2024, 9:37 PM
Subscribers
None

Details

Summary

Squash EBADF from closed stdin, stdout, or stderr in caph_limit_stdio().
Any program used during special shell scripts may commonly be forked
from a parent process with closed standard stream. Do the common sense
thing for this common use.

Reported by: Iblis Lin <iblis AT hs.ntnu.edu.tw>

https://lists.freebsd.org/pipermail/freebsd-current/2016-November/063949.html

Test Plan

Tested with closed stdin:

$ truss basename $HOME <& -
...
cap_rights_limit(0x0,0x7fffffffe280)             ERR#9 'Bad file descriptor'
cap_rights_limit(0x1,0x7fffffffe280)             = 0 (0x0)
cap_ioctls_limit(0x1,0x7fffffffe270,0x2)         = 0 (0x0)
cap_fcntls_limit(0x1,0x8)                        = 0 (0x0)
cap_rights_limit(0x2,0x7fffffffe280)             = 0 (0x0)
cap_ioctls_limit(0x2,0x7fffffffe270,0x2)         = 0 (0x0)
cap_fcntls_limit(0x2,0x8)                        = 0 (0x0)
cap_enter()                                      = 0 (0x0)
fstat(1,{ mode=crw--w---- ,inode=124,size=0,blksize=4096 }) = 0 (0x0)
ioctl(1,TIOCGETA,0xffffe0c0)                     = 0 (0x0)
write(1,"cmeyer\n",7)                            = 7 (0x7)
...

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

cem retitled this revision from to capsicum_helpers: Squash errors from closed fds.
cem updated this object.
cem edited the test plan for this revision. (Show Details)
cem added reviewers: emaste, oshogbo, allanjude.

We have special flag to the caph_limit_stream() to ignore EBADF.

We have special flag to the caph_limit_stream() to ignore EBADF.

Yes, but caph_limit_stdin and friends do not take a flag argument. They could be replaced with several caph_limit_stream() calls instead, I guess. The approaches are functionally equivalent; if you think the style would be better that way, it's fine with me.

cem edited edge metadata.

Use caph_limit_stream() to ignore EBADF rather than handling directly in
caph_limit_stdio().

oshogbo edited edge metadata.
oshogbo added inline comments.
lib/libcapsicum/capsicum_helpers.h
98 ↗(On Diff #22582)

It's over 80.
Otherwise I agree with that change.

This revision is now accepted and ready to land.Dec 1 2016, 12:25 PM
This revision was automatically updated to reflect the committed changes.