mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 19:51:31 -04:00
net: add build-time checks for msg->msg_name size
This is a follow-up patch to f3d3342602 ("net: rework recvmsg
handler msg_name and msg_namelen logic").
DECLARE_SOCKADDR validates that the structure we use for writing the
name information to is not larger than the buffer which is reserved
for msg->msg_name (which is 128 bytes). Also use DECLARE_SOCKADDR
consistently in sendmsg code paths.
Signed-off-by: Steffen Hurrle <[email protected]>
Suggested-by: Hannes Frederic Sowa <[email protected]>
Acked-by: Hannes Frederic Sowa <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
This commit is contained in:
parent
ea02f9411d
commit
342dfc306f
34 changed files with 68 additions and 78 deletions
|
|
@ -86,7 +86,7 @@ static int pn_init(struct sock *sk)
|
|||
static int pn_sendmsg(struct kiocb *iocb, struct sock *sk,
|
||||
struct msghdr *msg, size_t len)
|
||||
{
|
||||
struct sockaddr_pn *target;
|
||||
DECLARE_SOCKADDR(struct sockaddr_pn *, target, msg->msg_name);
|
||||
struct sk_buff *skb;
|
||||
int err;
|
||||
|
||||
|
|
@ -94,13 +94,12 @@ static int pn_sendmsg(struct kiocb *iocb, struct sock *sk,
|
|||
MSG_CMSG_COMPAT))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (msg->msg_name == NULL)
|
||||
if (target == NULL)
|
||||
return -EDESTADDRREQ;
|
||||
|
||||
if (msg->msg_namelen < sizeof(struct sockaddr_pn))
|
||||
return -EINVAL;
|
||||
|
||||
target = (struct sockaddr_pn *)msg->msg_name;
|
||||
if (target->spn_family != AF_PHONET)
|
||||
return -EAFNOSUPPORT;
|
||||
|
||||
|
|
@ -160,6 +159,7 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
|
|||
rval = (flags & MSG_TRUNC) ? skb->len : copylen;
|
||||
|
||||
if (msg->msg_name != NULL) {
|
||||
__sockaddr_check_size(sizeof(sa));
|
||||
memcpy(msg->msg_name, &sa, sizeof(sa));
|
||||
*addr_len = sizeof(sa);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue