[PATCH v3 7/7] connector/cn_proc: Allow non-root users access

From: Anjali Kulkarni
Date: Wed Mar 29 2023 - 14:26:37 EST


There were a couple of reasons for not allowing non-root users access
initially - one is there was some point no proper receive buffer
management in place for netlink multicast. But that should be long
fixed. See link below for more context.

Second is that some of the messages may contain data that is root only. But
this should be handled with a finer granularity, which is being done at the
protocol layer. The only problematic protocols are nf_queue and the
firewall netlink. Hence, this restriction for non-root access was relaxed
for NETLINK_ROUTE initially:
https://lore.kernel.org/all/20020612013101.A22399@xxxxxxxxxxxxx/

This restriction has also been removed for following protocols:
NETLINK_KOBJECT_UEVENT, NETLINK_AUDIT, NETLINK_SOCK_DIAG,
NETLINK_GENERIC, NETLINK_SELINUX.

Since process connector messages are not sensitive (process fork, exit
notifications etc.), and anyone can read /proc data, we can allow non-root
access here. However, since process event notification is not the only
consumer of NETLINK_CONNECTOR, we can make this change even more
fine grained than the protocol level, by checking for multicast group
within the protocol.

Set perm_groups for CN_IDX_PROC to 1 indicating it has non-root access.
Reason we need this change is we cannot run our DB application as root.

Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@xxxxxxxxxx>
---
drivers/connector/cn_proc.c | 7 -------
drivers/connector/connector.c | 1 +
2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 35bec1fd7ee0..046a8c1d8577 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -408,12 +408,6 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
!task_is_in_init_pid_ns(current))
return;

- /* Can only change if privileged. */
- if (!__netlink_ns_capable(nsp, &init_user_ns, CAP_NET_ADMIN)) {
- err = EPERM;
- goto out;
- }
-
if (msg->len == sizeof(*pinput)) {
pinput = (struct proc_input *)msg->data;
mc_op = pinput->mcast_op;
@@ -460,7 +454,6 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
break;
}

-out:
cn_proc_ack(err, msg->seq, msg->ack);
}

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index d1179df2b0ba..a9e5ed36732d 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -262,6 +262,7 @@ static int cn_init(void)
.groups = CN_NETLINK_USERS + 0xf,
.input = cn_rx_skb,
.release = cn_release,
+ .perm_groups = 0x1,
};

dev->nls = netlink_kernel_create(&init_net, NETLINK_CONNECTOR, &cfg);
--
2.40.0