Limit descriptors and enter capability mode in jot(1)
Details
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
For some reason, phabricator is not willing to show me full context on this file -- whereas it did for your elfdump patch. I wonder why?
Overall I like these changes a lot, but had a few questions about implied need for ambient authority relating to random number generation and localisation.
usr.bin/jot/jot.c | ||
---|---|---|
120 ↗ | (On Diff #3011) | It makes me slightly nervous that we need CAP_WRITE | CAP_FSTAT | CAP_IOCTL for stdout, but only CAP_WRITE for stderr. |
288 ↗ | (On Diff #3011) | I guess srandom() doesn't access /dev/random (unlike srandomdev()), but it would be good to convince ourselves that it is able to properly initialise in capability mode. (I seem to recall we do allow access to the arc4random sysctl from capability mode for this reason .. but maybe srandom() doesn't use that?) |
397 ↗ | (On Diff #3011) | Is there any risk that various locale-related bits might need ambient authority to initialise? |
usr.bin/jot/jot.c | ||
---|---|---|
397 ↗ | (On Diff #3011) | why would they? Its just a table lookup? |
usr.bin/jot/jot.c | ||
---|---|---|
288 ↗ | (On Diff #3011) | srandom() calls good_rand() (pure computation - lib/libc/stdlib/random.c:219), and random() (which only calls good_rand()). So, it's entirely numerical computation based on the provided seed. On a side note, srandomdev() also seems to use sysctl() rather than opening /dev/random as a file (hooray!). |
kib was vehemently opposed, so I left it for now. Maybe something to discuss at BSDCan.
- Restrict stderr identically to stdout.
- Preopen NLS database(s) for err() usage after cap_enter().
usr.bin/jot/jot.c | ||
---|---|---|
318 ↗ | (On Diff #3011) | Note arc4random -> arc4_stir attempts to fall back to /dev/random if the kern.arandom sysctl fails. (I don't know why it would fail; maybe it's a fallback that can be removed.) I don't think this is a problem (the sysctl is used first). |
397 ↗ | (On Diff #3011) | Yes. err and friends need the localization database(s) opened. |
usr.bin/jot/jot.c | ||
---|---|---|
318 ↗ | (On Diff #3011) | We should ensure that srandomdev() failing leads to an application fail stop. Right now, srandomdev() does not have a return value -- which means we must ensure that libc triggers application exit if both the sysctl and /dev/random fail. This is especially important in Capsicum, where the latter is guaranteed to fail! |
usr.bin/jot/jot.c | ||
---|---|---|
114 ↗ | (On Diff #20507) | Code often makes assumptions about fd 0/1/2. We may want to limit stdin to no rights rather than closing it (cap_rights_limit(STDIN_FILENO, cap_rights_init(&rights));) as a pattern to follow, even if it doesn't matter for jot. See for example rS306056 in elfdump. |
usr.bin/jot/jot.c | ||
---|---|---|
114 ↗ | (On Diff #20507) | Sure. |