[PATCH] net: allow SO_MARK with CAP_NET_RAW

Subsystems: networking [general], networking [sockets], the rest

STALE1722d LANDED

Landed in mainline as 079925cce1d0 on 2021-11-25.

2 messages, 2 authors, 2021-11-25 · open the first message on its own page

[PATCH] net: allow SO_MARK with CAP_NET_RAW

From: Maciej Żenczykowski <hidden>
Date: 2021-11-23 20:37:21

From: Maciej Żenczykowski <redacted>

A CAP_NET_RAW capable process can already spoof (on transmit) anything
it desires via raw packet sockets...  There is no good reason to not
allow it to also be able to play routing tricks on packets from its
own normal sockets.

There is a desire to be able to use SO_MARK for routing table selection
(via ip rule fwmark) from within a user process without having to run
it as root.  Granting it CAP_NET_RAW is much less dangerous than
CAP_NET_ADMIN (CAP_NET_RAW doesn't permit persistent state change,
while CAP_NET_ADMIN does - by for example allowing the reconfiguration
of the routing tables and/or bringing up/down devices).

Let's keep CAP_NET_ADMIN for persistent state changes,
while using CAP_NET_RAW for non-configuration related stuff.

Signed-off-by: Maciej Żenczykowski <redacted>
---
 net/core/sock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index 1e49a127adef..4a499d255f40 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1281,7 +1281,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
 			clear_bit(SOCK_PASSSEC, &sock->flags);
 		break;
 	case SO_MARK:
-		if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
+		if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) &&
+		    !ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
 			ret = -EPERM;
 			break;
 		}
-- 
2.34.0.rc2.393.gf8c9666880-goog

Re: [PATCH] net: allow SO_MARK with CAP_NET_RAW

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-11-25 03:12:12

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski [off-list ref]:

On Tue, 23 Nov 2021 12:37:15 -0800 you wrote:
From: Maciej Żenczykowski <redacted>

A CAP_NET_RAW capable process can already spoof (on transmit) anything
it desires via raw packet sockets...  There is no good reason to not
allow it to also be able to play routing tricks on packets from its
own normal sockets.

[...]
Here is the summary with links:
  - net: allow SO_MARK with CAP_NET_RAW
    https://git.kernel.org/netdev/net-next/c/079925cce1d0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help