public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [BUG] acess_ok() missing from zerocopy_sg_from_iovec()
@ 2013-06-04  0:34 Eric Dumazet
  2013-06-04  1:06 ` Eric Dumazet
  2013-06-04  5:30 ` Michael S. Tsirkin
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2013-06-04  0:34 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev

It looks like access_ok(VERIFY_READ, base, len) checks are missing in
drivers/net/tun.c & drivers/net/macvtap.c before the
get_user_pages_fast() calls.

Or am I missing something ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG] acess_ok() missing from zerocopy_sg_from_iovec()
  2013-06-04  0:34 [BUG] acess_ok() missing from zerocopy_sg_from_iovec() Eric Dumazet
@ 2013-06-04  1:06 ` Eric Dumazet
  2013-06-04  3:25   ` Jason Wang
  2013-06-04  5:32   ` Michael S. Tsirkin
  2013-06-04  5:30 ` Michael S. Tsirkin
  1 sibling, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2013-06-04  1:06 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: netdev

On Mon, 2013-06-03 at 17:34 -0700, Eric Dumazet wrote:
> It looks like access_ok(VERIFY_READ, base, len) checks are missing in
> drivers/net/tun.c & drivers/net/macvtap.c before the
> get_user_pages_fast() calls.
> 
> Or am I missing something ?
> 

Patch would be :

[PATCH] tun/macvtap: use access_ok(VERIFY_READ)

Zero copy is good if only we make all needed security checks.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---

diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 59e9605..d793b7d 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -522,6 +522,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
 		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
 		if (i + size > MAX_SKB_FRAGS)
 			return -EMSGSIZE;
+		if (!access_ok(VERIFY_READ, base, len))
+			return -EFAULT;
 		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
 		if (num_pages != size) {
 			for (i = 0; i < num_pages; i++)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 89776c5..7a7b3b1 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1008,6 +1008,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
 		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
 		if (i + size > MAX_SKB_FRAGS)
 			return -EMSGSIZE;
+		if (!access_ok(VERIFY_READ, base, len))
+			return -EFAULT;
 		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
 		if (num_pages != size) {
 			for (i = 0; i < num_pages; i++)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [BUG] acess_ok() missing from zerocopy_sg_from_iovec()
  2013-06-04  1:06 ` Eric Dumazet
@ 2013-06-04  3:25   ` Jason Wang
  2013-06-04  5:32   ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Jason Wang @ 2013-06-04  3:25 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Michael S. Tsirkin, netdev

On 06/04/2013 09:06 AM, Eric Dumazet wrote:
> On Mon, 2013-06-03 at 17:34 -0700, Eric Dumazet wrote:
>> It looks like access_ok(VERIFY_READ, base, len) checks are missing in
>> drivers/net/tun.c & drivers/net/macvtap.c before the
>> get_user_pages_fast() calls.
>>
>> Or am I missing something ?
>>
> Patch would be :
>
> [PATCH] tun/macvtap: use access_ok(VERIFY_READ)
>
> Zero copy is good if only we make all needed security checks.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> ---
>
> diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
> index 59e9605..d793b7d 100644
> --- a/drivers/net/macvtap.c
> +++ b/drivers/net/macvtap.c
> @@ -522,6 +522,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
>  		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
>  		if (i + size > MAX_SKB_FRAGS)
>  			return -EMSGSIZE;
> +		if (!access_ok(VERIFY_READ, base, len))
> +			return -EFAULT;
>  		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
>  		if (num_pages != size) {
>  			for (i = 0; i < num_pages; i++)
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 89776c5..7a7b3b1 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1008,6 +1008,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
>  		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
>  		if (i + size > MAX_SKB_FRAGS)
>  			return -EMSGSIZE;
> +		if (!access_ok(VERIFY_READ, base, len))
> +			return -EFAULT;
>  		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
>  		if (num_pages != size) {
>  			for (i = 0; i < num_pages; i++)
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Looks like vhost is the only user of zerocopy now, and it does this
check when virtqueue is initialized in vq_memory_access_ok().

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG] acess_ok() missing from zerocopy_sg_from_iovec()
  2013-06-04  0:34 [BUG] acess_ok() missing from zerocopy_sg_from_iovec() Eric Dumazet
  2013-06-04  1:06 ` Eric Dumazet
@ 2013-06-04  5:30 ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2013-06-04  5:30 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev

On Mon, Jun 03, 2013 at 05:34:12PM -0700, Eric Dumazet wrote:
> It looks like access_ok(VERIFY_READ, base, len) checks are missing in
> drivers/net/tun.c & drivers/net/macvtap.c before the
> get_user_pages_fast() calls.
> 
> Or am I missing something ?

These paths (zero-copy xmit) are only used through vhost-net which does
its own access_ok checks.

Needs a comment, I agree.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUG] acess_ok() missing from zerocopy_sg_from_iovec()
  2013-06-04  1:06 ` Eric Dumazet
  2013-06-04  3:25   ` Jason Wang
@ 2013-06-04  5:32   ` Michael S. Tsirkin
  1 sibling, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2013-06-04  5:32 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: netdev

On Mon, Jun 03, 2013 at 06:06:09PM -0700, Eric Dumazet wrote:
> On Mon, 2013-06-03 at 17:34 -0700, Eric Dumazet wrote:
> > It looks like access_ok(VERIFY_READ, base, len) checks are missing in
> > drivers/net/tun.c & drivers/net/macvtap.c before the
> > get_user_pages_fast() calls.
> > 
> > Or am I missing something ?
> > 
> 
> Patch would be :
> 
> [PATCH] tun/macvtap: use access_ok(VERIFY_READ)
> 
> Zero copy is good if only we make all needed security checks.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

This is only called if msg_control is set, and the
assumption is that callers of tun_sendmsg
are in-kernel callers that have validated the iovec.

> ---
> 
> diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
> index 59e9605..d793b7d 100644
> --- a/drivers/net/macvtap.c
> +++ b/drivers/net/macvtap.c
> @@ -522,6 +522,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
>  		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
>  		if (i + size > MAX_SKB_FRAGS)
>  			return -EMSGSIZE;
> +		if (!access_ok(VERIFY_READ, base, len))
> +			return -EFAULT;
>  		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
>  		if (num_pages != size) {
>  			for (i = 0; i < num_pages; i++)
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 89776c5..7a7b3b1 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1008,6 +1008,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
>  		size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
>  		if (i + size > MAX_SKB_FRAGS)
>  			return -EMSGSIZE;
> +		if (!access_ok(VERIFY_READ, base, len))
> +			return -EFAULT;
>  		num_pages = get_user_pages_fast(base, size, 0, &page[i]);
>  		if (num_pages != size) {
>  			for (i = 0; i < num_pages; i++)
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-04  5:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-04  0:34 [BUG] acess_ok() missing from zerocopy_sg_from_iovec() Eric Dumazet
2013-06-04  1:06 ` Eric Dumazet
2013-06-04  3:25   ` Jason Wang
2013-06-04  5:32   ` Michael S. Tsirkin
2013-06-04  5:30 ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox