linux/security/selinux
Thiébaud Weksteen d1d991efaf selinux: Add netlink xperm support
Reuse the existing extended permissions infrastructure to support
policies based on the netlink message types.

A new policy capability "netlink_xperm" is introduced. When disabled,
the previous behaviour is preserved. That is, netlink_send will rely on
the permission mappings defined in nlmsgtab.c (e.g, nlmsg_read for
RTM_GETADDR on NETLINK_ROUTE). When enabled, the mappings are ignored
and the generic "nlmsg" permission is used instead.

The new "nlmsg" permission is an extended permission. The 16 bits of the
extended permission are mapped to the nlmsg_type field.

Example policy on Android, preventing regular apps from accessing the
device's MAC address and ARP table, but allowing this access to
privileged apps, looks as follows:

allow netdomain self:netlink_route_socket {
	create read getattr write setattr lock append connect getopt
	setopt shutdown nlmsg
};
allowxperm netdomain self:netlink_route_socket nlmsg ~{
	RTM_GETLINK RTM_GETNEIGH RTM_GETNEIGHTBL
};
allowxperm priv_app self:netlink_route_socket nlmsg {
	RTM_GETLINK RTM_GETNEIGH RTM_GETNEIGHTBL
};

The constants in the example above (e.g., RTM_GETLINK) are explicitly
defined in the policy.

It is possible to generate policies to support kernels that may or
may not have the capability enabled by generating a rule for each
scenario. For instance:

allow domain self:netlink_audit_socket nlmsg_read;
allow domain self:netlink_audit_socket nlmsg;
allowxperm domain self:netlink_audit_socket nlmsg { AUDIT_GET };

The approach of defining a new permission ("nlmsg") instead of relying
on the existing permissions (e.g., "nlmsg_read", "nlmsg_readpriv" or
"nlmsg_tty_audit") has been preferred because:
  1. This is similar to the other extended permission ("ioctl");
  2. With the new extended permission, the coarse-grained mapping is not
     necessary anymore. It could eventually be removed, which would be
     impossible if the extended permission was defined below these.
  3. Having a single extra extended permission considerably simplifies
     the implementation here and in libselinux.

Signed-off-by: Thiébaud Weksteen <tweek@google.com>
Signed-off-by: Bram Bonné <brambonne@google.com>
[PM: manual merge fixes for sock_skip_has_perm()]
Signed-off-by: Paul Moore <paul@paul-moore.com>
2024-10-07 16:28:11 -04:00
..
include selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
ss selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
.gitignore selinux: move genheaders to security/selinux/ 2024-10-03 16:07:51 -04:00
avc.c selinux/stable-6.12 PR 20240911 2024-09-16 16:55:42 +02:00
genheaders.c selinux: move genheaders to security/selinux/ 2024-10-03 16:07:51 -04:00
hooks.c selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
ibpkey.c selinux: stop passing selinux_state pointers and their offspring 2023-03-14 15:22:45 -04:00
ima.c selinux: adjust typos in comments 2023-05-08 16:44:01 -04:00
Kconfig selinux: improve debug configuration 2023-09-13 13:46:57 -04:00
Makefile selinux: move genheaders to security/selinux/ 2024-10-03 16:07:51 -04:00
netif.c selinux: avoid implicit conversions in the netif code 2023-07-18 18:29:48 -04:00
netlabel.c lsm/stable-6.12 PR 20240911 2024-09-16 18:19:47 +02:00
netlink.c selinux: mark some global variables __ro_after_init 2021-01-12 10:08:55 -05:00
netnode.c selinux: stop passing selinux_state pointers and their offspring 2023-03-14 15:22:45 -04:00
netport.c selinux: stop passing selinux_state pointers and their offspring 2023-03-14 15:22:45 -04:00
nlmsgtab.c selinux: Add netlink xperm support 2024-10-07 16:28:11 -04:00
selinuxfs.c selinux/stable-6.10 PR 20240513 2024-05-15 08:36:30 -07:00
status.c selinux: avoid implicit conversions regarding enforcing status 2023-07-18 18:29:50 -04:00
xfrm.c selinux: make more use of current_sid() 2024-03-27 18:25:18 -04:00