nfc: enforce CAP_NET_RAW for raw sockets
authorOri Nimron <orinimron123@gmail.com>
Fri, 20 Sep 2019 07:35:49 +0000 (09:35 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 24 Sep 2019 14:37:18 +0000 (16:37 +0200)
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>
net/nfc/llcp_sock.c

index 9b8742947aff12fdb7c2d3358ea11e2d22a20093..8dfea26536c9d42a6bd9f7b64e3001737dbc4d89 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, kern);
        if (sk == NULL)