net: qrtr: Add permission rules for QTI targets

Give control port access to processes that have root user priveleges,
AID_VENDOR_QRTR user priveleges, or NET_ADMIN capabilities.

Remove the need for SYS_ADMIN priveleges because they will not be
granted on any QTI targets.

This change squashes the following commits from msm-4.14:
  commit 17da4da93c96 ("qrtr: Allow net bind service capabilities")
  commit 56faadfd27b4 ("qrtr: Fix NET_BIND_SERVICE logic")
  commit 82ea58d60c46 ("net: qrtr: Allow control port access to
                        AID_VENDOR_QRTR")
  commit 9db4f5803ce1 ("net: qrtr: Allow Root guid process to bind")

In addition fix minor format issues.

Change-Id: I1441cbf53eb62880333a1031334a5331c1f54a77
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
This commit is contained in:
Chris Lew 2022-10-11 13:32:18 -07:00
parent bf77ef2d63
commit 904b1aa353

View File

@ -11,6 +11,7 @@
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/rwsem.h>
#include <linux/uidgid.h>
#include <net/sock.h>
@ -31,6 +32,8 @@
#define QRTR_STATE_MULTI -2
#define QRTR_STATE_INIT -1
#define AID_VENDOR_QRTR KGIDT_INIT(2906)
/**
* struct qrtr_hdr_v1 - (I|R)PCrouter packet header version 1
* @version: protocol version
@ -864,7 +867,10 @@ static int qrtr_port_assign(struct qrtr_sock *ipc, int *port)
rc = xa_alloc_cyclic(&qrtr_ports, port, ipc,
QRTR_EPH_PORT_RANGE, &qrtr_ports_next,
GFP_KERNEL);
} else if (*port < QRTR_MIN_EPH_SOCKET && !capable(CAP_NET_ADMIN)) {
} else if (*port < QRTR_MIN_EPH_SOCKET &&
!(capable(CAP_NET_ADMIN) ||
in_egroup_p(AID_VENDOR_QRTR) ||
in_egroup_p(GLOBAL_ROOT_GID))) {
rc = -EACCES;
} else if (*port == QRTR_PORT_CTRL) {
rc = xa_insert(&qrtr_ports, 0, ipc, GFP_KERNEL);