public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul@parallels•com>
To: Brian Haley <brian.haley@hp•com>
Cc: David Miller <davem@davemloft•net>,
	Eric Dumazet <eric.dumazet@gmail•com>,
	"netdev@vger•kernel.org" <netdev@vger•kernel.org>
Subject: Re: [PATCH net-next] sockopt: Change getsockopt() of SO_BINDTODEVICE to return an interface name
Date: Fri, 02 Nov 2012 13:36:11 +0400	[thread overview]
Message-ID: <5093940B.6020207@parallels.com> (raw)
In-Reply-To: <509184D9.8030103@hp.com>

> +static int sock_getbindtodevice(struct sock *sk, char __user *optval,
> +				int __user *optlen, int len)
> +{
> +	int ret = -ENOPROTOOPT;
> +#ifdef CONFIG_NETDEVICES
> +	struct net *net = sock_net(sk);
> +	struct net_device *dev;
> +	char devname[IFNAMSIZ];
> +
> +	if (sk->sk_bound_dev_if == 0) {
> +		len = 0;
> +		goto zero;
> +	}
> +
> +	ret = -EINVAL;
> +	if (len < IFNAMSIZ)
> +		goto out;
> +
> +	rcu_read_lock();
> +	dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
> +	if (dev)
> +		strcpy(devname, dev->name);

This still races with the device name change, potentially providing
a name which never existed in the system, doesn't it?

> +	rcu_read_unlock();
> +	ret = -ENODEV;
> +	if (!dev)
> +		goto out;
> +
> +	len = strlen(devname) + 1;
> +
> +	ret = -EFAULT;
> +	if (copy_to_user(optval, devname, len))
> +		goto out;
> +
> +zero:
> +	ret = -EFAULT;
> +	if (put_user(len, optlen))
> +		goto out;
> +
> +	ret = 0;
> +
> +out:
> +#endif
> +
> +	return ret;
> +}

Thanks,
Pavel

  parent reply	other threads:[~2012-11-02  9:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31 20:06 [PATCH net-next] sockopt: Change getsockopt() of SO_BINDTODEVICE to return an interface name Brian Haley
2012-10-31 20:47 ` Andi Kleen
2012-11-01 14:02   ` Brian Haley
2012-11-01 14:52   ` David Miller
2012-11-02  9:36 ` Pavel Emelyanov [this message]
2012-11-02 10:23   ` Eric Dumazet
2012-11-02 15:02   ` Brian Haley
2012-11-02 23:34     ` Ben Hutchings
2012-11-06  4:01       ` Brian Haley
2012-11-08  0:23         ` Ben Hutchings
2012-11-08 15:36         ` Brian Haley
2012-11-08 20:02           ` David Miller

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=5093940B.6020207@parallels.com \
    --to=xemul@parallels$(echo .)com \
    --cc=brian.haley@hp$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=eric.dumazet@gmail$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox