Page MenuHomeFreeBSD

Eliminate unnecessary loop in _cap_check()
ClosedPublic

Authored by freqlabs on Jul 30 2016, 7:49 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 9, 1:59 PM
Unknown Object (File)
Nov 19 2024, 4:53 AM
Unknown Object (File)
Nov 6 2024, 9:13 AM
Unknown Object (File)
Nov 3 2024, 7:14 AM
Unknown Object (File)
Nov 3 2024, 7:14 AM
Unknown Object (File)
Nov 3 2024, 7:14 AM
Unknown Object (File)
Nov 3 2024, 7:14 AM
Unknown Object (File)
Nov 3 2024, 6:47 AM

Details

Summary

Calling cap_rights_contains() several times with the same inputs is not going to produce a different output.

For context, here is the definition of cap_rights_contains() from sys/kern/subr_capability.c:

bool
cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little)
{
        unsigned int i, n;

        assert(CAPVER(big) == CAP_RIGHTS_VERSION_00);
        assert(CAPVER(little) == CAP_RIGHTS_VERSION_00);
        assert(CAPVER(big) == CAPVER(little));

        n = CAPARSIZE(big);
        assert(n >= CAPARSIZE_MIN && n <= CAPARSIZE_MAX);

        for (i = 0; i < n; i++) {
                if ((big->cr_rights[i] & little->cr_rights[i]) !=
                    little->cr_rights[i]) {
                        return (false);
                }
        }

        return (true);
}
Test Plan

Test early. Test often.

Diff Detail

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

Event Timeline

freqlabs retitled this revision from to Eliminate unnecessary loop in _cap_check().
freqlabs updated this object.
freqlabs edited the test plan for this revision. (Show Details)
freqlabs set the repository for this revision to rS FreeBSD src repository - subversion.
ed edited edge metadata.

Interesting. I suspect an older version of this code hand-rolled cap_rights_contains() and was incorrectly refactored?

This revision is now accepted and ready to land.Jul 31 2016, 6:34 AM
oshogbo edited edge metadata.
In D7369#153325, @ed wrote:

Interesting. I suspect an older version of this code hand-rolled cap_rights_contains() and was incorrectly refactored?

It sure looks that way, doesn't it. I dug through the logs to try to pinpoint where the refactor happened, but r255219 introduces the loop just like that. Lost artifact of development, I guess.

freqlabs edited edge metadata.

The variable i is not necessary, either.

This revision now requires review to proceed.Aug 30 2016, 1:48 AM
This revision is now accepted and ready to land.Aug 31 2016, 5:51 PM
This revision was automatically updated to reflect the committed changes.