diff options
author | Amerigo Wang <amwang@redhat.com> | 2009-12-14 20:57:37 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:10 -0500 |
commit | ec81aecb29668ad71f699f4e7b96ec46691895b6 (patch) | |
tree | 0a66a8fb41689955e3400cba7fc7419f4183dec5 /fs/hfs | |
parent | 4b731d50ff3df6b9141a6c12b088e8eb0109e83c (diff) |
hfs: fix a potential buffer overflow
A specially-crafted Hierarchical File System (HFS) filesystem could cause
a buffer overflow to occur in a process's kernel stack during a memcpy()
call within the hfs_bnode_read() function (at fs/hfs/bnode.c:24). The
attacker can provide the source buffer and length, and the destination
buffer is a local variable of a fixed length. This local variable (passed
as "&entry" from fs/hfs/dir.c:112 and allocated on line 60) is stored in
the stack frame of hfs_bnode_read()'s caller, which is hfs_readdir().
Because the hfs_readdir() function executes upon any attempt to read a
directory on the filesystem, it gets called whenever a user attempts to
inspect any filesystem contents.
[amwang@redhat.com: modify this patch and fix coding style problems]
Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Eugene Teo <eteo@redhat.com>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Dave Anderson <anderson@redhat.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/hfs')
-rw-r--r-- | fs/hfs/catalog.c | 4 | ||||
-rw-r--r-- | fs/hfs/dir.c | 11 | ||||
-rw-r--r-- | fs/hfs/super.c | 7 |
3 files changed, 21 insertions, 1 deletions
diff --git a/fs/hfs/catalog.c b/fs/hfs/catalog.c index 6d98f116ca03..424b0337f524 100644 --- a/fs/hfs/catalog.c +++ b/fs/hfs/catalog.c | |||
@@ -289,6 +289,10 @@ int hfs_cat_move(u32 cnid, struct inode *src_dir, struct qstr *src_name, | |||
289 | err = hfs_brec_find(&src_fd); | 289 | err = hfs_brec_find(&src_fd); |
290 | if (err) | 290 | if (err) |
291 | goto out; | 291 | goto out; |
292 | if (src_fd.entrylength > sizeof(entry) || src_fd.entrylength < 0) { | ||
293 | err = -EIO; | ||
294 | goto out; | ||
295 | } | ||
292 | 296 | ||
293 | hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, | 297 | hfs_bnode_read(src_fd.bnode, &entry, src_fd.entryoffset, |
294 | src_fd.entrylength); | 298 | src_fd.entrylength); |
diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c index 7c69b98a2e45..2b3b8611b41b 100644 --- a/fs/hfs/dir.c +++ b/fs/hfs/dir.c | |||
@@ -79,6 +79,11 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
79 | filp->f_pos++; | 79 | filp->f_pos++; |
80 | /* fall through */ | 80 | /* fall through */ |
81 | case 1: | 81 | case 1: |
82 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { | ||
83 | err = -EIO; | ||
84 | goto out; | ||
85 | } | ||
86 | |||
82 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, fd.entrylength); | 87 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, fd.entrylength); |
83 | if (entry.type != HFS_CDR_THD) { | 88 | if (entry.type != HFS_CDR_THD) { |
84 | printk(KERN_ERR "hfs: bad catalog folder thread\n"); | 89 | printk(KERN_ERR "hfs: bad catalog folder thread\n"); |
@@ -109,6 +114,12 @@ static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
109 | err = -EIO; | 114 | err = -EIO; |
110 | goto out; | 115 | goto out; |
111 | } | 116 | } |
117 | |||
118 | if (fd.entrylength > sizeof(entry) || fd.entrylength < 0) { | ||
119 | err = -EIO; | ||
120 | goto out; | ||
121 | } | ||
122 | |||
112 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, fd.entrylength); | 123 | hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, fd.entrylength); |
113 | type = entry.type; | 124 | type = entry.type; |
114 | len = hfs_mac2asc(sb, strbuf, &fd.key->cat.CName); | 125 | len = hfs_mac2asc(sb, strbuf, &fd.key->cat.CName); |
diff --git a/fs/hfs/super.c b/fs/hfs/super.c index f7fcbe49da72..5ed7252b7b23 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c | |||
@@ -409,8 +409,13 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) | |||
409 | /* try to get the root inode */ | 409 | /* try to get the root inode */ |
410 | hfs_find_init(HFS_SB(sb)->cat_tree, &fd); | 410 | hfs_find_init(HFS_SB(sb)->cat_tree, &fd); |
411 | res = hfs_cat_find_brec(sb, HFS_ROOT_CNID, &fd); | 411 | res = hfs_cat_find_brec(sb, HFS_ROOT_CNID, &fd); |
412 | if (!res) | 412 | if (!res) { |
413 | if (fd.entrylength > sizeof(rec) || fd.entrylength < 0) { | ||
414 | res = -EIO; | ||
415 | goto bail; | ||
416 | } | ||
413 | hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, fd.entrylength); | 417 | hfs_bnode_read(fd.bnode, &rec, fd.entryoffset, fd.entrylength); |
418 | } | ||
414 | if (res) { | 419 | if (res) { |
415 | hfs_find_exit(&fd); | 420 | hfs_find_exit(&fd); |
416 | goto bail_no_root; | 421 | goto bail_no_root; |