io_uring rules

io_uring operations for application developers for administrators for security researchers

An io_uring rule allows two features of io_uring. sqpoll is a kernel thread that polls the submission queue. override_creds is running a request with other registered credentials and label= limits whose. Creating a ring and submitting requests are not mediated by this class. A profile compiled for a feature set that lists io_uring denies both features without a rule.

On the map: rule classes

▶ Watch this deck — 9 scenes, ~5 min

Worth seeing first

01 demo asks for a polling thread

IO_URING RULES demo the kernel submission queue completion queue io_uring_setup(64, { .flags = 0 }) allowed: no rule needed io_uring_setup(64, { .flags = IORING_SETUP_SQPOLL }) polling thread = -1 EACCESwithout the rule io_uring sqpoll, line 22 of demo's profile the rule class knows two words: sqpoll and override_creds
demo sets up an io_uring ring, with a submission queue and a completion queue in the kernel. A plain io_uring_setup call with no flags is allowed and needs no rule. A setup call with IORING_SETUP_SQPOLL, which asks for a polling thread beside the submission queue, is refused with EACCES. The rule io_uring sqpoll allows it. The rule class knows two words: sqpoll and override_creds.

io_uring sqpoll, allows a ring with a submission-queue polling thread. A plain ring needs no rule.

Demo handles its sockets with io_uring, the kernel's interface for queuing many requests at once. Setting up a plain ring needs nothing from the profile. But demo wants the kernel to poll its queue with a thread of its own, so it doesn't have to make a system call per batch. That option is one of two io_uring features AppArmor puts behind a rule. Without the rule the setup call is refused. Line twenty-two allows it: io_uring sqpoll.

Details and sources

Details

  • The LSM hook is uring_sqpoll (lsm.c:683-704, registered at lsm.c:1889). It is called when a ring is created with IORING_SETUP_SQPOLL (sqpoll.c:505).
  • The feature file is /sys/kernel/security/apparmor/features/io_uring/mask, which reads sqpoll override_creds (apparmorfs.c:2679-2682).
  • io_uring sqpoll, is line 22 of demo's profile; it compiles with no warning (run with the tree's parser). The program demo and its profile are invented for the map.
  • Kernel statements are read from the kernel source and were not run.

02 Two permissions and a label

GRAMMAR QUALIFIERSio_uringPERMISSIONSlabel=LABEL, io_uring sqpoll, line 22 of demo's profile io_uring (sqpoll, override_creds), both, in parentheses io_uring override_creds label=demo-helper, label= belongs to override_creds io_uring, both permissions, any label audit deny io_uring override_creds, audit, allow, deny, priority= work; owner is refused
The syntax diagram of an io_uring rule: optional qualifiers, the word io_uring, optional permissions, an optional label conditional, a comma. Examples: io_uring sqpoll; both permissions in parentheses; override_creds with label=demo-helper; io_uring alone for both permissions and any label; and audit deny io_uring override_creds.

[QUALIFIERS] io_uring [sqpoll | override_creds | (sqpoll, override_creds)] [label=LABEL],.

The keyword is io_uring, with an underscore. Then the permissions: sqpoll, override_creds, or both in parentheses. Then one conditional, label, which only means something for override_creds. Leave the permissions out and you get both. The usual qualifiers go in front.

Details and sources

Details

  • The permissions are sqpoll and override_creds. A rule without a permission has both.
  • label takes = only, one value, and may appear once: only "=" allowed in conditions of io_uring rules, io_uring conditional "label" only supports a single value, io_uring conditional "label" can only be specified once. Blanks around = are allowed (label = /bar, ok_io_uring_09.sd).
  • Seats: audit, allow, deny, prompt and priority= are taken; owner and other are refused: owner io_uring, gives owner prefix not allowed on io_uring rules (run with the tree's parser).
  • Known discrepancy, on the bug list as "Variables in io_uring ... label= are not expanded": the label does not take variables. io_uring override_creds label=@{profile_name}, fails when the policy is compiled, with Unable to parse input line '@{profile_name}' and no line number (run with the tree's parser).
  • Examples in the tree: ok_io_uring_05.sd, ok_io_uring_07.sd.

for AppArmor developers for security researchers

In the code

03 Two features, not io_uring as a whole

WHAT IS ASKED the kernel demo 1 io_uring_setup() not asked 2 io_uring_enter(): read, write, accept ... not asked by this class the file and network rules still apply to what a request touches 3 io_uring_setup(IORING_SETUP_SQPOLL) sqpoll profile demo is asked 4 a request with personality = id override_creds no io_uring rule in a current profile: calls 3 and 4 are refused, 1 and 2 go on as before
Four calls from demo to the kernel. io_uring_setup is not asked. io_uring_enter with read, write or accept requests is not asked by this class; the file and network rules still apply to what a request touches. io_uring_setup with IORING_SETUP_SQPOLL passes the profile, which is asked for sqpoll. A request with a personality passes the profile, which is asked for override_creds. With no io_uring rule in a current profile, calls 3 and 4 are refused and calls 1 and 2 go on as before.

Mediated: IORING_SETUP_SQPOLL and requests that use a registered personality. Not mediated by this class: creating a ring, submitting requests.

It's easy to read io_uring sqpoll as: may use io_uring. It isn't that. AppArmor doesn't mediate creating a ring or submitting requests through this class. What a request does, opening a file or connecting a socket, is still checked by the rules for files and sockets. The class covers exactly two things: starting the polling thread, and submitting a request that runs with credentials other than the task's own. A profile with no io_uring rule refuses those two, and nothing else.

Details and sources

Details

  • The kernel has four io_uring LSM hooks; AppArmor registers two, uring_override_creds and uring_sqpoll (lsm.c:1888-1889). security_uring_allowed (io_uring.c:3401) and security_uring_cmd (uring_cmd.c:236) have no AppArmor implementation.
  • The default: a confined profile compiled for a feature set with io_uring mediates the class, so both features are refused without a rule. Without the feature the rule is dropped (warning io_uring rules not enforced, class rule-not-enforced, off by default) and the kernel allows both, because there is nothing to check (lsm.c:627-654).
  • In the tree only abi/5.0 and abi/5.0-interface list io_uring.
  • "The file and network rules still apply to what a request touches" states the general design of LSM hooks, which sit on the operations themselves; it was not traced for each io_uring request type.
  • Kernel statements are read from the kernel source and were not run.

for security researchers

Attack surface

  • A profile cannot forbid io_uring as such with this class: there is no permission for ring creation, and passthrough commands (uring_cmd) are not seen by AppArmor.
  • A profile pinned to an ABI before 5.0, or with no abi rule, cannot deny sqpoll or override_creds either; deny io_uring, there compiles to nothing.

04 override_creds: whose credentials

OTHER CREDENTIALS personality 1: demo-helper registered with the ring demo demo sqe->personality = 1 may demo use credentials labelled demo-helper? io_uring override_creds label=demo-helper, allowed personality 2: unconfined refused: label does not match io_uring override_creds, no label: any credentials label= changes nothing for sqpoll
demo, under profile demo, has registered credentials labelled demo-helper with its ring as personality 1. It submits a request with personality 1 and the kernel asks whether demo may use credentials labelled demo-helper. The rule io_uring override_creds label=demo-helper allows it. A second personality with the label unconfined is refused: the label does not match. io_uring override_creds without a label allows any credentials. label= changes nothing for sqpoll.

io_uring override_creds label=L, allows requests under registered credentials whose label matches L. Without label=, any.

The second feature is subtler. A program can register a set of credentials with its ring, called a personality, and later submit a request that runs with those credentials instead of its own. That's a way to act as someone else, so AppArmor asks. The question is about the label on those credentials. The permission override_creds with label=demo-helper lets demo use credentials that carry the demo-helper label, and nothing else. Leave the label out and any credentials will do. And note that label has no effect on sqpoll.

Details and sources

Details

  • The LSM hook is uring_override_creds(const struct cred *new) (lsm.c:663-682, registered at lsm.c:1888). It is called when a request with registered credentials is submitted (io_uring.c:1989).
  • For each confined profile that mediates the class, the label of the new credentials is matched and the override_creds permission is required (lsm.c:642-647, perms.h:51-53).
  • A personality is a copy of the credentials of the task that registers it, at that moment (register.c:90-96). Its label differs from the submitter's when the ring was registered before a profile change or by another process that shares the ring; in the tree's fixture tcontext equals profile.
  • The label in the rule is a pattern. A refusal carries tcontext= with the label of the credentials.
  • io_uring sqpoll label=demo-helper, compiles to the same rule as io_uring sqpoll, (run with the tree's parser).
  • The personality numbers and the demo-helper credentials are invented for the slide. "Refused" for personality 2 is derived from the match of the target label and was not run.
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

In the code

  • The kernel's name for the permission is AA_MAY_OVERRIDE_CRED (0x8) (perms.h:51-53).

05 What demo and the log see

THE DENIAL demo io_uring_setup(IORING_SETUP_SQPOLL) = -1 EACCES apparmor="DENIED" operation="uring_sqpoll" class="io_uring" profile="demo"pid=1320 comm="demo" requested="sqpoll" denied="sqpoll" apparmor="DENIED" operation="uring_override" class="io_uring" profile="demo"pid=1193 comm="demo" requested="override_creds" denied="override_creds" tcontext="demo-helper" io_uring sqpoll, denied= is the permission word io_uring override_creds label=demo-helper, tcontext is the label to put in the rule
demo calls io_uring_setup with IORING_SETUP_SQPOLL and gets EACCES. The record has operation uring_sqpoll, class io_uring, requested sqpoll and denied sqpoll; the denied word is the permission for the rule io_uring sqpoll. A second record has operation uring_override, requested and denied override_creds, and tcontext demo-helper; tcontext is the label to put in the rule io_uring override_creds label=demo-helper.

operation="uring_sqpoll" and operation="uring_override", class="io_uring"; tcontext= is the label for label=.

The setup call fails with EACCES. A refused request doesn't fail a call: it completes with -EACCES as its result. In the log they have different operation names: uring_sqpoll for the polling thread, uring_override for the credentials. Denied gives you the permission word for the rule. And the override record has one more field, tcontext: that's the label of the credentials demo tried to use, and it's exactly what goes after label=.

Details and sources

Details

  • Both records on the slide are assembled from fixtures, with demo's values, which are illustrative: testcase_io_uring_01.in (operation="uring_sqpoll" class="io_uring" ... requested="sqpoll" denied="sqpoll") and testcase_io_uring_02.in (operation="uring_override" ... requested="override_creds" denied="override_creds" tcontext=...).
  • requested= and denied= are sqpoll or override_creds; tcontext= is printed when there is a target label (lsm.c:598-625). The error is EACCES (lib.c:440): io_uring_setup returns it (sqpoll.c:505-507); for override_creds it is the res of the request's completion entry, and io_uring_enter itself succeeds (io_uring.c:1989-1993, io_uring.c:2000-2026).
  • A plain deny refuses without a record; in complain mode the record is ALLOWED.
  • Kernel statements are read from the kernel source and were not run.

06 One state for sqpoll, a label walk for override_creds for AppArmor developers for security researchers

IN THE PARSER io_uring (sqpoll, override_creds) label=demo-helper, \x16 class 22 0x18 sqpoll | override_creds 0x4 marker, same priority 0x4 \d22 at priority -1001 demo-helper 0x18 read for override_creds no label= in the rule: any label profile_uring() sqpoll: perms = aa_lookup_perms(class state) override_creds: aa_label_match(new, class state) the same scheme as userns: permissions on the class state, so the marker cannot sit above them
The rule io_uring (sqpoll, override_creds) label=demo-helper. The byte 16 hexadecimal, class 22, leads to a state that carries the permissions 0x18, a marker 0x4 at the same priority and the generic marker 0x4 at priority minus 1001. From that state the label demo-helper leads to a second state with 0x18. In the kernel profile_uring reads the class state for sqpoll and matches the label of the new credentials from the class state for override_creds.

io_uring.cc:116-164 writes \x16 with the permissions, a marker, and \x16 + label for override_creds; lsm.c:627-654 reads them.

Like userns, this class keeps permissions on the state right after the class byte, twenty-two. So each rule writes its permissions there and a marker at the same priority, and the generic marker goes to the bottom priority. When override_creds is among the permissions, a second rule continues from that state through the label, or through any label if none was given. In the kernel, the sqpoll check reads the class state. The override check walks the label of the new credentials from there.

Details and sources

for AppArmor developers for security researchers

Details

  • Dumps from the tree's parser (-D rule-exprs): io_uring sqpoll, gives \x16 with 0x10 and \x16 with 0x4; io_uring override_creds label=demo-helper, gives \x16 0x8, \x16 0x4 and \x16demo-helper 0x8; the line on the slide gives \x16 0x18, \x16 0x4 and \x16demo-helper 0x18; io_uring, gives \x16 0x18, \x16 0x4 and \x16[^\000]* 0x18. The generic marker is \d22 at priority -1001.
  • The rule: io_uring.cc:53-70, io_uring.cc:116-164. Class AA_CLASS_IO_URING is 22 (policydb.h:46). The generic marker is added for confined profiles only (parser_regex.c:1450-1452).
  • Kernel: profile_uring (lsm.c:627-654).
  • Known discrepancy, on the bug list as "io_uring accepts a conditional group with any name": the grammar accepts one conditional group of any name after the conditionals and treats its contents as plain conditionals: io_uring override_creds peer=(label=foo), and io_uring override_creds xattrs=(label=foo), mean label=foo (run with the tree's parser).
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

Read more

07 An unknown word inside the parentheses for AppArmor developers for security researchers

SPELLING io_uring sqpol, syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE io_uring (sqpoll, bogus), sqpoll the unknown word is dropped io_uring (sqpol), sqpoll + override_creds, any label io_uring, sqpoll + override_creds, any label identical no message for the second and third rule read from the compiled rules; a known discrepancy
Four io_uring rules and what they compile to. io_uring sqpol without parentheses is a syntax error. io_uring (sqpoll, bogus) compiles to sqpoll: the unknown word is dropped. io_uring (sqpol) compiles to sqpoll and override_creds with any label, identical to io_uring alone. There is no message for the second and third rule. Read from the compiled rules; a known discrepancy.

io_uring (sqpol), compiles exactly like io_uring, (parser_yacc.y:1597-1608, io_uring.cc:56-64). Checked with the tree's parser.

One for reviewers. Misspell a permission without parentheses and the parser stops you. Put the same misspelling in parentheses and it's skipped without a word. That's harmless when a correct word is next to it. But if the misspelt word is the only one, the list is empty, and for this rule an empty permission set means all of them. So a line that was meant to allow only the polling thread allows overriding credentials with any label as well. When you audit a profile, compare the words in io_uring parentheses letter by letter.

Details and sources

for AppArmor developers for security researchers

Details

  • Run with the tree's parser (-D rule-exprs): io_uring (sqpol), gives \x16 0x18, \x16 0x4 and \x16[^\000]* 0x18, the same three rules as io_uring,; io_uring (sqpoll, bogus), gives \x16 0x10 and \x16 0x4; io_uring sqpol, gives syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE.
  • The grammar action for a word in the list returns 0 for an unknown word instead of failing (parser_yacc.y:1597-1608), and the constructor treats 0 as "default to all" (io_uring.cc:56-64).
  • The other classes with lists fail on an unknown word; compare mqueue (create, bogus) /q,, which gives Internal: unexpected mqueue perms character 'b' in input.
  • Known discrepancy, on the bug list as "An unknown permission inside io_uring ( ... ) is ignored, and a list of unknown words means all permissions". Nothing here was run on a kernel.

for AppArmor developers for security researchers

Attack surface

  • The effect is a silent widening from one permission to both, including override_creds for any label.
  • With deny, a misspelt single word denies both, which is wider than written; with a correct word beside it, the misspelt one is silently not denied.
  • Reproduce with apparmor_parser -Q -K --skip-kernel-load -D rule-exprs. It is on the bug list as confirmed; see Known bugs.

for AppArmor developers for security researchers

Read more

08 Mistakes and their messages

MISTAKES io_uring read, syntax error, unexpected TOK_READ, expecting TOK_END_OF_RULE io_uring override_creds peer=demo-helper, invalid io_uring conditional "peer" the conditional is label= io_uring sqpoll label=(a b), io_uring conditional "label" only supports a single value owner io_uring, owner prefix not allowed on io_uring rules io_uring sqpoll override_creds, syntax error, unexpected TOK_OVERRIDE_CREDS, expecting TOK_END_OF_RULE two permissions need parentheses
Five io_uring rules. The word read is a syntax error. A conditional named peer is refused; the conditional is label=. label with a list of two values is refused. owner is refused. Two permissions without parentheses are a syntax error; they need parentheses.

Words: sqpoll, override_creds. Conditional: label= with one value.

The permissions are sqpoll and override_creds, and any other word outside parentheses is a syntax error. The conditional is label, not peer. It takes one value. Owner isn't allowed. Two permissions need parentheses. And take care with spelling inside them, because there the parser doesn't complain.

Details and sources

Details

  • The parser prints an error as AppArmor parser error for FILE in profile FILE at line N: MESSAGE; the slide shows MESSAGE. All five rows were run with the tree's parser. In row 1 the unexpected token is TOK_READ because read is a keyword; an unknown word such as sqpol gives unexpected TOK_ID.
  • When the feature set lacks io_uring, the rule is dropped; --warn=rule-not-enforced prints io_uring rules not enforced.
  • A variable in the label fails when the policy is compiled; see the details of "Two permissions and a label".
  • A failing example in the tree: bad_io_uring_01.sd.

for AppArmor developers for security researchers

In the code

09 Next to io_uring

ROADS io_uring sqpoll, the polling thread, and other credentials k-labels labels on credentials syn-rule-conditionals label= syn-userns the same kind of default syn-abi the feature set sec-unmediated the rest of io_uring adm-denials the uring records
io_uring rules in the centre with roads to k-labels and syn-rule-conditionals, to syn-userns and syn-abi, and to sec-unmediated and adm-denials.

io_uring rules cover sqpoll and override_creds only.

That's the io_uring rule: the polling thread, and other people's credentials. Labels have their own deck in the kernel district. The userns rule works the same way when it comes to defaults. And the deck on what isn't mediated puts the rest of io_uring in context.

Details and sources

Details

  • [QUALIFIERS] io_uring [PERMISSIONS] [label=LABEL],: the permissions are sqpoll and override_creds; without a list the rule has both.
  • A refused setup returns EACCES; a refused request completes with -EACCES. Both are logged, as operation="uring_sqpoll" or operation="uring_override".
  • Commits read for this deck: AppArmor 836052d21 (6.0.0~alpha2) and the kernel tree named on the page. The kernel behaviour was read from the source, not observed on a running kernel.

Read more

Basis of the statements on this page: "tree" means the parser built from the AppArmor commit above was run on the line (-Q -K --skip-kernel-load --warn=all, -D rule-exprs for compiled forms), with nothing loaded into a kernel; "code" means the parser source or the kernel source was read, not run. Nothing here was observed on a running kernel.

Grammar

IO_URING RULE:  [QUALIFIERS] io_uring [PERMISSIONS] [label=LABEL] ,
PERMISSIONS:    sqpoll | override_creds | ( sqpoll, override_creds )
QUALIFIERS:     [priority=N] [audit] [allow|deny|prompt]
  • Without permissions the rule has both (tree).
  • label takes =, one value, once; blanks around = are allowed (tree). It applies to override_creds only.
SeatOn an io_uring rule
priority=taken
audittaken
allow, deny, prompttaken: deny is not logged; prompt is in syn-prompt
owner, otherrefused: owner prefix not allowed on io_uring rules (tree)

Permissions

WordThe io_uring featureKernel hookOperation in the log
sqpolla ring with a kernel thread that polls the submission queue (IORING_SETUP_SQPOLL)uring_sqpolluring_sqpoll
override_credsa request that runs with credentials registered with the ring (a personality)uring_override_credsuring_override

Hooks: linux:security/apparmor/lsm.c:663-704 (code).

What the class does not cover

OperationSeen by AppArmor through this class
creating a ring (io_uring_setup without IORING_SETUP_SQPOLL)no
submitting requests (io_uring_enter)no
passthrough commands (LSM hook uring_cmd)no: no AppArmor implementation
the LSM hook uring_allowedno: no AppArmor implementation

Read from linux:security/apparmor/lsm.c:1785-1890 (code).

Feature set and default

The feature setNo io_uring ruleWith a rule
lists io_uring (abi/5.0, abi/5.0-interface)both features refusedas the rule says
does not list it (abi/3.0, abi/4.0, abi/4.0-ip, the kernel-5.4 files, no abi rule (the parser's built-in default))both allowedthe rule is dropped, also a deny; both allowed

The warning for a dropped rule is io_uring rules not enforced, class rule-not-enforced, off by default (tree). The feature file is /sys/kernel/security/apparmor/features/io_uring/mask, which reads sqpoll override_creds (code).

The log records

FieldMeaning
operation=uring_sqpoll or uring_override
class="io_uring"always
requested=, denied=sqpoll or override_creds
tcontext=the label of the credentials, for uring_override

Records from the tree (libraries/libapparmor/testsuite/test_multi/testcase_io_uring_01.in and testcase_io_uring_02.in):

apparmor="DENIED" operation="uring_sqpoll" class="io_uring" profile="/root/apparmor/tests/regression/apparmor/io_uring" pid=1320 comm="io_uring" requested="sqpoll" denied="sqpoll"
apparmor="DENIED" operation="uring_override" class="io_uring" profile="/root/apparmor/tests/regression/apparmor/io_uring" pid=1193 comm="io_uring" requested="override_creds" denied="override_creds" tcontext="/root/apparmor/tests/regression/apparmor/io_uring"

A refused setup returns EACCES; a refused request completes with -EACCES (linux:io_uring/sqpoll.c:505-507, linux:io_uring/io_uring.c:1989-1993, code).

Errors and warnings

RuleMessage
io_uring read,syntax error, unexpected TOK_READ, expecting TOK_END_OF_RULE
io_uring sqpol,syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE
io_uring sqpoll override_creds,syntax error, unexpected TOK_OVERRIDE_CREDS, expecting TOK_END_OF_RULE
io_uring override_creds peer=demo-helper,invalid io_uring conditional "peer"
io_uring sqpoll label=(a b),io_uring conditional "label" only supports a single value
label given twiceio_uring conditional "label" can only be specified once
an operator other than =only "=" allowed in conditions of io_uring rules
owner io_uring,owner prefix not allowed on io_uring rules
io_uring override_creds label=@{profile_name},Unable to parse input line '@{profile_name}', no line number
io_uring (sqpol),none; compiles like io_uring,
any io_uring rule, no io_uring in the feature set, --warn=rule-not-enforcedwarning io_uring rules not enforced

Rows with a rule are from the tree's parser; the two others are read from the parser source (code).

for AppArmor developers for security researchers

In the parser and the kernel

  • Class AA_CLASS_IO_URING 22 (parser/policydb.h:46); sqpoll 0x10, override_creds 0x8 (parser/io_uring.h:29-33).
  • A rule writes up to three policydb rules (parser/io_uring.cc:116-164): \x16 with the permissions, \x16 with the marker 0x4 at the rule's priority, and, when override_creds is among the permissions, \x16 + label (or [^\000]*) with the permissions.
  • The generic marker \d22 is added at the minimum priority for confined profiles (parser/parser_regex.c:1450-1452); the scheme is the one of syn-userns.
  • Kernel: profile_uring (linux:security/apparmor/lsm.c:627-654) reads the class state for sqpoll and calls aa_label_match on the new credentials' label for override_creds.
  • Grammar: parser/parser_yacc.y:1597-1627.

for AppArmor developers for security researchers

Known discrepancies

None of these is taught as intended behaviour. All are on the bug list as confirmed; see Known bugs.

  • An unknown word inside the parentheses is ignored; a list of only unknown words compiles as both permissions: io_uring (sqpol), equals io_uring, (tree).
  • The label does not take variables: io_uring override_creds label=@{profile_name}, fails at compile time without a line number (tree).
  • A conditional group of any name is read as plain conditionals: io_uring override_creds peer=(label=foo), means label=foo (tree).
  • The scanner state IOURING_MODE is declared and never entered (code).

Roads from here

START HERE

PREAMBLE AND REUSE

QUALIFIERS

RULE CLASSES

SECURITY · threat model and limits

RUNNING THE PARSER

IN THE KERNEL