Skip to contentSkip to conversation

net: allow SO_MARK with CAP_NET_RAW via cmsg

PATCH Applied Jakub Kicinski 4 participants 4 messages Jan 31, 2022 – Feb 2, 2022

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: allow SO_MARK with CAP_NET_RAW via cmsg

There's not reason SO_MARK would be allowed via setsockopt() and not via cmsg, let's keep the two consistent. See commit 079925cce1d0 ("net: allow SO_MARK with CAP_NET_RAW") for justification why NET_RAW -> SO_MARK is safe.

--
CC: [email protected]

---
 net/core/sock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/sock.c +2 -1
index d6804685f17f..09d31a7dc68f 100644
@@ -2625,7 +2625,8 @@ int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg,
 
 	switch (cmsg->cmsg_type) {
 	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))
 			return -EPERM;
 		if (cmsg->cmsg_len != CMSG_LEN(sizeof(u32)))
 			return -EINVAL;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines · Jakub Kicinski

There's not reason SO_MARK would be allowed via setsockopt() and not via cmsg, let's keep the two consistent. See commit 079925cce1d0 ("net: allow SO_MARK with CAP_NET_RAW") for justification why NET_RAW -> SO_MARK is safe.

--
CC: [email protected]

---
 net/core/sock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/sock.c +2 -2
index d6804685f17f..09d31a7dc68f 100644
@@ -2625,7 +2625,8 @@ int __sock_cmsg_send(struct sock *sk, struct msghdr *msg, struct cmsghdr *cmsg,
 
        switch (cmsg->cmsg_type) {
        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))
                        return -EPERM;
                if (cmsg->cmsg_len != CMSG_LEN(sizeof(u32)))
                        return -EINVAL;
--
Quoted 1 line

2.34.1

I thought I'd sent this out already... interesting must have forgotten.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Jakub Kicinski
Quoted 5 lines · Jakub Kicinski

There's not reason SO_MARK would be allowed via setsockopt() and not via cmsg, let's keep the two consistent. See commit 079925cce1d0 ("net: allow SO_MARK with CAP_NET_RAW") for justification why NET_RAW -> SO_MARK is safe.

Quoted 7 lines

--
CC: [email protected]

---
 net/core/sock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#3 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Mon, 31 Jan 2022 15:33:57 -0800 you wrote:

There's not reason SO_MARK would be allowed via setsockopt() and not via cmsg, let's keep the two consistent. See commit 079925cce1d0 ("net: allow SO_MARK with CAP_NET_RAW") for justification why NET_RAW -> SO_MARK is safe.

--
CC: [email protected]

[...]

Here is the summary with links:
- [net-next] net: allow SO_MARK with CAP_NET_RAW via cmsg

    https://git.kernel.org/netdev/net-next/c/91f0d8a4813a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html