6456ccbd | 04-Jun-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: fix regression in fs based unix sockets when using old abi
Policy loaded using abi 7 socket mediation was not being applied correctly in all cases. In some cases with fs based unix sockets
apparmor: fix regression in fs based unix sockets when using old abi
Policy loaded using abi 7 socket mediation was not being applied correctly in all cases. In some cases with fs based unix sockets a subset of permissions where allowed when they should have been denied.
This was happening because the check for if the socket was an fs based unix socket came before the abi check. But the abi check is where the correct path is selected, so having the fs unix socket check occur early would cause the wrong code path to be used.
Fix this by pushing the fs unix to be done after the abi check.
Fixes: dcd7a559411e ("apparmor: gate make fine grained unix mediation behind v9 abi") Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
50d56a1a | 14-Jun-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: fix AA_DEBUG_LABEL()
AA_DEBUG_LABEL() was not specifying it vargs, which is needed so it can output debug parameters.
Fixes: 71e6cff3e0dd ("apparmor: Improve debug print infrastructure")
apparmor: fix AA_DEBUG_LABEL()
AA_DEBUG_LABEL() was not specifying it vargs, which is needed so it can output debug parameters.
Fixes: 71e6cff3e0dd ("apparmor: Improve debug print infrastructure") Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
a30a9fdb | 14-Jun-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: fix af_unix auditing to include all address information
The auditing of addresses currently doesn't include the source address and mixes source and foreign/peer under the same audit name.
apparmor: fix af_unix auditing to include all address information
The auditing of addresses currently doesn't include the source address and mixes source and foreign/peer under the same audit name. Fix this so source is always addr, and the foreign/peer is peer_addr.
Fixes: c05e705812d1 ("apparmor: add fine grained af_unix mediation") Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
6afb0a7b | 22-Jun-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: update kernel doc comments for xxx_label_crit_section
Add a kernel doc header for __end_current_label_crit_section(), and update the header for __begin_current_label_crit_section().
Fixes
apparmor: update kernel doc comments for xxx_label_crit_section
Add a kernel doc header for __end_current_label_crit_section(), and update the header for __begin_current_label_crit_section().
Fixes: b42ecc5f58ef ("apparmor: make __begin_current_label_crit_section() indicate whether put is needed") Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
87cc7b00 | 18-Mar-2025 |
Mateusz Guzik <mjguzik@gmail.com> |
apparmor: make __begin_current_label_crit_section() indicate whether put is needed
Same as aa_get_newest_cred_label_condref().
This avoids a bunch of work overall and allows the compiler to note wh
apparmor: make __begin_current_label_crit_section() indicate whether put is needed
Same as aa_get_newest_cred_label_condref().
This avoids a bunch of work overall and allows the compiler to note when no clean up is necessary, allowing for tail calls.
This in particular happens in apparmor_file_permission(), which manages to tail call aa_file_perm() 105 bytes in (vs a regular call 112 bytes in followed by branches to figure out if clean up is needed).
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
aff426f3 | 24-May-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: mitigate parser generating large xtables
Some versions of the parser are generating an xtable transition per state in the state machine, even when the state machine isn't using the transit
apparmor: mitigate parser generating large xtables
Some versions of the parser are generating an xtable transition per state in the state machine, even when the state machine isn't using the transition table.
The parser bug is triggered by commit 2e12c5f06017 ("apparmor: add additional flags to extended permission.")
In addition to fixing this in userspace, mitigate this in the kernel as part of the policy verification checks by detecting this situation and adjusting to what is actually used, or if not used at all freeing it, so we are not wasting unneeded memory on policy.
Fixes: 2e12c5f06017 ("apparmor: add additional flags to extended permission.") Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
b1f87be7 | 16-Feb-2025 |
John Johansen <john.johansen@canonical.com> |
apparmor: Document that label must be last member in struct aa_profile
The label struct is variable length. While its use in struct aa_profile is fixed length at 2 entries the variable length member
apparmor: Document that label must be last member in struct aa_profile
The label struct is variable length. While its use in struct aa_profile is fixed length at 2 entries the variable length member needs to be the last member in the structure.
The code already does this but the comment has it in the wrong location. Also add a comment to ensure it stays at the end of the structure.
While we are at it, update the documentation for other profile members as well.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
a88db916 | 01-May-2025 |
Ryan Lee <ryan.lee@canonical.com> |
apparmor: fix loop detection used in conflicting attachment resolution
Conflicting attachment resolution is based on the number of states traversed to reach an accepting state in the attachment DFA,
apparmor: fix loop detection used in conflicting attachment resolution
Conflicting attachment resolution is based on the number of states traversed to reach an accepting state in the attachment DFA, accounting for DFA loops traversed during the matching process. However, the loop counting logic had multiple bugs:
- The inc_wb_pos macro increments both position and length, but length is supposed to saturate upon hitting buffer capacity, instead of wrapping around. - If no revisited state is found when traversing the history, is_loop would still return true, as if there was a loop found the length of the history buffer, instead of returning false and signalling that no loop was found. As a result, the adjustment step of aa_dfa_leftmatch would sometimes produce negative counts with loop- free DFAs that traversed enough states. - The iteration in the is_loop for loop is supposed to stop before i = wb->len, so the conditional should be < instead of <=.
This patch fixes the above bugs as well as the following nits: - The count and size fields in struct match_workbuf were not used, so they can be removed. - The history buffer in match_workbuf semantically stores aa_state_t and not unsigned ints, even if aa_state_t is currently unsigned int. - The local variables in is_loop are counters, and thus should be unsigned ints instead of aa_state_t's.
Fixes: 21f606610502 ("apparmor: improve overlapping domain attachment resolution")
Signed-off-by: Ryan Lee <ryan.lee@canonical.com> Co-developed-by: John Johansen <john.johansen@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
6c055e62 | 01-May-2025 |
Ryan Lee <ryan.lee@canonical.com> |
apparmor: ensure WB_HISTORY_SIZE value is a power of 2
WB_HISTORY_SIZE was defined to be a value not a power of 2, despite a comment in the declaration of struct match_workbuf stating it is and a mo
apparmor: ensure WB_HISTORY_SIZE value is a power of 2
WB_HISTORY_SIZE was defined to be a value not a power of 2, despite a comment in the declaration of struct match_workbuf stating it is and a modular arithmetic usage in the inc_wb_pos macro assuming that it is. Bump WB_HISTORY_SIZE's value up to 32 and add a BUILD_BUG_ON_NOT_POWER_OF_2 line to ensure that any future changes to the value of WB_HISTORY_SIZE respect this requirement.
Fixes: 136db994852a ("apparmor: increase left match history buffer size")
Signed-off-by: Ryan Lee <ryan.lee@canonical.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
a949b46e | 03-May-2025 |
Randy Dunlap <rdunlap@infradead.org> |
apparmor: fix some kernel-doc issues in header files
Fix kernel-doc warnings in apparmor header files as reported by scripts/kernel-doc:
cred.h:128: warning: expecting prototype for end_label_crit_
apparmor: fix some kernel-doc issues in header files
Fix kernel-doc warnings in apparmor header files as reported by scripts/kernel-doc:
cred.h:128: warning: expecting prototype for end_label_crit_section(). Prototype was for end_current_label_crit_section() instead file.h:108: warning: expecting prototype for aa_map_file_perms(). Prototype was for aa_map_file_to_perms() instead
lib.h:159: warning: Function parameter or struct member 'hname' not described in 'basename' lib.h:159: warning: Excess function parameter 'name' description in 'basename'
match.h:21: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst * The format used for transition tables is based on the GNU flex table
perms.h:109: warning: Function parameter or struct member 'accum' not described in 'aa_perms_accum_raw' perms.h:109: warning: Function parameter or struct member 'addend' not described in 'aa_perms_accum_raw' perms.h:136: warning: Function parameter or struct member 'accum' not described in 'aa_perms_accum' perms.h:136: warning: Function parameter or struct member 'addend' not described in 'aa_perms_accum'
Signed-off-by: Randy Dunlap <rdunlap@infradead.org> Reviewed-by: Ryan Lee <ryan.lee@canonical.com> Cc: John Johansen <john.johansen@canonical.com> Cc: John Johansen <john@apparmor.net> Cc: apparmor@lists.ubuntu.com Cc: linux-security-module@vger.kernel.org Cc: Paul Moore <paul@paul-moore.com> Cc: James Morris <jmorris@namei.org> Cc: "Serge E. Hallyn" <serge@hallyn.com> Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
dcd7a559 | 12-Oct-2024 |
John Johansen <john.johansen@canonical.com> |
apparmor: gate make fine grained unix mediation behind v9 abi
Fine grained unix mediation in Ubuntu used ABI v7, and policy using this has propogated onto systems where fine grained unix mediation w
apparmor: gate make fine grained unix mediation behind v9 abi
Fine grained unix mediation in Ubuntu used ABI v7, and policy using this has propogated onto systems where fine grained unix mediation was not supported. The userspace policy compiler supports downgrading policy so the policy could be shared without changes.
Unfortunately this had the side effect that policy was not updated for the none Ubuntu systems and enabling fine grained unix mediation on those systems means that a new kernel can break a system with existing policy that worked with the previous kernel. With fine grained af_unix mediation this regression can easily break the system causing boot to fail, as it affect unix socket files, non-file based unix sockets, and dbus communication.
To aoid this regression move fine grained af_unix mediation behind a new abi. This means that the system's userspace and policy must be updated to support the new policy before it takes affect and dropping a new kernel on existing system will not result in a regression.
The abi bump is done in such a way as existing policy can be activated on the system by changing the policy abi declaration and existing unix policy rules will apply. Policy then only needs to be incrementally updated, can even be backported to existing Ubuntu policy.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
c05e7058 | 07-Sep-2022 |
John Johansen <john.johansen@canonical.com> |
apparmor: add fine grained af_unix mediation
Extend af_unix mediation to support fine grained controls based on the type (abstract, anonymous, fs), the address, and the labeling on the socket.
This
apparmor: add fine grained af_unix mediation
Extend af_unix mediation to support fine grained controls based on the type (abstract, anonymous, fs), the address, and the labeling on the socket.
This allows for using socket addresses to label and the socket and control which subjects can communicate.
The unix rule format follows standard apparmor rules except that fs based unix sockets can be mediated by existing file rules. None fs unix sockets can be mediated by a unix socket rule. Where The address of an abstract unix domain socket begins with the @ character, similar to how they are reported (as paths) by netstat -x. The address then follows and may contain pattern matching and any characters including the null character. In apparmor null characters must be specified by using an escape sequence \000 or \x00. The pattern matching is the same as is used by file path matching so * will not match / even though it has no special meaning with in an abstract socket name. Eg.
allow unix addr=@*,
Autobound unix domain sockets have a unix sun_path assigned to them by the kernel, as such specifying a policy based address is not possible. The autobinding of sockets can be controlled by specifying the special auto keyword. Eg.
allow unix addr=auto,
To indicate that the rule only applies to auto binding of unix domain sockets. It is important to note this only applies to the bind permission as once the socket is bound to an address it is indistinguishable from a socket that have an addr bound with a specified name. When the auto keyword is used with other permissions or as part of a peer addr it will be replaced with a pattern that can match an autobound socket. Eg. For some kernels
allow unix rw addr=auto,
It is important to note, this pattern may match abstract sockets that were not autobound but have an addr that fits what is generated by the kernel when autobinding a socket.
Anonymous unix domain sockets have no sun_path associated with the socket address, however it can be specified with the special none keyword to indicate the rule only applies to anonymous unix domain sockets. Eg.
allow unix addr=none,
If the address component of a rule is not specified then the rule applies to autobind, abstract and anonymous sockets.
The label on the socket can be compared using the standard label= rule conditional. Eg.
allow unix addr=@foo peer=(label=bar),
see man apparmor.d for full syntax description.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
b4940d91 | 25-Apr-2024 |
John Johansen <john.johansen@canonical.com> |
apparmor: in preparation for finer networking rules rework match_prot
Rework match_prot into a common fn that can be shared by all the networking rules. This will provide compatibility with current
apparmor: in preparation for finer networking rules rework match_prot
Rework match_prot into a common fn that can be shared by all the networking rules. This will provide compatibility with current socket mediation, via the early bailout permission encoding.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
9045aa25 | 23-Apr-2024 |
John Johansen <john.johansen@canonical.com> |
apparmor: remove af_select macro
The af_select macro just adds a layer of unnecessary abstraction that makes following what the code is doing harder.
Signed-off-by: John Johansen <john.johansen@can
apparmor: remove af_select macro
The af_select macro just adds a layer of unnecessary abstraction that makes following what the code is doing harder.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
ce9e3b3f | 04-Jan-2024 |
John Johansen <john.johansen@canonical.com> |
apparmor: add ability to mediate caps with policy state machine
Currently the caps encoding is very limited and can't be used with conditionals. Allow capabilities to be mediated by the state machin
apparmor: add ability to mediate caps with policy state machine
Currently the caps encoding is very limited and can't be used with conditionals. Allow capabilities to be mediated by the state machine. This will allow us to add conditionals to capabilities that aren't possible with the current encoding.
This patch only adds support for using the state machine and retains the old encoding lookup as part of the runtime mediation code to support older policy abis. A follow on patch will move backwards compatibility to a mapping function done at policy load time.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
2e12c5f0 | 23-Jul-2023 |
John Johansen <john.johansen@canonical.com> |
apparmor: add additional flags to extended permission.
This is a step towards merging the file and policy state machines.
With the switch to extended permissions the state machine's ACCEPT2 table b
apparmor: add additional flags to extended permission.
This is a step towards merging the file and policy state machines.
With the switch to extended permissions the state machine's ACCEPT2 table became unused freeing it up to store state specific flags. The first flags to be stored are FLAG_OWNER and FLAG other which paves the way towards merging the file and policydb perms into a single permission table.
Currently Lookups based on the objects ownership conditional will still need separate fns, this will be address in a following patch.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
de4754c8 | 27-Oct-2023 |
John Johansen <john.johansen@canonical.com> |
apparmor: carry mediation check on label
In order to speed up the mediated check, precompute and store the result as a bit per class type. This will not only allow us to speed up the mediation check
apparmor: carry mediation check on label
In order to speed up the mediated check, precompute and store the result as a bit per class type. This will not only allow us to speed up the mediation check but is also a step to removing the unconfined special cases as the unconfined check can be replaced with the generic label_mediates() check.
Note: label check does not currently work for capabilities and resources which need to have their mediation updated first.
Signed-off-by: John Johansen <john.johansen@canonical.com>
show more ...
|
2d470c77 | 23-Oct-2024 |
Casey Schaufler <casey@schaufler-ca.com> |
lsm: replace context+len with lsm_context
Replace the (secctx,seclen) pointer pair with a single lsm_context pointer to allow return of the LSM identifier along with the context and context length.
lsm: replace context+len with lsm_context
Replace the (secctx,seclen) pointer pair with a single lsm_context pointer to allow return of the LSM identifier along with the context and context length. This allows security_release_secctx() to know how to release the context. Callers have been modified to use or save the returned data from the new structure.
security_secid_to_secctx() and security_lsmproc_to_secctx() will now return the length value on success instead of 0.
Cc: netdev@vger.kernel.org Cc: audit@vger.kernel.org Cc: netfilter-devel@vger.kernel.org Cc: Todd Kjos <tkjos@google.com> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> [PM: subject tweak, kdoc fix, signedness fix from Dan Carpenter] Signed-off-by: Paul Moore <paul@paul-moore.com>
show more ...
|