Skip to content

Commit

Permalink
ipv4: Use standard iovec primitive in raw_probe_proto_opt
Browse files Browse the repository at this point in the history
The function raw_probe_proto_opt tries to extract the first two
bytes from the user input in order to seed the IPsec lookup for
ICMP packets.  In doing so it's processing iovec by hand and
overcomplicating things.

This patch replaces the manual iovec processing with a call to
memcpy_fromiovecend.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Herbert Xu authored and David S. Miller committed Nov 10, 2014
1 parent 1ef8019 commit 32b5913
Showing 1 changed file with 11 additions and 39 deletions.
50 changes: 11 additions & 39 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,48 +422,20 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4,

static int raw_probe_proto_opt(struct flowi4 *fl4, struct msghdr *msg)
{
struct iovec *iov;
u8 __user *type = NULL;
u8 __user *code = NULL;
int probed = 0;
unsigned int i;
struct icmphdr icmph;
int err;

if (!msg->msg_iov)
if (fl4->flowi4_proto != IPPROTO_ICMP)
return 0;

for (i = 0; i < msg->msg_iovlen; i++) {
iov = &msg->msg_iov[i];
if (!iov)
continue;

switch (fl4->flowi4_proto) {
case IPPROTO_ICMP:
/* check if one-byte field is readable or not. */
if (iov->iov_base && iov->iov_len < 1)
break;

if (!type) {
type = iov->iov_base;
/* check if code field is readable or not. */
if (iov->iov_len > 1)
code = type + 1;
} else if (!code)
code = iov->iov_base;

if (type && code) {
if (get_user(fl4->fl4_icmp_type, type) ||
get_user(fl4->fl4_icmp_code, code))
return -EFAULT;
probed = 1;
}
break;
default:
probed = 1;
break;
}
if (probed)
break;
}
/* We only need the first two bytes. */
err = memcpy_fromiovecend((void *)&icmph, msg->msg_iov, 0, 2);
if (err)
return err;

fl4->fl4_icmp_type = icmph.type;
fl4->fl4_icmp_code = icmph.code;

return 0;
}

Expand Down

0 comments on commit 32b5913

Please sign in to comment.