mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-25 10:19:47 +00:00
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: David Howells <dhowells@redhat.com>
This commit is contained in:
parent
b3cfb6f567
commit
68eb64c3d2
2 changed files with 16 additions and 11 deletions
|
@ -17,11 +17,6 @@
|
|||
#include "internal.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.
|
||||
*/
|
||||
|
@ -43,11 +38,15 @@ struct afs_addr_list *afs_alloc_addrlist(unsigned int nr,
|
|||
|
||||
_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);
|
||||
if (!alist)
|
||||
return NULL;
|
||||
|
||||
refcount_set(&alist->usage, 1);
|
||||
alist->max_addrs = nr;
|
||||
|
||||
for (i = 0; i < nr; 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,
|
|||
} while (p < end);
|
||||
|
||||
_debug("%u/%u addresses", nr, AFS_MAX_ADDRESSES);
|
||||
if (nr > AFS_MAX_ADDRESSES)
|
||||
nr = AFS_MAX_ADDRESSES;
|
||||
|
||||
alist = afs_alloc_addrlist(nr, service, port);
|
||||
if (!alist)
|
||||
|
@ -180,7 +177,7 @@ struct afs_addr_list *afs_parse_text_addrs(const char *text, size_t len,
|
|||
}
|
||||
|
||||
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);
|
||||
return alist;
|
||||
|
@ -241,6 +238,9 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
|
|||
__be16 xport = htons(port);
|
||||
int i;
|
||||
|
||||
if (alist->nr_addrs >= alist->max_addrs)
|
||||
return;
|
||||
|
||||
for (i = 0; i < alist->nr_ipv4; i++) {
|
||||
a = &alist->addrs[i].transport.sin6;
|
||||
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)
|
|||
__be16 xport = htons(port);
|
||||
int i, diff;
|
||||
|
||||
if (alist->nr_addrs >= alist->max_addrs)
|
||||
return;
|
||||
|
||||
for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
|
||||
a = &alist->addrs[i].transport.sin6;
|
||||
diff = memcmp(xdr, &a->sin6_addr, 16);
|
||||
|
|
|
@ -73,12 +73,14 @@ struct afs_addr_list {
|
|||
struct rcu_head rcu; /* Must be first */
|
||||
refcount_t usage;
|
||||
u32 version; /* Version */
|
||||
unsigned short nr_addrs;
|
||||
unsigned short index; /* Address currently in use */
|
||||
unsigned short nr_ipv4; /* Number of IPv4 addresses */
|
||||
unsigned char max_addrs;
|
||||
unsigned char nr_addrs;
|
||||
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 yfs; /* Mask of servers that are YFS */
|
||||
struct sockaddr_rxrpc addrs[];
|
||||
#define AFS_MAX_ADDRESSES ((unsigned int)(sizeof(unsigned long) * 8))
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue