Thread (15 messages) 15 messages, 5 authors, 2012-10-23

Re: [PATCH net-next] sockopt: Make SO_BINDTODEVICE readable

flat view

From: Brian Haley <hidden>
Date: 2012-10-22 21:20:51

On 10/22/2012 04:45 PM, Eric Dumazet wrote:
On Mon, 2012-10-22 at 14:04 -0400, Brian Haley wrote:
quoted
+	char devname[IFNAMSIZ];
+
+	ret = 0;
+	if (sk->sk_bound_dev_if == 0)
+		goto out;
+
+	ret = -EINVAL;
+	if (len < IFNAMSIZ)
+		goto out;
+	if (len > IFNAMSIZ)
+		len = IFNAMSIZ;
+
+	rcu_read_lock();
+	dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
+	if (dev)
+		strcpy(dev->name, devname);
+	rcu_read_unlock();
+	ret = -ENODEV;
You probably meant

	strcpy(devname, dev->name)
Yes, that was a stupid mistake, I'll fix it.
By the way, this is not really safe in case device is renamed
It's not much different from what's there:

	setsockopt("foo");

	rename foo -> bar

	index = getsockopt();
	if_indextoname(index) -> "bar"

I more raised the issue since you pass a 'char *' to setsockopt() but an 'int *'
to getsockopt(), I don't think any other value is non-symmetrical like this.

-Brian
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help