Commit graph

23 commits

Author SHA1 Message Date
Georgia Garcia
f9621054d7 parser: add port range support on network policy
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-09-05 17:01:46 -03:00
John Johansen
2737cb2c2b parser: minimization - remove unnecessary second minimization pass
Moving apply_and_clear_deny() before the first minimization pass, which
was necessary to propperly support building accept information for
older none extended permission dfas, allows us to also get rid of doing a
second minimization pass if we want to force clearing explicit deny
info from extended permission tables.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-14 17:15:24 -07:00
John Johansen
5c2bd20720 parser: pass rule mode prompt through to backend
Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-14 15:47:13 -07:00
John Johansen
2e18cb9aed parser: rename rules.h perms_t to perm32_t
There are two distinct declarations of perms_t.
  rule.h: typedef uint32_t perms_t
  hfa.h: class perms_t

these definitions clash when the front end and backend share more info.
To avoid this rename rule.h to perm32_t, and move the definition into
perms.h and use it in struct aa_perms.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-08-14 14:39:18 -07:00
John Johansen
ab9e6311f3 Merge parser: add network inet mediation documentation to apparmor.d
This updates the man page for the recent inet mediation patch.

This is an extension of MR 1202, it adds a patch that changes the anonymous ip address anon to be ip address none which is a better fit.

This patch adds documentation of the recent network changes which extended all network rules to support access permissions, and added address and port matching for inet and inet6 families.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1213
Approved-by: John Johansen <john@jjmx.net>
Merged-by: John Johansen <john@jjmx.net>
2024-04-12 03:46:23 +00:00
John Johansen
689df6d3cd switch inet mediation from using anon to none
inet mediation allows specifying rules for sockets that don't have
a known address, whether because it is unbound or because the
kernel doesn't make the address available.

The current code uses the word anon for anonymous, but that has
proven to be unclear. Switch from using anon to none, to emphasize
that this is a case where there just isn't an address to use as
part of mediation.

Signed-off-by: John Johansen <john.johansen@canonical.com>
2024-04-11 19:03:43 -07:00
Georgia Garcia
c1ca0286e8 parser: inet conditionals should only generate rules for inet family
When a family is specified in the network rules, we have to make sure
the conditionals match the family. A netlink rule should not be able
to specify ip and port for local and remote (peer) sockets, for example.

When type or protocol is specified in network rules along with inet
conditionals, we should only generate rules for the families that
support those conditionals.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-04-10 16:46:08 -03:00
Georgia Garcia
f9527d2113 parser: fix issues appointed by coverity
Fix issues introduced in coverity's snapshots 75887, 70858 and 75429.
- CID 353483: Uninitialized pointer field (UNINIT_CTOR)
- CID 349572: Unsigned compared against 0 (NO_EFFECT)

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-18 10:36:56 -03:00
Georgia Garcia
efc2ec5fdd parser: fix cmp function for network rules
The network cmp function was missing the new attributes added, causing
rules to be dropped.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 16:38:10 -03:00
Georgia Garcia
b01b9895e7 parser: add ability to specify anonymous ip
If anonymous ip is specified, then the port will match anything.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 16:38:10 -03:00
Georgia Garcia
a0a0c88d9e parser: generate all ip options when ip is not specified
When the ip is not specified, then we should generate rules for ip
types: anonymous, ipv4 and ipv6. And that's the case for both local
and peer when considering recv and send permissions.

std::ostringstream does not have a copy constructor, that's why in
several places one can see streaming the string of one stream into
another.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
63676459c4 parser: encode create permission separately from the others
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
9ed04cb01e parser: introduce network label attribute
We want to be able to determine label in the future and build the
policy dfa based on its presence or not.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
2a885872a3 parser: ip size encoding should be an enum, not the ip size
According to the protocol expected by the kernel, the field
representing the ip size should be an enum instead of the actual ip
size. This is more future-proof.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
989501428e parser: initial steps into encoding protocol properly
Before the inet patches, protocol was not handled, so the information
was ignored. This patch introduces the ability to start mediating
protocol.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-15 10:33:33 -03:00
Georgia Garcia
2db41acd1b parser: fix generic perms in network rules
The permission for network rules when the inet mediation was not
available, or for when the family was not af_inet or af_inet6 was
being generated as one that would allow anything. Make them specific
using perms.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:33:54 -03:00
Georgia Garcia
a10d9044b8 parser: fix policy generation for non-af_inet rules
The layout for AF_INET and AF_INET6 rules were being applied to all
families, which causes failures in their mediation.

Fixes: ddefe11a ("parser: add fine grained conditionals to network rule")
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-03-06 10:07:17 -03:00
Georgia Garcia
119e3f38f9 parser: maintain compatibility for fine grained inet network mediation
A simple rule without conditionals need to be generated for when the
kernel does not support fine grained inet network mediation.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 18:27:20 -03:00
Georgia Garcia
ddefe11a40 parser: add fine grained conditionals to network rule
Options available are ip= and port= inside the peer group or outside,
representing local addresses and ports:

network peer=(ip=127.0.0.1 port=8080),
network ip=::1 port=8080 peer=(ip=::2 port=8081),

The 'ip' option supports both IPv4 and IPv6. Examples would be
ip=192.168.0.4, or ip=::578d

The 'port' option accepts a 16-bit unsigned integer. An example would
be port=1234

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-29 16:25:59 -03:00
Georgia Garcia
746f76d3e1 parser: add ability to specify permission in network rules
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2024-02-28 21:42:18 -03:00
Georgia Garcia
2be9c431ca parser: add opt_cond in preparation to finer grained network mediation
Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:15 -07:00
Georgia Garcia
05de4b82e7 parser: implement dedup of network rules
Since network rules don't use the "perms" attribute, it is using the
dedup class in which duplicate rules are removed.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:13:04 -07:00
Georgia Garcia
820f1fb5f2 parser: refactor network to use rule class as its base.
There is one significant difference in the encoding of the network
rules. Before this change, when the parser was encoding a "network,"
rule, it would generate an entry for every family and every
type/protocol. After this patch the parser should generate an entry
for every family, but the type/protocol is changed to .. in the pcre
syntax. There should be no difference in behavior.

Signed-off-by: Georgia Garcia <georgia.garcia@canonical.com>
2023-09-07 00:12:51 -07:00
Renamed from parser/network.c (Browse further)