Skip to content

Commit

Permalink
tipc: don't use memcpy to copy from user space
Browse files Browse the repository at this point in the history
tipc_msg_build() calls skb_copy_to_linear_data_offset() to copy data
from user space to kernel space. However, the latter function does
in its turn call memcpy() to perform the actual copying. This poses
an obvious security and robustness risk, since memcpy() never makes
any validity check on the pointer it is copying from.

To correct this, we the replace the offending function call with
a call to memcpy_fromiovecend(), which uses copy_from_user() to
perform the copying.

Signed-off-by: Ying Xue <[email protected]>
Reviewed-by: Paul Gortmaker <[email protected]>
Signed-off-by: Jon Maloy <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ying-xue authored and davem330 committed Oct 18, 2013
1 parent 7cc7c5e commit 5c0a0fc
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions net/tipc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
u32 num_sect, unsigned int total_len, int max_size,
struct sk_buff **buf)
{
int dsz, sz, hsz, pos, res, cnt;
int dsz, sz, hsz;
unsigned char *to;

dsz = total_len;
pos = hsz = msg_hdr_sz(hdr);
hsz = msg_hdr_sz(hdr);
sz = hsz + dsz;
msg_set_size(hdr, sz);
if (unlikely(sz > max_size)) {
Expand All @@ -91,16 +92,11 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
if (!(*buf))
return -ENOMEM;
skb_copy_to_linear_data(*buf, hdr, hsz);
for (res = 1, cnt = 0; res && (cnt < num_sect); cnt++) {
skb_copy_to_linear_data_offset(*buf, pos,
msg_sect[cnt].iov_base,
msg_sect[cnt].iov_len);
pos += msg_sect[cnt].iov_len;
to = (*buf)->data + hsz;
if (total_len && memcpy_fromiovecend(to, msg_sect, 0, dsz)) {
kfree_skb(*buf);
*buf = NULL;
return -EFAULT;
}
if (likely(res))
return dsz;

kfree_skb(*buf);
*buf = NULL;
return -EFAULT;
return dsz;
}

0 comments on commit 5c0a0fc

Please sign in to comment.