Skip to contentSkip to conversation

Raw socket cleanups

PATCH In review Greg Kroah-Hartman 3 participants 9 messages Sep 20, 2019 – Sep 24, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Raw socket cleanups

Ori Nimron pointed out that there are a number of places in the kernel where you can create a raw socket, without having to have the CAP_NET_RAW permission.

To resolve this, here's a short patch series to test these odd and old protocols for this permission before allowing the creation to succeed

All patches are currently against the net tree.

thanks,

greg k-h

Ori Nimron (5):
mISDN: enforce CAP_NET_RAW for raw sockets
appletalk: enforce CAP_NET_RAW for raw sockets
ax25: enforce CAP_NET_RAW for raw sockets
ieee802154: enforce CAP_NET_RAW for raw sockets
nfc: enforce CAP_NET_RAW for raw sockets

 drivers/isdn/mISDN/socket.c | 2 ++
 net/appletalk/ddp.c         | 5 +++++
 net/ax25/af_ax25.c          | 2 ++
 net/ieee802154/socket.c     | 3 +++
 net/nfc/llcp_sock.c         | 7 +++++--
 5 files changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/5 mISDN: enforce CAP_NET_RAW for raw sockets

From: Ori Nimron <[email protected]>

When creating a raw AF_ISDN socket, CAP_NET_RAW needs to be checked first.

---
 drivers/isdn/mISDN/socket.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/isdn/mISDN/socket.c +2 -0
index c6ba37df4b9d..dff4132b3702 100644
@@ -754,6 +754,8 @@ base_sock_create(struct net *net, struct socket *sock, int protocol, int kern)
 
 	if (sock->type != SOCK_RAW)
 		return -ESOCKTNOSUPPORT;
+	if (!capable(CAP_NET_RAW))
+		return -EPERM;
 
 	sk = sk_alloc(net, PF_ISDN, GFP_KERNEL, &mISDN_proto, kern);
 	if (!sk)
Signature · 1 line
2.23.0
#2 lore raw

PATCH 2/5 appletalk: enforce CAP_NET_RAW for raw sockets

In reply to Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_APPLETALK socket, CAP_NET_RAW needs to be checked first.

---
 net/appletalk/ddp.c | 5 +++++
 1 file changed, 5 insertions(+)
net/appletalk/ddp.c +5 -0
index 4072e9d394d6..b41375d4d295 100644
@@ -1023,6 +1023,11 @@ static int atalk_create(struct net *net, struct socket *sock, int protocol,
 	 */
 	if (sock->type != SOCK_RAW && sock->type != SOCK_DGRAM)
 		goto out;
+
+	rc = -EPERM;
+	if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
+		goto out;
+
 	rc = -ENOMEM;
 	sk = sk_alloc(net, PF_APPLETALK, GFP_KERNEL, &ddp_proto, kern);
 	if (!sk)
Signature · 1 line
2.23.0
#3 lore raw

PATCH 3/5 ax25: enforce CAP_NET_RAW for raw sockets

In reply to Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_AX25 socket, CAP_NET_RAW needs to be checked first.

---
 net/ax25/af_ax25.c | 2 ++
 1 file changed, 2 insertions(+)
net/ax25/af_ax25.c +2 -0
index ca5207767dc2..bb222b882b67 100644
@@ -855,6 +855,8 @@ static int ax25_create(struct net *net, struct socket *sock, int protocol,
 		break;
 
 	case SOCK_RAW:
+		if (!capable(CAP_NET_RAW))
+			return -EPERM;
 		break;
 	default:
 		return -ESOCKTNOSUPPORT;
Signature · 1 line
2.23.0
#4 lore raw

PATCH 4/5 ieee802154: enforce CAP_NET_RAW for raw sockets

In reply to Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_IEEE802154 socket, CAP_NET_RAW needs to be checked first.

---
 net/ieee802154/socket.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/socket.c +3 -0
index badc5cfe4dc6..d93d4531aa9b 100644
@@ -1008,6 +1008,9 @@ static int ieee802154_create(struct net *net, struct socket *sock,
 
 	switch (sock->type) {
 	case SOCK_RAW:
+		rc = -EPERM;
+		if (!capable(CAP_NET_RAW))
+			goto out;
 		proto = &ieee802154_raw_prot;
 		ops = &ieee802154_raw_ops;
 		break;
Signature · 1 line
2.23.0
maintainer Acked-by on v1 4/5
#5 lore raw

Re: [PATCH 4/5] ieee802154: enforce CAP_NET_RAW for raw sockets

Hello.

Quoted 17 lines · Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_IEEE802154 socket, CAP_NET_RAW needs to be checked first.

---
 net/ieee802154/socket.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/socket.c +0 -0
index badc5cfe4dc6..d93d4531aa9b 100644

net/ieee802154/socket.c static int ieee802154_create(struct net *net, struct socket *sock, · line 1016

Quoted 9 lines
net/ieee802154/socket.c +3 -0
@@ -1008,6 +1008,9 @@ static int ieee802154_create(struct net *net, struct socket *sock,
 
 	switch (sock->type) {
 	case SOCK_RAW:
+		rc = -EPERM;
+		if (!capable(CAP_NET_RAW))
+			goto out;
 		proto = &ieee802154_raw_prot;
 		ops = &ieee802154_raw_ops;
 		break;

I assume this will go as a whole series into net. If you want me to pick it up into my tree directly let me know.

regards
Stefan Schmidt

#6 lore raw

Re: [PATCH 4/5] ieee802154: enforce CAP_NET_RAW for raw sockets

Quoted 33 lines · Stefan Schmidt

Hello.

Quoted 17 lines · Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_IEEE802154 socket, CAP_NET_RAW needs to be checked first.

---
 net/ieee802154/socket.c | 3 +++
 1 file changed, 3 insertions(+)
net/ieee802154/socket.c +0 -0
index badc5cfe4dc6..d93d4531aa9b 100644

net/ieee802154/socket.c static int ieee802154_create(struct net *net, struct socket *sock, · line 1016

Quoted 9 lines
net/ieee802154/socket.c +3 -0
@@ -1008,6 +1008,9 @@ static int ieee802154_create(struct net *net, struct socket *sock,
 
 	switch (sock->type) {
 	case SOCK_RAW:
+		rc = -EPERM;
+		if (!capable(CAP_NET_RAW))
+			goto out;
 		proto = &ieee802154_raw_prot;
 		ops = &ieee802154_raw_ops;
 		break;

I assume this will go as a whole series into net. If you want me to pick it up into my tree directly let me know.

Quoted 1 line

That's up to the networking maintainer, if he does not suck it in, I'll resend and ask you to take it.

thanks,

greg k-h

#7 lore raw

PATCH 5/5 nfc: enforce CAP_NET_RAW for raw sockets

In reply to Greg Kroah-Hartman

From: Ori Nimron <[email protected]>

When creating a raw AF_NFC socket, CAP_NET_RAW needs to be checked first.

---
 net/nfc/llcp_sock.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/nfc/llcp_sock.c +5 -2
index 9b8742947aff..8dfea26536c9 100644
@@ -1004,10 +1004,13 @@ static int llcp_sock_create(struct net *net, struct socket *sock,
 	    sock->type != SOCK_RAW)
 		return -ESOCKTNOSUPPORT;
 
-	if (sock->type == SOCK_RAW)
+	if (sock->type == SOCK_RAW) {
+		if (!capable(CAP_NET_RAW))
+			return -EPERM;
 		sock->ops = &llcp_rawsock_ops;
-	else
+	} else {
 		sock->ops = &llcp_sock_ops;
+	}
 
 	sk = nfc_llcp_sock_alloc(sock, sock->type, GFP_ATOMIC, kern);
 	if (sk == NULL)
Signature · 1 line
2.23.0
maintainer
#8 lore raw
In reply to Greg Kroah-Hartman

From: Greg Kroah-Hartman <[email protected]>
Date: Fri, 20 Sep 2019 09:35:44 +0200

Quoted 8 lines

Ori Nimron pointed out that there are a number of places in the kernel where you can create a raw socket, without having to have the CAP_NET_RAW permission.

To resolve this, here's a short patch series to test these odd and old protocols for this permission before allowing the creation to succeed

All patches are currently against the net tree.

Applied and queued up for -stable.