[PATCH] net/tun: fix ioctl() based info leaks

Subsystems: networking drivers, the rest, tun/tap driver

STALE5127d

7 messages, 4 authors, 2012-07-30 · open the first message on its own page

[PATCH] net/tun: fix ioctl() based info leaks

From: Mathias Krause <hidden>
Date: 2012-07-29 20:58:56

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 <redacted>
---
 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

Re: [PATCH] net/tun: fix ioctl() based info leaks

From: richard -rw- weinberger <hidden>
Date: 2012-07-29 23:11:29

On Sun, Jul 29, 2012 at 10:58 PM, Mathias Krause [off-list ref] wrote:
quoted hunk
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 <redacted>
---
 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

Re: [PATCH] net/tun: fix ioctl() based info leaks

From: Mathias Krause <hidden>
Date: 2012-07-30 05:38:38

On Mon, Jul 30, 2012 at 1:11 AM, richard -rw- weinberger
[off-list ref] wrote:
On Sun, Jul 29, 2012 at 10:58 PM, Mathias Krause [off-list ref] wrote:
quoted
-       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

[PATCH v2] net/tun: fix ioctl() based info leaks

From: Mathias Krause <hidden>
Date: 2012-07-30 05:46:02

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 <redacted>
---
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

Re: [PATCH v2] net/tun: fix ioctl() based info leaks

From: David Miller <davem@davemloft.net>
Date: 2012-07-30 06:20:30

From: Mathias Krause <redacted>
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 <redacted>
Applied and queued up for -stable, thanks.

Re: [PATCH v2] net/tun: fix ioctl() based info leaks

From: Eric Dumazet <hidden>
Date: 2012-07-30 06:22:26

On Mon, 2012-07-30 at 07:45 +0200, Mathias Krause wrote:
quoted hunk
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 <redacted>
---
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();
}

Re: [PATCH v2] net/tun: fix ioctl() based info leaks

From: David Miller <davem@davemloft.net>
Date: 2012-07-30 06:34:19

From: Eric Dumazet <redacted>
Date: Mon, 30 Jul 2012 08:22:20 +0200
On Mon, 2012-07-30 at 07:45 +0200, Mathias Krause wrote:
quoted
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 <redacted>
---
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help