All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/tun: fix ioctl() based info leaks
@ 2012-07-29 20:58 Mathias Krause
  2012-07-29 23:11 ` richard -rw- weinberger
  0 siblings, 1 reply; 7+ messages in thread
From: Mathias Krause @ 2012-07-29 20:58 UTC (permalink / raw)
  To: David S. Miller; +Cc: netdev, Mathias Krause

The tun module leaks up to 36 bytes of memory by not initializing a
structure located on the stack that gets copied to user memory by the
TUNGETIFF and SIOCGIFHWADDR ioctl()s.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
 drivers/net/tun.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 987aeef..cadeb94 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1252,9 +1252,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	int vnet_hdr_sz;
 	int ret;
 
-	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
+	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
 		if (copy_from_user(&ifr, argp, ifreq_len))
 			return -EFAULT;
+	} else {
+		memset(&ifr, 0, sizeof(ifr));
+	}
 
 	if (cmd == TUNGETFEATURES) {
 		/* Currently this just means: "what IFF flags are valid?".
-- 
1.7.10.4

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

* Re: [PATCH] net/tun: fix ioctl() based info leaks
  2012-07-29 20:58 [PATCH] net/tun: fix ioctl() based info leaks Mathias Krause
@ 2012-07-29 23:11 ` richard -rw- weinberger
  2012-07-30  5:38   ` Mathias Krause
  2012-07-30  5:45   ` [PATCH v2] " Mathias Krause
  0 siblings, 2 replies; 7+ messages in thread
From: richard -rw- weinberger @ 2012-07-29 23:11 UTC (permalink / raw)
  To: Mathias Krause; +Cc: David S. Miller, netdev

On Sun, Jul 29, 2012 at 10:58 PM, Mathias Krause <minipli@googlemail.com> wrote:
> The tun module leaks up to 36 bytes of memory by not initializing a
> structure located on the stack that gets copied to user memory by the
> TUNGETIFF and SIOCGIFHWADDR ioctl()s.
>
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> ---
>  drivers/net/tun.c |    5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 987aeef..cadeb94 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1252,9 +1252,12 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
>         int vnet_hdr_sz;
>         int ret;
>
> -       if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
> +       if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
>                 if (copy_from_user(&ifr, argp, ifreq_len))
>                         return -EFAULT;
> +       } else {
> +               memset(&ifr, 0, sizeof(ifr));
> +       }
>
>         if (cmd == TUNGETFEATURES) {
>                 /* Currently this just means: "what IFF flags are valid?".

The fix makes sense to me.

Beside of the fix, why are you adding braces to if and else?
We don't use braces on single statements.

-- 
Thanks,
//richard

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

* Re: [PATCH] net/tun: fix ioctl() based info leaks
  2012-07-29 23:11 ` richard -rw- weinberger
@ 2012-07-30  5:38   ` Mathias Krause
  2012-07-30  5:45   ` [PATCH v2] " Mathias Krause
  1 sibling, 0 replies; 7+ messages in thread
From: Mathias Krause @ 2012-07-30  5:38 UTC (permalink / raw)
  To: richard -rw- weinberger; +Cc: David S. Miller, netdev

On Mon, Jul 30, 2012 at 1:11 AM, richard -rw- weinberger
<richard.weinberger@gmail.com> wrote:
> On Sun, Jul 29, 2012 at 10:58 PM, Mathias Krause <minipli@googlemail.com> wrote:
>> -       if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
>> +       if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
>>                 if (copy_from_user(&ifr, argp, ifreq_len))
>>                         return -EFAULT;
>> +       } else {
>> +               memset(&ifr, 0, sizeof(ifr));
>> +       }
>>
>>         if (cmd == TUNGETFEATURES) {
>>                 /* Currently this just means: "what IFF flags are valid?".
>
> The fix makes sense to me.
>
> Beside of the fix, why are you adding braces to if and else?

The pair of braces around the "if" is needed to attach the "else"
branch to the right "if". The braces around the "else" are just for
consistency.

> We don't use braces on single statements.

Even tun.c isn't consistently following this rule but I'll send a new
patch without the "else" braces.


Thanks,
Mathias

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

* [PATCH v2] net/tun: fix ioctl() based info leaks
  2012-07-29 23:11 ` richard -rw- weinberger
  2012-07-30  5:38   ` Mathias Krause
@ 2012-07-30  5:45   ` Mathias Krause
  2012-07-30  6:20     ` David Miller
  2012-07-30  6:22     ` Eric Dumazet
  1 sibling, 2 replies; 7+ messages in thread
From: Mathias Krause @ 2012-07-30  5:45 UTC (permalink / raw)
  To: David S. Miller; +Cc: richard -rw- weinberger, netdev, Mathias Krause

The tun module leaks up to 36 bytes of memory by not fully initializing
a structure located on the stack that gets copied to user memory by the
TUNGETIFF and SIOCGIFHWADDR ioctl()s.

Signed-off-by: Mathias Krause <minipli@googlemail.com>
---
v2:
- removed braces around else branch
- minor adjustment of the commit message

 drivers/net/tun.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 987aeef..01255ff 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1252,9 +1252,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
 	int vnet_hdr_sz;
 	int ret;
 
-	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
+	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
 		if (copy_from_user(&ifr, argp, ifreq_len))
 			return -EFAULT;
+	} else
+		memset(&ifr, 0, sizeof(ifr));
 
 	if (cmd == TUNGETFEATURES) {
 		/* Currently this just means: "what IFF flags are valid?".
-- 
1.7.10.4

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

* Re: [PATCH v2] net/tun: fix ioctl() based info leaks
  2012-07-30  5:45   ` [PATCH v2] " Mathias Krause
@ 2012-07-30  6:20     ` David Miller
  2012-07-30  6:22     ` Eric Dumazet
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2012-07-30  6:20 UTC (permalink / raw)
  To: minipli; +Cc: richard.weinberger, netdev

From: Mathias Krause <minipli@googlemail.com>
Date: Mon, 30 Jul 2012 07:45:14 +0200

> The tun module leaks up to 36 bytes of memory by not fully initializing
> a structure located on the stack that gets copied to user memory by the
> TUNGETIFF and SIOCGIFHWADDR ioctl()s.
> 
> Signed-off-by: Mathias Krause <minipli@googlemail.com>

Applied and queued up for -stable, thanks.

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

* Re: [PATCH v2] net/tun: fix ioctl() based info leaks
  2012-07-30  5:45   ` [PATCH v2] " Mathias Krause
  2012-07-30  6:20     ` David Miller
@ 2012-07-30  6:22     ` Eric Dumazet
  2012-07-30  6:34       ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2012-07-30  6:22 UTC (permalink / raw)
  To: Mathias Krause; +Cc: David S. Miller, richard -rw- weinberger, netdev

On Mon, 2012-07-30 at 07:45 +0200, Mathias Krause wrote:
> The tun module leaks up to 36 bytes of memory by not fully initializing
> a structure located on the stack that gets copied to user memory by the
> TUNGETIFF and SIOCGIFHWADDR ioctl()s.
> 
> Signed-off-by: Mathias Krause <minipli@googlemail.com>
> ---
> v2:
> - removed braces around else branch
> - minor adjustment of the commit message
> 
>  drivers/net/tun.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index 987aeef..01255ff 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1252,9 +1252,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
>  	int vnet_hdr_sz;
>  	int ret;
>  
> -	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
> +	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
>  		if (copy_from_user(&ifr, argp, ifreq_len))
>  			return -EFAULT;
> +	} else
> +		memset(&ifr, 0, sizeof(ifr));
>  
>  	if (cmd == TUNGETFEATURES) {
>  		/* Currently this just means: "what IFF flags are valid?".


Actually braces were better

vi +169 Documentation/CodingStyle

This does not apply if only one branch of a conditional statement is a
single
statement; in the latter case use braces in both branches:

if (condition) {
        do_this();
        do_that();
} else {
        otherwise();
}

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

* Re: [PATCH v2] net/tun: fix ioctl() based info leaks
  2012-07-30  6:22     ` Eric Dumazet
@ 2012-07-30  6:34       ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2012-07-30  6:34 UTC (permalink / raw)
  To: eric.dumazet; +Cc: minipli, richard.weinberger, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Mon, 30 Jul 2012 08:22:20 +0200

> On Mon, 2012-07-30 at 07:45 +0200, Mathias Krause wrote:
>> The tun module leaks up to 36 bytes of memory by not fully initializing
>> a structure located on the stack that gets copied to user memory by the
>> TUNGETIFF and SIOCGIFHWADDR ioctl()s.
>> 
>> Signed-off-by: Mathias Krause <minipli@googlemail.com>
>> ---
>> v2:
>> - removed braces around else branch
>> - minor adjustment of the commit message
>> 
>>  drivers/net/tun.c |    4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
>> index 987aeef..01255ff 100644
>> --- a/drivers/net/tun.c
>> +++ b/drivers/net/tun.c
>> @@ -1252,9 +1252,11 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
>>  	int vnet_hdr_sz;
>>  	int ret;
>>  
>> -	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89)
>> +	if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
>>  		if (copy_from_user(&ifr, argp, ifreq_len))
>>  			return -EFAULT;
>> +	} else
>> +		memset(&ifr, 0, sizeof(ifr));
>>  
>>  	if (cmd == TUNGETFEATURES) {
>>  		/* Currently this just means: "what IFF flags are valid?".
> 
> 
> Actually braces were better
> 
> vi +169 Documentation/CodingStyle
> 
> This does not apply if only one branch of a conditional statement is a
> single
> statement; in the latter case use braces in both branches:
> 
> if (condition) {
>         do_this();
>         do_that();
> } else {
>         otherwise();
> }

Ok I'll fix this up myself.

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

end of thread, other threads:[~2012-07-30  6:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-29 20:58 [PATCH] net/tun: fix ioctl() based info leaks Mathias Krause
2012-07-29 23:11 ` richard -rw- weinberger
2012-07-30  5:38   ` Mathias Krause
2012-07-30  5:45   ` [PATCH v2] " Mathias Krause
2012-07-30  6:20     ` David Miller
2012-07-30  6:22     ` Eric Dumazet
2012-07-30  6:34       ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.