Skip to content

Commit 68c6beb

Browse files
strssndktndavem330
authored andcommitted
net: add BUG_ON if kernel advertises msg_namelen > sizeof(struct sockaddr_storage)
In that case it is probable that kernel code overwrote part of the stack. So we should bail out loudly here. The BUG_ON may be removed in future if we are sure all protocols are conformant. Suggested-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f3d3342 commit 68c6beb

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎net/socket.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
221221
int err;
222222
int len;
223223

224+
BUG_ON(klen > sizeof(struct sockaddr_storage));
224225
err = get_user(len, ulen);
225226
if (err)
226227
return err;
227228
if (len > klen)
228229
len = klen;
229-
if (len < 0 || len > sizeof(struct sockaddr_storage))
230+
if (len < 0)
230231
return -EINVAL;
231232
if (len) {
232233
if (audit_sockaddr(klen, kaddr))

0 commit comments

Comments
 (0)