aboutsummaryrefslogtreecommitdiffstats
path: root/fs/befs
diff options
context:
space:
mode:
authorDiego Calleja <diegocg@gmail.com>2006-08-05 15:14:55 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-08-06 11:57:48 -0400
commit94f563c426a78c97fc2a377315995e6ec8343872 (patch)
treea3cd539a665947d389d90bc99aff9daa50eda5a2 /fs/befs
parente31f59ce593b073ee14241781edfb0637697eeb6 (diff)
[PATCH] Fix BeFS slab corruption
In bugzilla #6941, Jens Kilian reported: "The function befs_utf2nls (in fs/befs/linuxvfs.c) writes a 0 byte past the end of a block of memory allocated via kmalloc(), leading to memory corruption. This happens only for filenames which are pure ASCII and a multiple of 4 bytes in length. [...] Without DEBUG_SLAB, this leads to further corruption and hard lockups; I believe this is the bug which has made kernels later than 2.6.8 unusable for me. (This must be due to changes in memory management, the bug has been in the BeFS driver since the time it was introduced (AFAICT).) Steps to reproduce: Create a directory (in BeOS, naturally :-) with files named, e.g., "1", "22", "333", "4444", ... Mount it in Linux and do an "ls" or "find"" This patch implements the suggested fix. Credits to Jens Kilian for debugging the problem and finding the right fix. Signed-off-by: Diego Calleja <diegocg@gmail.com> Cc: Jens Kilian <jjk@acm.org> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/befs')
-rw-r--r--fs/befs/linuxvfs.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index fcaeead9696b..50cfca5c7efd 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -512,7 +512,11 @@ befs_utf2nls(struct super_block *sb, const char *in,
512 wchar_t uni; 512 wchar_t uni;
513 int unilen, utflen; 513 int unilen, utflen;
514 char *result; 514 char *result;
515 int maxlen = in_len; /* The utf8->nls conversion can't make more chars */ 515 /* The utf8->nls conversion won't make the final nls string bigger
516 * than the utf one, but if the string is pure ascii they'll have the
517 * same width and an extra char is needed to save the additional \0
518 */
519 int maxlen = in_len + 1;
516 520
517 befs_debug(sb, "---> utf2nls()"); 521 befs_debug(sb, "---> utf2nls()");
518 522
@@ -588,7 +592,10 @@ befs_nls2utf(struct super_block *sb, const char *in,
588 wchar_t uni; 592 wchar_t uni;
589 int unilen, utflen; 593 int unilen, utflen;
590 char *result; 594 char *result;
591 int maxlen = 3 * in_len; 595 /* There're nls characters that will translate to 3-chars-wide UTF-8
596 * characters, a additional byte is needed to save the final \0
597 * in special cases */
598 int maxlen = (3 * in_len) + 1;
592 599
593 befs_debug(sb, "---> nls2utf()\n"); 600 befs_debug(sb, "---> nls2utf()\n");
594 601