diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2008-01-25 04:08:09 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2008-02-04 01:24:52 -0600 |
commit | cd9df1aac346f1c7f592739d092ff710c27bbcde (patch) | |
tree | cc7eadf1e209742b89cb0a064495dee9f1fc6c98 /fs/dlm | |
parent | 02ed16b64dc5b7a4f78476bdb64da9bbf88d84b3 (diff) | |
download | linux-cd9df1aac346f1c7f592739d092ff710c27bbcde.tar.gz linux-cd9df1aac346f1c7f592739d092ff710c27bbcde.tar.bz2 linux-cd9df1aac346f1c7f592739d092ff710c27bbcde.zip |
dlm: validate data in dlm_recover_directory()
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: David Teigland <teigland@redhat.com>
Diffstat (limited to 'fs/dlm')
-rw-r--r-- | fs/dlm/dir.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c index ce30136671b3..831050e5bfd5 100644 --- a/fs/dlm/dir.c +++ b/fs/dlm/dir.c @@ -220,6 +220,7 @@ int dlm_recover_directory(struct dlm_ls *ls) last_len = 0; for (;;) { + int left; error = dlm_recovery_stopped(ls); if (error) goto out_free; @@ -236,11 +237,20 @@ int dlm_recover_directory(struct dlm_ls *ls) */ b = ls->ls_recover_buf->rc_buf; + left = ls->ls_recover_buf->rc_header.h_length; + left -= sizeof(struct dlm_rcom); for (;;) { - memcpy(&namelen, b, sizeof(uint16_t)); - namelen = be16_to_cpu(namelen); - b += sizeof(uint16_t); + __be16 v; + + error = -EINVAL; + if (left < sizeof(__be16)) + goto out_free; + + memcpy(&v, b, sizeof(__be16)); + namelen = be16_to_cpu(v); + b += sizeof(__be16); + left -= sizeof(__be16); /* namelen of 0xFFFFF marks end of names for this node; namelen of 0 marks end of the @@ -251,6 +261,12 @@ int dlm_recover_directory(struct dlm_ls *ls) if (!namelen) break; + if (namelen > left) + goto out_free; + + if (namelen > DLM_RESNAME_MAXLEN) + goto out_free; + error = -ENOMEM; de = get_free_de(ls, namelen); if (!de) @@ -262,6 +278,7 @@ int dlm_recover_directory(struct dlm_ls *ls) memcpy(de->name, b, namelen); memcpy(last_name, b, namelen); b += namelen; + left -= namelen; add_entry_to_hash(ls, de); count++; |