Re: [PATCH] net/nfc/rawsock.c: add CAP_NET_RAW check.

2020-08-11 Thread David Miller
From: Qingyu Li 
Date: Mon, 10 Aug 2020 09:51:00 +0800

> When creating a raw AF_NFC socket, CAP_NET_RAW needs to be checked first.
> 
> Signed-off-by: Qingyu Li 

Applied and queued up for -stable, thank you.


[PATCH] net/nfc/rawsock.c: add CAP_NET_RAW check.

2020-08-09 Thread Qingyu Li
When creating a raw AF_NFC socket, CAP_NET_RAW needs to be checked first.

Signed-off-by: Qingyu Li 
---
 net/nfc/rawsock.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
index ba5ffd3badd3..b5c867fe3232 100644
--- a/net/nfc/rawsock.c
+++ b/net/nfc/rawsock.c
@@ -332,10 +332,13 @@ static int rawsock_create(struct net *net, struct socket 
*sock,
if ((sock->type != SOCK_SEQPACKET) && (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 = _raw_ops;
-   else
+   } else {
sock->ops = _ops;
+   }
 
sk = sk_alloc(net, PF_NFC, GFP_ATOMIC, nfc_proto->proto, kern);
if (!sk)
-- 
2.17.1