All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Loganaden Velvindron <logan@elandsys.com>, netdev@vger.kernel.org
Subject: Re: [PATCH net-next ] net: ipv4: memset addr before calling copy_to_user()
Date: Mon, 09 Nov 2015 11:09:06 +0100	[thread overview]
Message-ID: <1447063746.377490.433562497.7B532277@webmail.messagingengine.com> (raw)
In-Reply-To: <20151109065236.GA2271@mx.elandsys.com>

Hello,

On Mon, Nov 9, 2015, at 07:52, Loganaden Velvindron wrote:
> zero addr before calling copy_to_user()
>  
> Signed-off-by: Loganaden Velvindron <logan@elandsys.com>
> ---
>  net/ipv4/ip_sockglue.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
> index c3c359a..d7a5a8b 100644
> --- a/net/ipv4/ip_sockglue.c
> +++ b/net/ipv4/ip_sockglue.c
> @@ -1373,6 +1373,7 @@ static int do_ip_getsockopt(struct sock *sk, int
> level, int optname,
>  	case IP_MULTICAST_IF:
>  	{
>  		struct in_addr addr;
> +               memset(&addr, 0, sizeof(addr));
>  		len = min_t(unsigned int, len, sizeof(struct in_addr));
>  		addr.s_addr = inet->mc_addr;
>  		release_sock(sk);

There is no possibility we leak any unwanted data to user space here.

If you are not sure if sizeof(addr) > sizeof(addr.s_addr) use a
designated initializer:

addr = { .s_addr = inet->mc_addr };

which clears all other non-initialized elements. But here we are very
certain.

We do not do defensive programming, we try to do logical things, and
only logical things.
— Eric Dumazet (Thanks to Dan Carpenter.)

Bye,
Hannes

      reply	other threads:[~2015-11-09 10:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  6:52 [PATCH net-next ] net: ipv4: memset addr before calling copy_to_user() Loganaden Velvindron
2015-11-09 10:09 ` Hannes Frederic Sowa [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447063746.377490.433562497.7B532277@webmail.messagingengine.com \
    --to=hannes@stressinduktion.org \
    --cc=logan@elandsys.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.