Page MenuHomeFreeBSD

sort(1): Capsicumize
Needs ReviewPublic

Authored by yzhong_freebsdfoundation.org on Oct 23 2020, 3:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Mar 31, 2:31 PM
Unknown Object (File)
Mar 13 2024, 5:29 PM
Unknown Object (File)
Mar 11 2024, 4:47 AM
Unknown Object (File)
Feb 11 2024, 8:45 PM
Unknown Object (File)
Dec 20 2023, 5:51 AM
Unknown Object (File)
Dec 12 2023, 9:05 PM
Unknown Object (File)
Nov 19 2023, 3:15 AM
Unknown Object (File)
Nov 19 2023, 3:14 AM
Subscribers
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This program likes passing files around by name. Before entering capability mode, we:
1, Open the temporary files directory
2, Make a cap_fileargs service for all the input files
3, Make another cap_fileargs service for the output files. Sort can write to the specified output file, as well as a temporary outfile in the same directory, in case the output file is also an input file
4, Open the outfile directory, with rename and unlink rights, so the program can rename the temporary outfile to be the real one
5, If --compress-program is specified, open a cap_exec service so that the program can call the provided compression program

Most of the changes are centered around openfile() in file.c. The rest are minor, like changing unlink() calls to unlinkat()s and such.

Test Plan

Unfortunately sort(1)'s test suite is currently for NetBSD's version of the program and isn't compatible with this one. When testing manually, important options to look at include -S (limits memory buffer size, so the program is forced to use temp files) and --compress-program (only used when creating temp files - compresses the temp data using the provided program).

Depends on D24327

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

usr.bin/sort/sort.c
1223–1224

If outputting to stdout, outfile will be '-', in which case it would make no sense to add it to fileargs.