Network rules

families and types for application developers for administrators for security researchers

A network rule allows socket operations for an address family and a socket type. Twelve permissions from create to receive can narrow it. A confined program with no matching rule gets EACCES from socket. What the rule compiles to depends on the kernel's feature set.

On the map: rule classes

▶ Watch this deck — 9 scenes, ~6 min

Worth seeing first

Part of journeys

01 demo opens a socket

NETWORK RULES demo socket(AF_INET, SOCK_STREAM, 0) the kernel profile demo: a rule for inet + stream? none = -1 EACCES network inet stream, line 11 of demo's profile with the rule: yes TCP socket inet address family: IPv4 stream socket type: TCP is the stream type of inet
demo calls socket(AF_INET, SOCK_STREAM, 0). The kernel finds no rule for inet and stream in profile demo and the call fails with EACCES. With the rule network inet stream the answer is yes and demo gets a TCP socket. inet is the address family IPv4, stream the socket type.

network FAMILY TYPE, allows sockets of that family and type. Without a matching rule a confined task gets EACCES from socket().

Demo is a network service, so the first thing it does is ask for a socket. Under a profile that isn't automatic. The kernel looks for a network rule that covers this family and this type, and if there's none, the socket call fails with EACCES. The rule is one line: network, the family, the type. Inet is IP version four. Stream is the connection-oriented type, which for inet means TCP. That's line eleven of demo's profile. Everything else demo does with the socket is checked against the same rule.

Details and sources

Details

  • The LSM hook socket_create asks for the permission create with the family, type and protocol of the call (lsm.c:1258-1291). It does nothing for sockets the kernel creates for itself and for an unconfined task (lsm.c:1265-1269). A refusal is EACCES.
  • A profile with no network rule refuses every socket when the feature set has network mediation (network_v8, or network_v9 with af_unix): every profile that is not in unconfined or default_allow mode then mediates networking, whether or not it has a network rule. The slide assumes such a feature set.
  • Feature files: /sys/kernel/security/apparmor/features/network_v8/af_mask and network_v9/af_mask (net.c:24-36).
  • network inet stream, is line 11 of demo's profile. The program demo and its profile are invented for the map.
  • Kernel statements are read from the kernel source and were not run.

02 network, permissions, family, type

GRAMMAR QUALIFIERSnetworkPERMISSIONSFAMILYTYPECONDITIONALS, network,network inet,network inet stream,network (bind, listen) inet stream,network tcp, every family, every type, every permission all types of inet permissions go before the family; several need parentheses not a family, so read as a type: inet and inet6 stream CONDITIONALS: ip= port= peer=( ) for inet and inet6, see the next deck
The syntax diagram: optional qualifiers, the word network, optional permissions, family, type and conditionals, a comma. Five examples: network alone; network inet; network inet stream; network (bind, listen) inet stream; and network tcp, where tcp is read as a type.

[QUALIFIERS] network [PERMISSIONS] [FAMILY] [TYPE] [CONDITIONALS],. Each part left out means "all".

Everything after the keyword is optional. Network on its own allows all networking. Add a family and it's that family with all its types. Add a type and it's narrower again. If you want to limit what demo may do with the socket, put a permission list right after the keyword, before the family, and use parentheses when there's more than one. A single word that isn't a family name is taken as a type, so network tcp covers TCP over both IP versions. Address and port conditionals come last, and they have their own deck.

Details and sources

Details

  • Accepted by the tree's parser: network inet,, network inet tcp,, network tcp,, network stream,, network (create, bind listen) inet,, network create inet stream,, network rw inet,, network "inet",, audit deny network,, prompt network inet,.
  • There is no third word after family and type.
  • Qualifiers: audit, deny, allow and prompt are taken. priority= and owner are refused: priority prefix not allowed on network rules, owner prefix not allowed on network rules (network.h:270-276).
  • Rules for the same family merge.

for AppArmor developers for security researchers

In the code

03 Families, types and three aliases

WORDS socket(AF_INET, SOCK_STREAM) network inet stream, = network inet tcp, socket(AF_INET6, SOCK_DGRAM) network inet6 dgram, = network inet6 udp, socket(AF_NETLINK, SOCK_RAW) network netlink raw, 45 families unix inet inet6 netlink packet bluetooth can ... AF_NAME becomes name 6 types stream dgram seqpacket rdm raw packet aliases: tcp udp icmp network inet sctp, Invalid network entry. no word for a protocol number
Three socket calls and the rule that covers each: AF_INET with SOCK_STREAM is network inet stream, the same as network inet tcp; AF_INET6 with SOCK_DGRAM is network inet6 dgram or udp; AF_NETLINK with SOCK_RAW is network netlink raw. There are 45 families and 6 types with the aliases tcp, udp and icmp. network inet sctp is refused.

Family = the AF_ name in lower case (45 of them); type = stream, dgram, seqpacket, rdm, raw, packet; tcp, udp, icmp are aliases. Names are case sensitive.

The words map straight onto the socket call. The family is the AF constant in lower case, without the prefix: inet, inet6, netlink, unix. The type is the sock constant, the same way: stream, dgram, raw. For convenience tcp means stream and udp means dgram, and the parser produces exactly the same policy either way. The resolver sockets in the nameservice abstraction are a good real example. What you can't do is name a protocol by number. There's no word for SCTP, so an SCTP socket is matched by its type.

Details and sources

Details

  • The 45 family names come from base_af_names.h:1-46; the table is in the reference below.
  • Aliases (network.cc:124-153): for inet, tcp is stream, udp is dgram and icmp is raw; for inet6, tcp and udp. network inet stream, and network inet tcp, give identical output (run with the tree's parser).
  • Refused with Invalid network entry.: network inet dccp,, network inet sctp,, network inet6 icmp,, network inet icmpv6,, network bogus,, network INET,, network local,.
  • The parser does not consult the kernel's af_mask: a family the kernel lacks is compiled anyway.
  • The kernel matches the type recorded on the socket (net.c:237) and has a separate hook for SCTP bind and connect (lsm.c:1409-1424; feature network_v8/sctp).
  • A real example: abstractions/nameservice:92-99.
  • Known discrepancy: with a feature set that has af_inet, network inet icmp, carries protocol value 2 rather than 1 (network.cc:148-149). It is not relevant to the mainline kernel, which matches no protocol for inet rules.
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

In the code

04 Twelve permissions, one per step

PERMISSIONS socket()create the socket call setsockopt()setopt bind()bind listen()listen a server sets up accept()accept recv()receive send()send connections and data connect()connect a client dials out getsockname()getattr shutdown()shutdown getsockopt()getopt asking and closing no list = all twelve; setattr is accepted and no socket call asks for it network (create, setopt, bind, listen, accept, send, receive) inet stream,
The socket calls of a server in order, each with the permission it asks for: socket create, setsockopt setopt, bind bind, listen listen, accept accept, recv receive, send send, getsockname getattr, shutdown shutdown; for a client connect connect; and getsockopt getopt. A rule lists seven of them for a server.

create bind listen accept connect shutdown getattr setattr getopt setopt send receive. Each socket call requests one; a rule without a list grants all.

If family and type are too coarse, the permission list says which operations are allowed. They follow the life of a socket. Create for the socket call. Setopt and getopt for options. Bind, listen and accept for a server, connect for a client. Send and receive for the data. Getattr for asking the socket its name, and shutdown at the end. A rule with no list has all of them, which is what line eleven does. A server that should not dial out could leave connect off the list. You can also write read and write for receive and send.

Details and sources

Details

  • Hook, operation name in the log, permission: socket_create, create, create (lsm.c:1258-1291); socket_bind, bind, bind (lsm.c:1372-1388); socket_connect, connect, connect (lsm.c:1390-1407); socket_listen, listen, listen (lsm.c:1426-1440); socket_accept, accept, accept (lsm.c:1446-1461); socket_sendmsg, sendmsg, send (lsm.c:1483-1502); socket_recvmsg, recvmsg, receive (lsm.c:1504-1508); socket_getsockname and socket_getpeername, getattr (lsm.c:1527-1535); socket_getsockopt and socket_setsockopt, getopt and setopt (lsm.c:1555-1567); socket_shutdown, shutdown (lsm.c:1569-1572).
  • Other spellings: read or r for receive, write or w for send, and rw.
  • Sending with MSG_FASTOPEN on TCP or MPTCP is also checked as connect (lsm.c:1490-1499; feature tcp-fast-open).
  • A socket used through read and write, or passed over a unix socket, is checked again as send and receive when the label cached on the file does not cover the task (file.c:551-573).
  • No socket hook requests setattr.
  • Local permissions (create, shutdown, setattr, getattr, bind, listen, setopt, getopt) cannot be combined with peer conditionals; the peer permissions are send, receive, connect and accept.
  • Kernel statements are read from the kernel source and were not run.

Read more

for AppArmor developers for security researchers

In the code

05 What demo and the log see

THE DENIAL network inet stream, demo socket(AF_INET6, SOCK_STREAM, 0) = -1 EACCES apparmor="DENIED" operation="create" class="net" ... profile="demo" pid=... comm="demo"family="inet6" sock_type="stream" protocol=0 requested="create" denied="create" network (create) inet6 stream, those three words are the rule operation="recvmsg" ... laddr=::1 lport=2048 faddr=::1 fport=33986family="inet6" sock_type="stream" protocol=6 connected sockets also show both addresses deny network ..., refuses the same way and logs nothing; audit deny logs
With only network inet stream in the profile, demo asks for an inet6 socket and gets EACCES. The record shows operation create, family inet6, sock_type stream and denied create, which make the rule network (create) inet6 stream. A record for recvmsg on a connected socket also shows the local and remote address and port.

Network denials return EACCES and log family=, sock_type=, protocol=, requested= and denied=. Records for connected inet sockets add laddr, lport, faddr, fport.

Demo's rule says inet. One day it's started with an IP version six address. The socket call fails with EACCES, and demo probably reports permission denied. The log has the answer: operation="create", the family, the socket type, and which permission was denied. Those three words are your rule. For calls on a connected socket, the record also carries the local and remote address and port, which helps you see who demo was talking to. And remember: a deny rule refuses the same way, silently.

Details and sources

Details

  • The first record on the slide is built from the kernel's format strings ( family=, sock_type=, protocol=, requested=, denied=; net.c:38-78, net.c:118-166) with demo's values, which are illustrative.
  • The second record is shortened from testcase_network_04.in. That older sample has no requested= and denied= fields.
  • laddr, lport, faddr and fport come from the common LSM audit code, for sockets other than unix (lsm_audit.c:297-314).
  • A family the kernel has no name for is logged as unknown(N). The info= reasons are failed af match, failed type match and failed protocol match (net.c:234-247).
  • Operation names: create, bind, connect, listen, accept, sendmsg, recvmsg, getsockname, getpeername, getsockopt, setsockopt, socket_shutdown (audit.h:75-87). The class is always net.
  • The check uses the label of the calling task and asks each confined profile of it (net.c:282-284, net.c:301-303).
  • Kernel statements are read from the kernel source and were not run.

06 The same line on three kernels

DEPENDS ON THE KERNEL network (connect) inet stream, the feature set hasnetwork_v8 or network_v9 family + type + permissions only connect is allowed only the old featurenetwork family + type the permission list is lost: every operation on inet stream no network feature(none) rule dropped networking is not mediated $ apparmor_parser --warn=rule-not-enforced --warn=rule-downgraded -Q demo network rules not enforced without those options the parser says nothing; the features directory shows what the kernel has
The rule network (connect) inet stream compiled for three feature sets. With network_v8 or network_v9: family, type and permissions, only connect is allowed. With only the old network feature: family and type, the permission list is lost. With no network feature: the rule is dropped. The parser reports this only with --warn=rule-not-enforced and --warn=rule-downgraded.

With network_v8 or network_v9 the rule keeps its permissions; with only the legacy network feature it is reduced to family and type; with none it is dropped. Use --warn=rule-not-enforced --warn=rule-downgraded to be told.

What you've seen so far is what a current kernel does. The parser compiles each rule for the kernel's feature set, or for the one your abi line pins, and network rules have changed shape over the years. With the current form, the rule keeps its permissions. For an old kernel that only knows the first form, the rule becomes just family and type, and connect-only quietly becomes everything. With no network feature at all, the rule is dropped. None of this is announced unless you ask. Run the parser with the two warn options and it tells you.

Details and sources

Details

  • The three results on the slide were produced with the tree's parser and three feature files: with only the legacy feature, network (connect) inet stream, gives the same output as network inet stream,; with no network feature, every network rule gives the output of a profile without it. Nothing was loaded into a kernel.
  • The feature tests are network, network_v8, network_v9, network_v8/af_inet, network_v9/af_inet, network/af_unix, network_v9/af_unix, network_v9_skb and network_v9_skb/iface. Each is the intersection of the kernel feature set and the policy ABI (parser_main.c:1044-1073).
  • The mainline kernel exports network_v8 with af_mask, tcp-fast-open and sctp, and network_v9 with af_mask, af_unix and tcp-fast-open (net.c:24-36, apparmorfs.c:2688-2689). It has no reader for the legacy per-family table.
  • Warnings, all off by default: network rules not enforced, profile NAME network rules not enforced (network.cc:669-672), downgrading extended network unix socket rule to generic network rule (af_unix.cc:537).
  • Where to look: /sys/kernel/security/apparmor/features/network_v8/ and network_v9/, or aa-features-abi -x.

for security researchers

Attack surface

  • The compiled rule can be broader than the text. On a legacy-only feature set the permission list and all conditionals are lost (network.cc:1138-1167, parser_interface.c:572-584).
  • Conditionals that the feature set cannot express (ip=, port=, label=, interface=) are dropped without a message at any warning level, also from deny rules: see Network address conditionals.
  • Every network rule that covers AF_UNIX also creates a unix rule. Known discrepancy (run with the tree's parser): the permission list is not carried into it, so with the mainline feature set network (create) unix stream, allows every operation on abstract and unnamed unix stream sockets, and network (create), does the same for all unix types (af_unix.cc:105-125): see Unix socket rules.
  • Known discrepancy (run with the tree's parser): on the legacy-only feature set the parser prints network rules not enforced although it writes the table.
  • Not mediated by these rules: sockets the kernel creates for itself (lsm.c:1265-1266), and the packet path: the secmark hooks act only on profiles with a secmark table, which this parser does not write (net.c:371-403).

07 Class, family, type: five bytes for AppArmor developers for security researchers

IN THE PARSER network (connect) inet stream, feature set: mainline (no af_inet) 0f 00 02 00 01 class family AF_INET type SOCK_STREAM perms 0x40 connect class 15, AA_CLASS_NETV9 all six types: the type bytes become .. class 14 when only network_v8 aa_profile_af_perm() start[class] 2 bytes family 2 bytes type early match: take the permissions here 2 bytes protocol only if the state says continue PF_UNIX -> af_unix.c PF_INET, PF_INET6 -> af_inet.c others -> net.c class markers \d14 \d15 are added to every confined profile, so a profile without rules still mediates
The rule network (connect) inet stream as five bytes: 0f for the class, 00 02 for the family AF_INET, 00 01 for the type SOCK_STREAM, with the permission 0x40, connect, at the last state. In the kernel aa_profile_af_perm starts at the class, feeds two bytes of family and two of type and takes the permissions there.

network.cc:1000-1038 writes class, family, type; net.c:228-274 walks them and reads the permissions at the type state.

On a current feature set, each family in a rule becomes one policydb rule: the class byte, fifteen for version nine, two bytes of family, two of type, and the folded permission bits attached to that state. In the kernel, every socket hook dispatches on the family. For the generic path, aa_profile_af_perm starts at the class, feeds the family and the type, and takes the permissions right there, only going on to the protocol if the state asks for it. The class marker rules are why a profile with no network rule still denies sockets.

Details and sources

for AppArmor developers for security researchers

Details

  • The bytes 0f 00 02 00 01 and the permission value 0x40 were produced with the tree's parser and the mainline feature file, for network (connect) inet stream peer=(ip=10.0.0.1 port=80),, which compiles to the same single rule as the line on the slide.
  • Classes: AA_CLASS_NET 4, AA_CLASS_NETV8 14, AA_CLASS_NETV9 15, AA_CLASS_NETV9_SKB 30 (policydb.h:28, policydb.h:38-39, policydb.h:54).
  • In the kernel RULE_MEDIATES_NET tries class 15 and falls back to the kernel's AA_CLASS_NET, which is 14 (policy.h:346-358, apparmor.h:30-31). The walk: net.c:192-274.
  • All six types together (ALL_TYPES, 0x43e) become .. in the match string (network.cc:40, network.cc:1009-1029).
  • The legacy table net_allowed_af holds, per family, three u16 values: allow without deny, allowed and audited, deny and quiet (parser_interface.c:572-582).
  • The rule class is mergeable and compared by family map and conditionals (network.cc:1301-1314). The grammar action also creates the unix rule and updates the legacy table (parser_yacc.y:757-779).
  • The class markers are added for every confined profile at parser_regex.c:1415-1440.
  • Known discrepancy: the unix class-marker rule matches the family bytes 0x00 0x31 instead of 0x00 0x01 (parser_regex.c:1339-1353). No effect was found for the mainline kernel.
  • Kernel statements are read from the kernel source and were not run.

for AppArmor developers for security researchers

Read more

08 Mistakes and their messages

MISTAKES network inet stream tcp, syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE two words at most network INET stream, Invalid network entry. names are lower case network inet create, syntax error, unexpected TOK_CREATE, expecting TOK_END_OF_RULE permissions go first network send receive inet, syntax error, unexpected TOK_RECEIVE, expecting TOK_END_OF_RULE two permissions need parentheses priority=1 network inet, priority prefix not allowed on network rules owner is refused too network (bind) inet peer=(port=8080), network 'create', ... 'bind', ... accesses cannot be used with peer socket conditionals
Six refused network rules with the message of the parser: three words after network; a family in capitals; a permission after the family; two permissions without parentheses; priority on a network rule; bind combined with a peer conditional.

At most a family and a type; permissions first and in parentheses when several; no priority= and no owner.

A network rule takes at most two words, so inet stream tcp is one too many: tcp already means stream. The names are lower case. Permissions go before the family, not after. Two permissions without parentheses stop the parser at the second. Network rules are one of the few classes that refuse priority, and they refuse owner too. And a permission that's about your own socket, like bind, can't be combined with conditions on the peer.

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, produced by the tree's parser. The messages of rows 3 and 4 continue with the tokens the parser expected.
  • The full text of the last message: network 'create', 'shutdown', 'setattr', 'getattr', 'bind', 'listen', 'setopt', and/or 'getopt' accesses cannot be used with peer socket conditionals (network.cc:526).
  • An unknown word in the permission list is read as r and w letters: network (bogus) inet, gives Internal: unexpected net perms character 'b' in input, and network (rwx) inet, the same for x.
  • owner network inet, gives owner prefix not allowed on network rules (network.h:270-276).
  • network inet xattrs=(a=b), gives network rule: invalid conditional group xattrs=().
  • Failing examples in the tree: the network_bad_*.sd files in parser/tst/simple_tests/network.

09 Finer rules for two families

ROADS network inet stream, family and type; finer rules exist for inet and unix syn-network-inet ip= port= syn-unix unix sockets syn-capability net_bind_service, net_raw prac-abstractions nameservice adm-features what the kernel has syn-abi pinning a feature set upstream-and-ubuntu which kernel enforces
Network rules in the centre with roads to syn-network-inet and syn-unix, to syn-capability and prac-abstractions, and to adm-features, syn-abi and upstream-and-ubuntu.

Next: address conditionals, unix rules, and the feature set of your kernel.

Family and type are the coarse grid. Two families have finer rules: inet and inet6, with address and port conditionals, and unix sockets, with their own rule class. Low ports and raw sockets also need a capability. And since so much here depends on the kernel, the features deck and the upstream and Ubuntu deck tell you what yours enforces.

Details and sources

Details

  • [QUALIFIERS] network [PERMISSIONS] [FAMILY] [TYPE] [CONDITIONALS],: each part left out means all.
  • A refused socket operation returns EACCES and is logged with family=, sock_type= and denied=.
  • What a rule compiles to depends on the feature set; --warn=rule-not-enforced --warn=rule-downgraded makes the parser say so.
  • 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), 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

NETWORK RULE:  [QUALIFIERS] network [PERMISSIONS] [FAMILY] [TYPE] [CONDITIONALS] ,
PERMISSIONS:   PERMISSION | ( PERMISSION ... )
QUALIFIERS:    [audit] [allow|deny|prompt]
  • Every part after the keyword is optional and means "all" when left out (tree).
  • A permission list comes before the family; more than one permission needs parentheses; inside them blanks or commas separate (tree).
  • The first word is looked up as a family; a single word that is not a family is looked up as a type or alias across all families: network tcp, is inet and inet6 stream (tree).
  • At most two words. Names are case sensitive (tree).
  • Conditionals (ip=, port=, peer=( )) are in syn-network-inet.

Families

The name is the kernel's AF_ constant in lower case (parser/base_af_names.h).

NameConstantNumber
unspecAF_UNSPEC0
unixAF_UNIX1
inetAF_INET2
ax25AF_AX253
ipxAF_IPX4
appletalkAF_APPLETALK5
netromAF_NETROM6
bridgeAF_BRIDGE7
atmpvcAF_ATMPVC8
x25AF_X259
inet6AF_INET610
roseAF_ROSE11
netbeuiAF_NETBEUI13
securityAF_SECURITY14
keyAF_KEY15
netlinkAF_NETLINK16
packetAF_PACKET17
ashAF_ASH18
econetAF_ECONET19
atmsvcAF_ATMSVC20
rdsAF_RDS21
snaAF_SNA22
irdaAF_IRDA23
pppoxAF_PPPOX24
wanpipeAF_WANPIPE25
llcAF_LLC26
ibAF_IB27
mplsAF_MPLS28
canAF_CAN29
tipcAF_TIPC30
bluetoothAF_BLUETOOTH31
iucvAF_IUCV32
rxrpcAF_RXRPC33
isdnAF_ISDN34
phonetAF_PHONET35
ieee802154AF_IEEE80215436
caifAF_CAIF37
algAF_ALG38
nfcAF_NFC39
vsockAF_VSOCK40
kcmAF_KCM41
qipcrtrAF_QIPCRTR42
smcAF_SMC43
xdpAF_XDP44
mctpAF_MCTP45

Rules that cover unix also create a unix rule; see syn-unix.

Types and aliases

WordConstantAlias
streamSOCK_STREAMtcp for inet and inet6
dgramSOCK_DGRAMudp for inet and inet6
rawSOCK_RAWicmp for inet
seqpacketSOCK_SEQPACKET
rdmSOCK_RDM
packetSOCK_PACKET

There is no word for a protocol number: network inet sctp, and network inet dccp, are refused (tree).

Permissions

WordAlso writtenSideRequested by (LSM hook)Operation in the log
createlocalsocket_createcreate
bindlocalsocket_bindbind
listenlocalsocket_listenlisten
acceptpeersocket_acceptaccept
connectpeersocket_connectconnect
sendwrite, wpeersocket_sendmsgsendmsg
receiveread, rpeersocket_recvmsgrecvmsg
getattrlocalsocket_getsockname, socket_getpeernamegetsockname, getpeername
setattrlocalnone
getoptlocalsocket_getsockoptgetsockopt
setoptlocalsocket_setsockoptsetsockopt
shutdownlocalsocket_shutdownsocket_shutdown
  • A rule without a list grants all twelve (code). rw is send and receive.
  • Local permissions cannot be combined with peer conditionals (tree).
  • The hooks are read from linux:security/apparmor/lsm.c:1258-1572, not from a run.

Qualifiers

SeatOn a network rule
priority=refused: priority prefix not allowed on network rules (tree)
audittaken
allow, deny, prompttaken: deny is not logged; prompt is in syn-prompt
owner, otherrefused: owner prefix not allowed on network rules (tree)

What depends on the feature set

The feature set hasThe rule is compiled asLost
network_v8 or network_v9family, type and permissionsconditionals, unless it also has af_inet: see syn-network-inet
only the legacy networkfamily and typethe permission list and all conditionals
no network featurenothing: the rule is droppedeverything; networking is not mediated
  • Results from the tree's parser with three feature files (tree).
  • The parser reports this only with --warn=rule-not-enforced and --warn=rule-downgraded; both are off by default (code).
  • See adm-features, syn-abi and upstream-and-ubuntu.

The log record

FieldMeaning
operation=the socket operation, see the permission table
class="net"always
family=the family name, or unknown(N)
sock_type=the socket type
protocol=the protocol number
requested=, denied=permission names
laddr=, lport=, faddr=, fport=local and remote address and port, for sockets other than unix
info=failed af match, failed type match or failed protocol match

Read from the kernel's format strings (linux:security/apparmor/net.c:38-166, linux:security/lsm_audit.c:297-314).

Errors and warnings

RuleMessage
network inet stream tcp,syntax error, unexpected TOK_ID, expecting TOK_END_OF_RULE
network INET stream,Invalid network entry.
network inet sctp,Invalid network entry.
network inet create,syntax error, unexpected TOK_CREATE, expecting TOK_END_OF_RULE
network send receive inet,syntax error, unexpected TOK_RECEIVE, expecting TOK_END_OF_RULE
network (bogus) inet,Internal: unexpected net perms character 'b' in input
priority=1 network inet,priority prefix not allowed on network rules
owner network inet,owner prefix not allowed on network rules
network (bind) inet peer=(port=8080),network 'create', 'shutdown', 'setattr', 'getattr', 'bind', 'listen', 'setopt', and/or 'getopt' accesses cannot be used with peer socket conditionals
network inet xattrs=(a=b),network rule: invalid conditional group xattrs=()
any network rule, no network feature, --warn=rule-not-enforcedwarning network rules not enforced
a unix rule on a feature set without unix mediation, --warn=rule-downgradedwarning downgrading extended network unix socket rule to generic network rule

All rows are from the tree's parser.

for AppArmor developers

Encoding

  • Per family one policydb rule: the class byte (AA_CLASS_NETV9 15, or AA_CLASS_NETV8 14), two bytes of family and two of type, big endian, with the folded permissions at that state (parser/network.cc:1000-1038). network (connect) inet stream, is \x0f\x00\x02\x00\x01 with 0x40 (tree).
  • All six types become .. (parser/network.cc:1009-1029).
  • Class markers for classes 14 and 15 are added to every confined profile (parser/parser_regex.c:1415-1440), which is why a profile without network rules refuses sockets.
  • The legacy table net_allowed_af: per family three u16 values (parser/parser_interface.c:572-582).
  • Kernel: every socket hook dispatches on the family; the generic match aa_profile_af_perm starts at the class, feeds family and type and reads the permissions there (linux:security/apparmor/net.c:192-274).
  • Grammar and scanner: parser/parser_yacc.y:1154-1194, parser/parser_lex.l:627-694.

for security researchers

Known discrepancies

None of these is taught as intended behaviour; the verdicts come from the review.

  • network (PERMISSIONS) unix ... creates a unix rule with every permission (tree): see syn-unix.
  • inet conditionals are dropped without a message when the feature set has no af_inet, also from deny rules (tree): see syn-network-inet.
  • network inet icmp, carries protocol value 2 on a feature set with af_inet (code).
  • The unix class-marker rule matches the family bytes 0x00 0x31 (code).
  • On a legacy-only feature set the parser prints network rules not enforced although it writes the table (tree).

Roads from here

START HERE

PREAMBLE AND REUSE

QUALIFIERS

RULE CLASSES

IN PRACTICE · general-purpose apps

SECURITY · threat model and limits

RUNNING THE PARSER