Skip to content

Commit a37d690

Browse files
kcp-gitLinuxMinion
authored andcommitted
IB/ipoib: Remove ACL sysfs debug files
Currently, there are device attributes like add_acl which are writable and can be used to add ACL in addition to using ioctl. The kernel needs to parse a string from user space. While parsing IPv4 address is simple, parsing IPv6 address is not. And it is error prone and can be a security issue if not done right. Since those attributes are only used in a debug kernel, it is advisable to remove those attributes instead of adding IPv6 support to them. The following attributes, add_acl, delete_acl, acl, acl_instance, add_acl_instance and delete_acl_instance are removed. The last four do not handle IP address. But to be consistent, they are also removed. Orabug: 25410192 Signed-off-by: Ka-Cheong Poon <[email protected]> Reviewed-by: Yuval Shaia <[email protected]> Reviewed-by: Håkon Bugge <[email protected]>
1 parent 27d5eb0 commit a37d690

File tree

1 file changed

+1
-252
lines changed

1 file changed

+1
-252
lines changed

drivers/infiniband/ulp/ipoib/ipoib_acl.c

Lines changed: 1 addition & 252 deletions
Original file line numberDiff line numberDiff line change
@@ -32,73 +32,6 @@
3232
#include <linux/jhash.h>
3333
#include "ipoib.h"
3434

35-
int extract_guid_and_subnet(const char *buf, char *name, u64 *subnet_prefix,
36-
u64 *guid)
37-
{
38-
u64 gid[8];
39-
int i, shift;
40-
41-
memset(&gid, 0, sizeof(gid));
42-
43-
if (name) {
44-
if (sscanf(buf,
45-
"%s %4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx",
46-
name, &gid[0], &gid[1], &gid[2], &gid[3], &gid[4],
47-
&gid[5], &gid[6], &gid[7]) != 9)
48-
return -EINVAL;
49-
} else
50-
if (sscanf(buf,
51-
"%4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx",
52-
&gid[0], &gid[1], &gid[2], &gid[3], &gid[4], &gid[5],
53-
&gid[6], &gid[7]) != 8)
54-
return -EINVAL;
55-
56-
*guid = 0;
57-
*subnet_prefix = 0;
58-
for (i = 0; i < 4; i++) {
59-
shift = ((3 - i) * 16);
60-
*subnet_prefix |= gid[i] << shift;
61-
*guid |= gid[i + 4] << shift;
62-
}
63-
64-
return 0;
65-
}
66-
67-
int extract_guid_subnet_and_ip(const char *buf, char *name, u64 *subnet_prefix,
68-
u64 *guid, u32 *src_ip, char *uuid)
69-
{
70-
u64 gid[8];
71-
u32 ip[4];
72-
int rc, i, shift;
73-
74-
memset(&gid, 0, sizeof(gid));
75-
memset(&ip, 0, sizeof(ip));
76-
memset(uuid, 0, UUID_SZ);
77-
78-
rc = sscanf(buf,
79-
"%s %4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx:%4llx %s %d.%d.%d.%d",
80-
name, &gid[0], &gid[1], &gid[2], &gid[3], &gid[4], &gid[5],
81-
&gid[6], &gid[7], uuid, &ip[0], &ip[1], &ip[2], &ip[3]);
82-
if (rc != 14)
83-
return -EINVAL;
84-
85-
*guid = 0;
86-
*subnet_prefix = 0;
87-
for (i = 0; i < 4; i++) {
88-
shift = ((3 - i) * 16);
89-
*subnet_prefix |= gid[i] << shift;
90-
*guid |= gid[i + 4] << shift;
91-
}
92-
93-
*src_ip = 0;
94-
for (i = 0; i < 4; i++) {
95-
shift = ((3 - i) * 8);
96-
*src_ip |= ip[i] << shift;
97-
}
98-
99-
return 0;
100-
}
101-
10235
static ssize_t show_acl_enabled(struct device *d,
10336
struct device_attribute *attr, char *buf)
10437
{
@@ -122,115 +55,6 @@ static ssize_t set_acl_enabled(struct device *d, struct device_attribute *attr,
12255
static DEVICE_ATTR(acl_enabled, S_IWUSR | S_IRUGO, show_acl_enabled,
12356
set_acl_enabled);
12457

125-
static ssize_t add_acl(struct device *d, struct device_attribute *attr,
126-
const char *buf, size_t count)
127-
{
128-
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
129-
int rc;
130-
u64 guid, subnet_prefix;
131-
u32 ip;
132-
char uuid[UUID_SZ];
133-
struct ib_cm_acl *instance_acl;
134-
char name[INSTANCE_ACL_ID_SZ];
135-
136-
rc = extract_guid_subnet_and_ip(buf, name, &subnet_prefix, &guid, &ip,
137-
uuid);
138-
if (rc != 0)
139-
return rc;
140-
141-
instance_acl = ipoib_get_instance_acl(name, to_net_dev(d));
142-
if (!instance_acl)
143-
return -EINVAL;
144-
145-
rc = ib_cm_acl_insert(instance_acl, subnet_prefix, guid, ip, uuid);
146-
rc |= ib_cm_acl_insert(&priv->acl, subnet_prefix, guid, ip, uuid);
147-
if (rc != 0)
148-
return rc;
149-
150-
return count;
151-
}
152-
153-
static DEVICE_ATTR(add_acl, S_IWUSR, NULL, add_acl);
154-
155-
static ssize_t delete_acl(struct device *d, struct device_attribute *attr,
156-
const char *buf, size_t count)
157-
{
158-
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
159-
u64 guid, subnet_prefix;
160-
int rc;
161-
struct ib_cm_acl *instance_acl;
162-
char name[INSTANCE_ACL_ID_SZ];
163-
164-
rc = extract_guid_and_subnet(buf, name, &subnet_prefix, &guid);
165-
if (rc != 0)
166-
return rc;
167-
168-
instance_acl = ipoib_get_instance_acl(name, to_net_dev(d));
169-
if (!instance_acl)
170-
return -EINVAL;
171-
172-
ib_cm_acl_delete(instance_acl, subnet_prefix, guid);
173-
ib_cm_acl_delete(&priv->acl, subnet_prefix, guid);
174-
175-
return count;
176-
}
177-
178-
static DEVICE_ATTR(delete_acl, S_IWUSR, NULL, delete_acl);
179-
180-
void print_acl_to_buf(char *buf, const char *name, struct ib_cm_acl *acl)
181-
{
182-
struct ib_cm_acl_elem *list;
183-
ssize_t list_count, i;
184-
u8 *subnet_prefix, *guid;
185-
u8 *ip;
186-
187-
ib_cm_acl_scan(acl, &list, &list_count);
188-
for (i = 0; i < list_count; i++) {
189-
subnet_prefix = (u8 *)&(list[i].subnet_prefix);
190-
guid = (u8 *)&(list[i].guid);
191-
ip = (u8 *)&(list[i].ip);
192-
sprintf(buf,
193-
"%s%s\t%d\t%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\t%s\t%d.%d.%d.%d\n",
194-
buf, name, list[i].ref_count, subnet_prefix[7],
195-
subnet_prefix[6], subnet_prefix[5], subnet_prefix[4],
196-
subnet_prefix[3], subnet_prefix[2], subnet_prefix[1],
197-
subnet_prefix[0], guid[7], guid[6], guid[5], guid[4],
198-
guid[3], guid[2], guid[1], guid[0], list[i].uuid,
199-
ip[3], ip[2], ip[1], ip[0]);
200-
}
201-
kfree(list);
202-
}
203-
204-
static ssize_t show_acl(struct device *d,
205-
struct device_attribute *attr, char *buf)
206-
{
207-
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
208-
struct ipoib_instance_acl *results[ACL_BATCH_SZ];
209-
unsigned int count, i;
210-
unsigned long idx = 0;
211-
212-
strcpy(buf, "");
213-
214-
print_acl_to_buf(buf, DRIVER_ACL_NAME, &priv->acl);
215-
216-
count = 0;
217-
do {
218-
count = radix_tree_gang_lookup(&priv->instances_acls.instances,
219-
(void **)results, idx,
220-
ACL_BATCH_SZ);
221-
for (i = 0; i < count; i++)
222-
print_acl_to_buf(buf, results[i]->name,
223-
&results[i]->acl);
224-
if (count)
225-
idx = jhash(results[i - 1]->name,
226-
strlen(results[i - 1]->name), 0) + 1;
227-
} while (count);
228-
229-
return strlen(buf);
230-
}
231-
232-
static DEVICE_ATTR(acl, S_IRUGO, show_acl, NULL);
233-
23458
void print_acl_instances_to_buf(char *buf, size_t sz,
23559
struct ipoib_dev_priv *priv)
23660
{
@@ -261,87 +85,12 @@ void print_acl_instances_to_buf(char *buf, size_t sz,
26185
} while (count);
26286
}
26387

264-
static ssize_t show_acl_instances(struct device *d,
265-
struct device_attribute *attr, char *buf)
266-
{
267-
struct ipoib_dev_priv *priv = netdev_priv(to_net_dev(d));
268-
269-
/* Assumption here is that buf has enoght place to hold entire list */
270-
print_acl_instances_to_buf(buf, priv->instances_acls.list_count *
271-
INSTANCE_ACL_ID_SZ + 1, priv);
272-
273-
return strlen(buf);
274-
}
275-
276-
static DEVICE_ATTR(acl_instances, S_IRUGO, show_acl_instances, NULL);
277-
278-
static ssize_t add_acl_instance(struct device *d, struct device_attribute *attr,
279-
const char *buf, size_t count)
280-
{
281-
char name[INSTANCE_ACL_ID_SZ];
282-
char *crlf_pos = strchr(buf, '\n');
283-
284-
strncpy(name, buf, INSTANCE_ACL_ID_SZ);
285-
if (crlf_pos)
286-
name[crlf_pos - buf] = 0;
287-
ipoib_create_instance_acl(name, to_net_dev(d));
288-
289-
return count;
290-
}
291-
292-
static DEVICE_ATTR(add_acl_instance, S_IWUSR, NULL, add_acl_instance);
293-
294-
static ssize_t delete_acl_instance(struct device *d,
295-
struct device_attribute *attr,
296-
const char *buf, size_t count)
297-
{
298-
char name[INSTANCE_ACL_ID_SZ];
299-
char *crlf_pos = strchr(buf, '\n');
300-
301-
strncpy(name, buf, INSTANCE_ACL_ID_SZ);
302-
if (crlf_pos)
303-
name[crlf_pos - buf] = 0;
304-
ipoib_delete_instance_acl(name, to_net_dev(d));
305-
306-
return count;
307-
}
308-
309-
static DEVICE_ATTR(delete_acl_instance, S_IWUSR, NULL, delete_acl_instance);
310-
31188
int ipoib_create_acl_sysfs(struct net_device *dev)
31289
{
313-
int rc = 0;
314-
31590
if (!ipoib_debug_level)
31691
dev_attr_acl_enabled.attr.mode = 0444;
31792

318-
rc = device_create_file(&dev->dev, &dev_attr_acl_enabled);
319-
if (rc)
320-
return rc;
321-
322-
if (!ipoib_debug_level)
323-
return 0;
324-
325-
rc = device_create_file(&dev->dev, &dev_attr_add_acl);
326-
if (rc)
327-
return rc;
328-
rc = device_create_file(&dev->dev, &dev_attr_delete_acl);
329-
if (rc)
330-
return rc;
331-
rc = device_create_file(&dev->dev, &dev_attr_acl);
332-
if (rc)
333-
return rc;
334-
rc = device_create_file(&dev->dev, &dev_attr_add_acl_instance);
335-
if (rc)
336-
return rc;
337-
rc = device_create_file(&dev->dev, &dev_attr_delete_acl_instance);
338-
if (rc)
339-
return rc;
340-
rc = device_create_file(&dev->dev, &dev_attr_acl_instances);
341-
if (rc)
342-
return rc;
343-
344-
return 0;
93+
return device_create_file(&dev->dev, &dev_attr_acl_enabled);
34594
}
34695

34796
void delete_instance_acls(struct net_device *dev)

0 commit comments

Comments
 (0)