All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
To: davem@davemloft.net
Cc: edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	zbr@ioremap.net, brauner@kernel.org, johannes@sipsolutions.net,
	ecree.xilinx@gmail.com, leon@kernel.org, keescook@chromium.org,
	socketcan@hartkopp.net, petrm@nvidia.com,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	anjali.k.kulkarni@oracle.com
Subject: [PATCH v4 6/6] connector/cn_proc: Allow non-root users access
Date: Fri, 31 Mar 2023 16:55:28 -0700	[thread overview]
Message-ID: <20230331235528.1106675-7-anjali.k.kulkarni@oracle.com> (raw)
In-Reply-To: <20230331235528.1106675-1-anjali.k.kulkarni@oracle.com>

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@wotan.suse.de/

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.

Allow non-root access for NETLINK_CONNECTOR via NL_CFG_F_NONROOT_RECV
but add new bind function cn_bind(), which allows non-root access only
for CN_IDX_PROC multicast group.

Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
---
 drivers/connector/cn_proc.c   |  7 -------
 drivers/connector/connector.c | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 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..193d3056de64 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -166,6 +166,18 @@ static int cn_call_callback(struct sk_buff *skb)
 	return err;
 }
 
+static int cn_bind(struct net *net, int group)
+{
+	unsigned long groups = 0;
+	groups = (unsigned long) group;
+
+	if (ns_capable(net->user_ns, CAP_NET_ADMIN))
+		return 0;
+	if (test_bit(CN_IDX_PROC - 1, &groups))
+		return 0;
+	return -EPERM;
+}
+
 static void cn_release(struct sock *sk, unsigned long *groups)
 {
 	if (groups && test_bit(CN_IDX_PROC - 1, groups)) {
@@ -261,6 +273,8 @@ static int cn_init(void)
 	struct netlink_kernel_cfg cfg = {
 		.groups	= CN_NETLINK_USERS + 0xf,
 		.input	= cn_rx_skb,
+		.flags  = NL_CFG_F_NONROOT_RECV,
+		.bind   = cn_bind,
 		.release = cn_release,
 	};
 
-- 
2.40.0


      parent reply	other threads:[~2023-03-31 23:56 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 23:55 [PATCH v4 0/6] Process connector bug fixes & enhancements Anjali Kulkarni
2023-03-31 23:55 ` [PATCH v4 1/6] netlink: Reverse the patch which removed filtering Anjali Kulkarni
2023-04-01  4:08   ` Jakub Kicinski
2023-04-01  4:09   ` Jakub Kicinski
2023-04-01 18:24     ` Anjali Kulkarni
2023-04-01 19:12       ` Jakub Kicinski
2023-04-01 19:58         ` Anjali Kulkarni
2023-04-03 20:47           ` Jakub Kicinski
2023-04-02  2:32         ` Anjali Kulkarni
2023-04-03 20:50           ` Jakub Kicinski
2023-04-04 18:06             ` Anjali Kulkarni
2023-04-26 23:58             ` Anjali Kulkarni
2023-04-27 17:03               ` Jakub Kicinski
2023-05-11 16:04                 ` Anjali Kulkarni
2023-06-01 16:15                   ` Anjali Kulkarni
2023-06-01 16:24                     ` Jakub Kicinski
2023-06-01 16:34                       ` Anjali Kulkarni
2023-06-01 16:43                         ` Jakub Kicinski
2023-06-01 16:49                           ` Anjali Kulkarni
2023-03-31 23:55 ` [PATCH v4 2/6] netlink: Add new netlink_release function Anjali Kulkarni
2023-04-01  4:08   ` Jakub Kicinski
2023-03-31 23:55 ` [PATCH v4 3/6] connector/cn_proc: Add filtering to fix some bugs Anjali Kulkarni
2023-03-31 23:55 ` [PATCH v4 4/6] connector/cn_proc: Test code for proc connector Anjali Kulkarni
2023-03-31 23:55 ` [PATCH v4 5/6] connector/cn_proc: Performance improvements Anjali Kulkarni
2023-06-01 16:25   ` Jakub Kicinski
2023-06-01 16:38     ` Anjali Kulkarni
2023-06-01 16:48       ` Jakub Kicinski
2023-06-01 16:53         ` Anjali Kulkarni
2023-06-01 17:15           ` Jakub Kicinski
2023-06-02 22:23             ` Anjali Kulkarni
2023-06-02 23:02               ` Jakub Kicinski
2023-03-31 23:55 ` Anjali Kulkarni [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230331235528.1106675-7-anjali.k.kulkarni@oracle.com \
    --to=anjali.k.kulkarni@oracle.com \
    --cc=brauner@kernel.org \
    --cc=davem@davemloft.net \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=socketcan@hartkopp.net \
    --cc=zbr@ioremap.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.