diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-10-21 05:47:43 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-10-22 10:18:28 -0400 |
commit | 47191d65b647af5eb5c82ede70ed4c24b1e93ef4 (patch) | |
tree | 864eabcb29d69af1397290e7ffa926207eee01ff | |
parent | 34e45ad9378c31ef2b59e8bd63d62f0ca8e719a3 (diff) |
netlink: fix locking around NETLINK_LIST_MEMBERSHIPS
Currently, NETLINK_LIST_MEMBERSHIPS grabs the netlink table while copying
the membership state to user-space. However, grabing the netlink table is
effectively a write_lock_irq(), and as such we should not be triggering
page-faults in the critical section.
This can be easily reproduced by the following snippet:
int s = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
void *p = mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
int r = getsockopt(s, 0x10e, 9, p, (void*)((char*)p + 4092));
This should work just fine, but currently triggers EFAULT and a possible
WARN_ON below handle_mm_fault().
Fix this by reducing locking of NETLINK_LIST_MEMBERSHIPS to a read-side
lock. The write-lock was overkill in the first place, and the read-lock
allows page-faults just fine.
Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/netlink/af_netlink.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index 0a49a8c7c564..fafe33bdb619 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -2371,7 +2371,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, | |||
2371 | int pos, idx, shift; | 2371 | int pos, idx, shift; |
2372 | 2372 | ||
2373 | err = 0; | 2373 | err = 0; |
2374 | netlink_table_grab(); | 2374 | netlink_lock_table(); |
2375 | for (pos = 0; pos * 8 < nlk->ngroups; pos += sizeof(u32)) { | 2375 | for (pos = 0; pos * 8 < nlk->ngroups; pos += sizeof(u32)) { |
2376 | if (len - pos < sizeof(u32)) | 2376 | if (len - pos < sizeof(u32)) |
2377 | break; | 2377 | break; |
@@ -2386,7 +2386,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, | |||
2386 | } | 2386 | } |
2387 | if (put_user(ALIGN(nlk->ngroups / 8, sizeof(u32)), optlen)) | 2387 | if (put_user(ALIGN(nlk->ngroups / 8, sizeof(u32)), optlen)) |
2388 | err = -EFAULT; | 2388 | err = -EFAULT; |
2389 | netlink_table_ungrab(); | 2389 | netlink_unlock_table(); |
2390 | break; | 2390 | break; |
2391 | } | 2391 | } |
2392 | case NETLINK_CAP_ACK: | 2392 | case NETLINK_CAP_ACK: |