Skip to content

Commit 0301870

Browse files
kcp-gitSomasundaram Krishnasamy
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]> Orabug: 27487514 (cherry picked from commit a37d690) cherry-pick-repo=linux-uek.git Signed-off-by: Gerd Rausch <[email protected]> Reviewed-by: Sudhakar Didnukurti <[email protected]> Signed-off-by: Aron Silverton <[email protected]> Signed-off-by: Somasundaram Krishnasamy <[email protected]>
1 parent b8fab58 commit 0301870

File tree

1 file changed

+1
-276
lines changed

1 file changed

+1
-276
lines changed

drivers/infiniband/ulp/ipoib/ipoib_acl.c

Lines changed: 1 addition & 276 deletions
Original file line numberDiff line numberDiff line change
@@ -34,74 +34,6 @@
3434
#include <linux/jhash.h>
3535
#include "ipoib.h"
3636

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

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 = ipoib_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)
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-
if (rc)
147-
return rc;
148-
149-
rc = ib_cm_acl_insert(&priv->acl, subnet_prefix, guid, ip, uuid);
150-
if (rc)
151-
return rc;
152-
153-
return count;
154-
}
155-
156-
static DEVICE_ATTR(add_acl, S_IWUSR, NULL, add_acl);
157-
158-
static ssize_t delete_acl(struct device *d, struct device_attribute *attr,
159-
const char *buf, size_t count)
160-
{
161-
struct ipoib_dev_priv *priv = ipoib_priv(to_net_dev(d));
162-
u64 guid, subnet_prefix;
163-
int rc;
164-
struct ib_cm_acl *instance_acl;
165-
char name[INSTANCE_ACL_ID_SZ];
166-
167-
rc = extract_guid_and_subnet(buf, name, &subnet_prefix, &guid);
168-
if (rc)
169-
return rc;
170-
171-
instance_acl = ipoib_get_instance_acl(name, to_net_dev(d));
172-
if (!instance_acl)
173-
return -EINVAL;
174-
175-
ib_cm_acl_delete(instance_acl, subnet_prefix, guid);
176-
ib_cm_acl_delete(&priv->acl, subnet_prefix, guid);
177-
178-
return count;
179-
}
180-
181-
static DEVICE_ATTR(delete_acl, S_IWUSR, NULL, delete_acl);
182-
183-
static void print_acl_to_buf(char *buf, size_t buf_size, const char *name,
184-
size_t name_size, struct ib_cm_acl *acl)
185-
{
186-
struct ib_cm_acl_elem *list;
187-
ssize_t list_count, i;
188-
u8 *subnet_prefix, *guid;
189-
u8 *ip;
190-
size_t curr_buf_size = 0;
191-
const size_t line_size = name_size + 100; /* Rough estimation */
192-
193-
ib_cm_acl_scan(acl, &list, &list_count);
194-
for (i = 0; i < list_count; i++) {
195-
/* Do we have enough place for more lines */
196-
if (curr_buf_size >= buf_size + line_size) {
197-
strcat(buf, "\nNo more space in buffer \n");
198-
goto out;
199-
}
200-
201-
subnet_prefix = (u8 *)&(list[i].subnet_prefix);
202-
guid = (u8 *)&(list[i].guid);
203-
ip = (u8 *)&(list[i].ip);
204-
curr_buf_size += sprintf(buf,
205-
"%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",
206-
buf, name, list[i].ref_count, subnet_prefix[7],
207-
subnet_prefix[6], subnet_prefix[5], subnet_prefix[4],
208-
subnet_prefix[3], subnet_prefix[2], subnet_prefix[1],
209-
subnet_prefix[0], guid[7], guid[6], guid[5], guid[4],
210-
guid[3], guid[2], guid[1], guid[0], list[i].uuid,
211-
ip[3], ip[2], ip[1], ip[0]);
212-
}
213-
214-
out:
215-
kfree(list);
216-
}
217-
218-
static ssize_t show_acl(struct device *d,
219-
struct device_attribute *attr, char *buf)
220-
{
221-
struct ipoib_dev_priv *priv = ipoib_priv(to_net_dev(d));
222-
struct ipoib_instance_acl *results[ACL_BATCH_SZ];
223-
unsigned int count, i;
224-
unsigned long idx = 0;
225-
226-
strcpy(buf, "");
227-
228-
/* Per Documentation/filesystems/sysfs.txt buf size is PAGE_SIZE */
229-
print_acl_to_buf(buf, PAGE_SIZE, DRIVER_ACL_NAME, INSTANCE_ACL_ID_SZ,
230-
&priv->acl);
231-
232-
count = 0;
233-
do {
234-
count = radix_tree_gang_lookup(&priv->instances_acls.instances,
235-
(void **)results, idx,
236-
ACL_BATCH_SZ);
237-
for (i = 0; i < count; i++)
238-
print_acl_to_buf(buf, PAGE_SIZE, results[i]->name,
239-
INSTANCE_ACL_ID_SZ, &results[i]->acl);
240-
if (count)
241-
idx = jhash(results[i - 1]->name,
242-
strlen(results[i - 1]->name), 0) + 1;
243-
} while (count);
244-
245-
return strlen(buf);
246-
}
247-
248-
static DEVICE_ATTR(acl, S_IRUGO, show_acl, NULL);
249-
25057
void print_acl_instances_to_buf(char *buf, size_t sz,
25158
struct ipoib_dev_priv *priv)
25259
{
@@ -278,94 +85,12 @@ void print_acl_instances_to_buf(char *buf, size_t sz,
27885
} while (count);
27986
}
28087

281-
static ssize_t show_acl_instances(struct device *d,
282-
struct device_attribute *attr, char *buf)
283-
{
284-
struct ipoib_dev_priv *priv = ipoib_priv(to_net_dev(d));
285-
286-
/* Per Documentation/filesystems/sysfs.txt buf size is PAGE_SIZE */
287-
if (priv->instances_acls.list_count * (INSTANCE_ACL_ID_SZ + 1) + 1 <
288-
PAGE_SIZE)
289-
print_acl_instances_to_buf(buf, priv->instances_acls.list_count
290-
* (INSTANCE_ACL_ID_SZ + 1) + 1,
291-
priv);
292-
293-
return strlen(buf);
294-
}
295-
296-
static DEVICE_ATTR(acl_instances, S_IRUGO, show_acl_instances, NULL);
297-
298-
static ssize_t add_acl_instance(struct device *d, struct device_attribute *attr,
299-
const char *buf, size_t count)
300-
{
301-
char name[INSTANCE_ACL_ID_SZ];
302-
char *crlf_pos = strchr(buf, '\n');
303-
304-
strncpy(name, buf, INSTANCE_ACL_ID_SZ - 1);
305-
if (crlf_pos && (crlf_pos - buf) < INSTANCE_ACL_ID_SZ - 1)
306-
name[crlf_pos - buf] = 0;
307-
else
308-
name[INSTANCE_ACL_ID_SZ - 1] = 0;
309-
ipoib_create_instance_acl(name, to_net_dev(d));
310-
311-
return count;
312-
}
313-
314-
static DEVICE_ATTR(add_acl_instance, S_IWUSR, NULL, add_acl_instance);
315-
316-
static ssize_t delete_acl_instance(struct device *d,
317-
struct device_attribute *attr,
318-
const char *buf, size_t count)
319-
{
320-
char name[INSTANCE_ACL_ID_SZ];
321-
char *crlf_pos = strchr(buf, '\n');
322-
323-
strncpy(name, buf, INSTANCE_ACL_ID_SZ - 1);
324-
if (crlf_pos && (crlf_pos - buf) < INSTANCE_ACL_ID_SZ - 1)
325-
name[crlf_pos - buf] = 0;
326-
else
327-
name[INSTANCE_ACL_ID_SZ - 1] = 0;
328-
ipoib_delete_instance_acl(name, to_net_dev(d));
329-
330-
return count;
331-
}
332-
333-
static DEVICE_ATTR(delete_acl_instance, S_IWUSR, NULL, delete_acl_instance);
334-
33588
int ipoib_create_acl_sysfs(struct net_device *dev)
33689
{
337-
int rc;
338-
33990
if (!ipoib_debug_level)
34091
dev_attr_acl_enabled.attr.mode = 0444;
34192

342-
rc = device_create_file(&dev->dev, &dev_attr_acl_enabled);
343-
if (rc)
344-
return rc;
345-
346-
if (!ipoib_debug_level)
347-
return 0;
348-
349-
rc = device_create_file(&dev->dev, &dev_attr_add_acl);
350-
if (rc)
351-
return rc;
352-
rc = device_create_file(&dev->dev, &dev_attr_delete_acl);
353-
if (rc)
354-
return rc;
355-
rc = device_create_file(&dev->dev, &dev_attr_acl);
356-
if (rc)
357-
return rc;
358-
rc = device_create_file(&dev->dev, &dev_attr_add_acl_instance);
359-
if (rc)
360-
return rc;
361-
rc = device_create_file(&dev->dev, &dev_attr_delete_acl_instance);
362-
if (rc)
363-
return rc;
364-
rc = device_create_file(&dev->dev, &dev_attr_acl_instances);
365-
if (rc)
366-
return rc;
367-
368-
return 0;
93+
return device_create_file(&dev->dev, &dev_attr_acl_enabled);
36994
}
37095

37196
void delete_instance_acls(struct net_device *dev)

0 commit comments

Comments
 (0)