nfc: enforce CAP_NET_RAW for raw sockets
authorOri Nimron <orinimron123@gmail.com>
Fri, 20 Sep 2019 07:35:49 +0000 (09:35 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 15 Nov 2019 00:56:55 +0000 (00:56 +0000)
commit 3a359798b176183ef09efb7a3dc59abad1cc7104 upstream.

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

Signed-off-by: Ori Nimron <orinimron123@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/nfc/llcp_sock.c

index 51f077a92fa9220eb987b7b9185efcc75312328a..3e2982db97e56d24ca2ee68cbfa4211f254c2263 100644 (file)
@@ -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);
        if (sk == NULL)