* [PATCH] add kmalloc checking to fs/jffs/intrep.c (245-ac16)
@ 2001-06-23 14:42 Rasmus Andersen
2001-06-23 14:57 ` David Woodhouse
0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Andersen @ 2001-06-23 14:42 UTC (permalink / raw)
To: jffs-dev; +Cc: linux-kernel
Hi.
The following patch adds some checks for kmalloc returning NULL
to fs/jffs/intrep.c along with some way of getting that propagated
back. Applies against 245ac16 and 246p5. These dereferences were
reported by the Stanford team a way back.
--- linux-245-ac16-clean/fs/jffs/intrep.c Thu Jun 21 21:26:24 2001
+++ linux-245-ac16/fs/jffs/intrep.c Sat Jun 23 16:25:33 2001
@@ -320,8 +320,8 @@
}
-__u32
-jffs_checksum_flash(struct mtd_info *mtd, loff_t start, int size)
+int
+jffs_checksum_flash(struct mtd_info *mtd, loff_t start, int size, __u32* checksum)
{
__u32 sum = 0;
loff_t ptr = start;
@@ -330,6 +330,10 @@
/* Allocate read buffer */
read_buf = (__u8 *) kmalloc (sizeof(__u8) * 4096, GFP_KERNEL);
+ if (!read_buf) {
+ printk(KERN_ERR "(jffs:) Out of memory allocating buffer. Aborting.");
+ return -1;
+ }
/* Loop until checksum done */
while (size) {
@@ -357,7 +361,8 @@
/* Return result */
D3(printk("checksum result: 0x%08x\n", sum));
- return sum;
+ *checksum = sum;
+ return 0;
}
static __inline__ void jffs_fm_write_lock(struct jffs_fmcontrol *fmc)
{
@@ -605,6 +610,8 @@
/* Allocate read buffer */
read_buf = (__u8 *) kmalloc (sizeof(__u8) * 4096, GFP_KERNEL);
+ if (!read_buf)
+ return -ENOMEM;
/* Start the scan. */
while (pos < end) {
@@ -859,7 +866,10 @@
if (raw_inode.rename) {
deleted_file = flash_read_u32(fmc->mtd, pos);
}
- checksum = jffs_checksum_flash(fmc->mtd, pos, raw_inode.dsize);
+ if (jffs_checksum_flash(fmc->mtd, pos,
+ raw_inode.dsize, &checksum))
+ return -ENOMEM;
+
pos += raw_inode.dsize
+ JFFS_GET_PAD_BYTES(raw_inode.dsize);
--
Regards,
Rasmus(rasmus@jaquet.dk)
Television is called a medium because it is neither rare nor well-done.
-- Anonymous
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] add kmalloc checking to fs/jffs/intrep.c (245-ac16)
2001-06-23 14:42 [PATCH] add kmalloc checking to fs/jffs/intrep.c (245-ac16) Rasmus Andersen
@ 2001-06-23 14:57 ` David Woodhouse
0 siblings, 0 replies; 2+ messages in thread
From: David Woodhouse @ 2001-06-23 14:57 UTC (permalink / raw)
To: Rasmus Andersen; +Cc: jffs-dev, linux-kernel
rasmus@jaquet.dk said:
> The following patch adds some checks for kmalloc returning NULL to fs/
> jffs/intrep.c along with some way of getting that propagated back.
> Applies against 245ac16 and 246p5. These dereferences were reported by
> the Stanford team a way back.
Fixed in my tree at about the same time the FTL code was, a month or so ago,
along with some more important bugs. I haven't yet got round to feeding the
updates to Linus - that's next on my list after the MTD stuff which is in
2.4.6.
--
dwmw2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-06-23 14:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-06-23 14:42 [PATCH] add kmalloc checking to fs/jffs/intrep.c (245-ac16) Rasmus Andersen
2001-06-23 14:57 ` David Woodhouse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox