Skip to content

Commit

Permalink
NFS: Correct the array bound calculation in nfs_readdir_add_to_array
Browse files Browse the repository at this point in the history
It looks as if the array size calculation in MAX_READDIR_ARRAY does not
take the alignment of struct nfs_cache_array_entry into account.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
  • Loading branch information
Trond Myklebust authored and Trond Myklebust committed Nov 22, 2010
1 parent ece0b42 commit 3020093
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ struct nfs_cache_array {
struct nfs_cache_array_entry array[0];
};

#define MAX_READDIR_ARRAY ((PAGE_SIZE - sizeof(struct nfs_cache_array)) / sizeof(struct nfs_cache_array_entry))

typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int);
typedef struct {
struct file *file;
Expand Down Expand Up @@ -257,11 +255,14 @@ int nfs_readdir_add_to_array(struct nfs_entry *entry, struct page *page)

if (IS_ERR(array))
return PTR_ERR(array);

cache_entry = &array->array[array->size];

/* Check that this entry lies within the page bounds */
ret = -ENOSPC;
if (array->size >= MAX_READDIR_ARRAY)
if ((char *)&cache_entry[1] - (char *)page_address(page) > PAGE_SIZE)
goto out;

cache_entry = &array->array[array->size];
cache_entry->cookie = entry->prev_cookie;
cache_entry->ino = entry->ino;
ret = nfs_readdir_make_qstr(&cache_entry->string, entry->name, entry->len);
Expand Down

0 comments on commit 3020093

Please sign in to comment.