Skip to content

Commit

Permalink
net: compat: Update get_compat_msghdr() to match copy_msghdr_from_use…
Browse files Browse the repository at this point in the history
…r() behaviour

Commit db31c55 (net: clamp ->msg_namelen instead of returning an
error) introduced the clamping of msg_namelen when the unsigned value
was larger than sizeof(struct sockaddr_storage). This caused a
msg_namelen of -1 to be valid. The native code was subsequently fixed by
commit dbb490b (net: socket: error on a negative msg_namelen).

In addition, the native code sets msg_namelen to 0 when msg_name is
NULL. This was done in commit (6a2a2b3 net:socket: set msg_namelen
to 0 if msg_name is passed as NULL in msghdr struct from userland) and
subsequently updated by 08adb7d (fold verify_iovec() into
copy_msghdr_from_user()).

This patch brings the get_compat_msghdr() in line with
copy_msghdr_from_user().

Fixes: db31c55 (net: clamp ->msg_namelen instead of returning an error)
Cc: David S. Miller <[email protected]>
Cc: Dan Carpenter <[email protected]>
Signed-off-by: Catalin Marinas <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ctmarinas authored and davem330 committed Mar 20, 2015
1 parent de58a6d commit 91edd09
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions net/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ ssize_t get_compat_msghdr(struct msghdr *kmsg,
__get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
__get_user(kmsg->msg_flags, &umsg->msg_flags))
return -EFAULT;

if (!uaddr)
kmsg->msg_namelen = 0;

if (kmsg->msg_namelen < 0)
return -EINVAL;

if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
kmsg->msg_namelen = sizeof(struct sockaddr_storage);
kmsg->msg_control = compat_ptr(tmp3);
Expand Down

0 comments on commit 91edd09

Please sign in to comment.