]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: allow SO_MARK with CAP_NET_RAW via cmsg
authorJakub Kicinski <kuba@kernel.org>
Mon, 31 Jan 2022 23:33:57 +0000 (15:33 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 2 Feb 2022 03:59:50 +0000 (19:59 -0800)
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.

Reviewed-by: Maciej Żenczykowski <maze@google.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20220131233357.52964-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/sock.c

index d6804685f17f0674b450f4368fbfaedd98fae7c9..09d31a7dc68f88af42f75f3f445818fe273b04fb 100644 (file)
@@ -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;