History

bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys

Currently, it is possible to create a sock hash map with key size of 0 and have the kernel return a fd back to user space. This is invalid for hash maps (and kernel also hasn't been tested for zero key size support in general at this point). Thus, reject such configuration.

Daniel Borkmann committed 8 years ago

Commit b845c891 parent 96c26e01 file · +3 −1Browse files

Unified · Split

kernel/bpf/sockmap.c+3−1
@@ -2140,7 +2140,9 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) · 2139 unmodified lines
2140 return ERR_PTR(-EPERM);2140 return ERR_PTR(-EPERM);
2141 2141
2142 /* check sanity of attributes */2142 /* check sanity of attributes */
2143 if (attr->max_entries == 0 || attr->value_size != 4 ||2143 if (attr->max_entries == 0 ||
2144 attr->key_size == 0 ||
2145 attr->value_size != 4 ||
2144 attr->map_flags & ~SOCK_CREATE_FLAG_MASK)2146 attr->map_flags & ~SOCK_CREATE_FLAG_MASK)
2145 return ERR_PTR(-EINVAL);2147 return ERR_PTR(-EINVAL);
2146 2148

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t