Limit descriptors and enter capability mode in jot(1)
Details
Diff Detail
- Lint
Lint Skipped - Unit
Tests Skipped
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 | It makes me slightly nervous that we need CAP_WRITE | CAP_FSTAT | CAP_IOCTL for stdout, but only CAP_WRITE for stderr. | |
288 | 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 | Is there any risk that various locale-related bits might need ambient authority to initialise? |
usr.bin/jot/jot.c | ||
---|---|---|
397 | why would they? Its just a table lookup? |
usr.bin/jot/jot.c | ||
---|---|---|
288 | 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 | 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 | Yes. err and friends need the localization database(s) opened. |
usr.bin/jot/jot.c | ||
---|---|---|
318 | 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 | Sure. |