Commit 68eb64c3 authored by David Howells's avatar David Howells

afs: Do better max capacity handling on address lists

Note the maximum allocated capacity in an afs_addr_list struct and discard
addresses that would exceed it in afs_merge_fs_addr{4,6}().

Also, since the current maximum capacity is less than 255, reduce the
relevant members to bytes.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent b3cfb6f5
...@@ -17,11 +17,6 @@ ...@@ -17,11 +17,6 @@
#include "internal.h" #include "internal.h"
#include "afs_fs.h" #include "afs_fs.h"
//#define AFS_MAX_ADDRESSES
// ((unsigned int)((PAGE_SIZE - sizeof(struct afs_addr_list)) /
// sizeof(struct sockaddr_rxrpc)))
#define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
/* /*
* Release an address list. * Release an address list.
*/ */
...@@ -43,11 +38,15 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr, ...@@ -43,11 +38,15 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr,
_enter("%u,%u,%u", nr, service, port); _enter("%u,%u,%u", nr, service, port);
if (nr > AFS_MAX_ADDRESSES)
nr = AFS_MAX_ADDRESSES;
alist = kzalloc(struct_size(alist, addrs, nr), GFP_KERNEL); alist = kzalloc(struct_size(alist, addrs, nr), GFP_KERNEL);
if (!alist) if (!alist)
return NULL; return NULL;
refcount_set(&alist->usage, 1); refcount_set(&alist->usage, 1);
alist->max_addrs = nr;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct sockaddr_rxrpc *srx = &alist->addrs[i]; struct sockaddr_rxrpc *srx = &alist->addrs[i];
...@@ -109,8 +108,6 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -109,8 +108,6 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
} while (p < end); } while (p < end);
_debug("%u/%u addresses", nr, AFS_MAX_ADDRESSES); _debug("%u/%u addresses", nr, AFS_MAX_ADDRESSES);
if (nr > AFS_MAX_ADDRESSES)
nr = AFS_MAX_ADDRESSES;
alist = afs_alloc_addrlist(nr, service, port); alist = afs_alloc_addrlist(nr, service, port);
if (!alist) if (!alist)
...@@ -180,7 +177,7 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len, ...@@ -180,7 +177,7 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
} }
alist->nr_addrs++; alist->nr_addrs++;
} while (p < end && alist->nr_addrs < AFS_MAX_ADDRESSES); } while (p < end && alist->nr_addrs < alist->max_addrs);
_leave(" = [nr %u]", alist->nr_addrs); _leave(" = [nr %u]", alist->nr_addrs);
return alist; return alist;
...@@ -241,6 +238,9 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port) ...@@ -241,6 +238,9 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
__be16 xport = htons(port); __be16 xport = htons(port);
int i; int i;
if (alist->nr_addrs >= alist->max_addrs)
return;
for (i = 0; i < alist->nr_ipv4; i++) { for (i = 0; i < alist->nr_ipv4; i++) {
a = &alist->addrs[i].transport.sin6; a = &alist->addrs[i].transport.sin6;
if (xdr == a->sin6_addr.s6_addr32[3] && if (xdr == a->sin6_addr.s6_addr32[3] &&
...@@ -277,6 +277,9 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port) ...@@ -277,6 +277,9 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
__be16 xport = htons(port); __be16 xport = htons(port);
int i, diff; int i, diff;
if (alist->nr_addrs >= alist->max_addrs)
return;
for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) { for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
a = &alist->addrs[i].transport.sin6; a = &alist->addrs[i].transport.sin6;
diff = memcmp(xdr, &a->sin6_addr, 16); diff = memcmp(xdr, &a->sin6_addr, 16);
......
...@@ -73,12 +73,14 @@ struct afs_addr_list { ...@@ -73,12 +73,14 @@ struct afs_addr_list {
struct rcu_head rcu; /* Must be first */ struct rcu_head rcu; /* Must be first */
refcount_t usage; refcount_t usage;
u32 version; /* Version */ u32 version; /* Version */
unsigned short nr_addrs; unsigned char max_addrs;
unsigned short index; /* Address currently in use */ unsigned char nr_addrs;
unsigned short nr_ipv4; /* Number of IPv4 addresses */ unsigned char index; /* Address currently in use */
unsigned char nr_ipv4; /* Number of IPv4 addresses */
unsigned long probed; /* Mask of servers that have been probed */ unsigned long probed; /* Mask of servers that have been probed */
unsigned long yfs; /* Mask of servers that are YFS */ unsigned long yfs; /* Mask of servers that are YFS */
struct sockaddr_rxrpc addrs[]; struct sockaddr_rxrpc addrs[];
#define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment