Message ID | 1343595494-10414-1-git-send-email-minipli@googlemail.com |
---|---|
State | Superseded, archived |
Delegated to: | David Miller |
Headers | show |
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.
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 -- 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
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 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(-)