Skip to contentSkip to conversation

120 potential dereference to invalid pointers errors for linux 2.4.1

PATCH New Andrew Morton 1 participant 1 message Mar 24, 2001

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 120 potential dereference to invalid pointers errors for linux 2.4.1

This gets us about 1/3 of the way through this one.

Affected files:

fs/proc/generic.c
arch/i386/kernel/irq.c
arch/i386/kernel/mtrr.c
drivers/acpi/dispatcher/dswload.c
drivers/atm/zatm.c
drivers/block/DAC960.c
drivers/block/ll_rw_blk.c
drivers/char/pc_keyb.c
drivers/char/rio/rio_linux.c
drivers/message/i2o/i2o_core.c

Four reports (drm and ip2main.c) were non-obvious and the maintainers have been poked.

The ll_rw_blk.c change could be a little more elegant. Really, we should propagate a failure of blk_init_queue() all the way back to the caller. In this patch we simply leave the device with a less-than-expected pool of requests and just limp along. Seems to be better than crashing.

Patch is against -ac24.

fs/proc/generic.c +2 -0
@@ -531,6 +531,8 @@
 	proc_register(parent, ent);
 	
 out:
+	if (ent == NULL)
+		printk(KERN_EMERG "create_proc_entry: failed to create entry for %s\n", name);
 	return ent;
 }
 
arch/i386/kernel/irq.c +6 -4
@@ -1155,10 +1155,12 @@
 		/* create /proc/irq/1234/smp_affinity */
 		entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
 
-		entry->nlink = 1;
-		entry->data = (void *)(long)irq;
-		entry->read_proc = irq_affinity_read_proc;
-		entry->write_proc = irq_affinity_write_proc;
+		if (entry) {
+			entry->nlink = 1;
+			entry->data = (void *)(long)irq;
+			entry->read_proc = irq_affinity_read_proc;
+			entry->write_proc = irq_affinity_write_proc;
+		}
 
 		smp_affinity_entry[irq] = entry;
 	}
arch/i386/kernel/mtrr.c +6 -3
@@ -1809,7 +1809,8 @@
     }
     devfs_set_file_size (devfs_handle, ascii_buf_bytes);
 #  ifdef CONFIG_PROC_FS
-    proc_root_mtrr->size = ascii_buf_bytes;
+    if (proc_root_mtrr)
+	proc_root_mtrr->size = ascii_buf_bytes;
 #  endif  /*  CONFIG_PROC_FS  */
 }   /*  End Function compute_ascii  */
 
@@ -2118,8 +2119,10 @@
 
 #ifdef CONFIG_PROC_FS
     proc_root_mtrr = create_proc_entry ("mtrr", S_IWUSR | S_IRUGO, &proc_root);
-    proc_root_mtrr->owner = THIS_MODULE;
-    proc_root_mtrr->proc_fops = &mtrr_fops;
+    if (proc_root_mtrr) {
+	proc_root_mtrr->owner = THIS_MODULE;
+	proc_root_mtrr->proc_fops = &mtrr_fops;
+    }
 #endif
 #ifdef CONFIG_DEVFS_FS
     devfs_handle = devfs_register (NULL, "cpu/mtrr", DEVFS_FL_DEFAULT, 0, 0,
drivers/acpi/dispatcher/dswload.c +5 -0
@@ -455,6 +455,11 @@
 			arg = acpi_ps_get_arg (op, 2);
 		}
 
+		if (arg == NULL) {
+			status = AE_NOT_FOUND;
+			break;
+		}
+	
 		/*
 		 * Enter the Name_string into the namespace
 		 */
drivers/atm/zatm.c +5 -1
@@ -1826,9 +1826,13 @@
 			devs++;
 			zatm_dev = (struct zatm_dev *) kmalloc(sizeof(struct
 			    zatm_dev),GFP_KERNEL);
-			if (!zatm_dev) break;
+			if (!zatm_dev) {
+				printk(KERN_EMERG "zatm.c: memory shortage\n");
+				goto out;
+			}
 		}
 	}
+out:
 	return devs;
 }
 
drivers/block/DAC960.c +149 -114

346 lines not on this page · raw message

drivers/block/ll_rw_blk.c +5 -0
@@ -395,6 +395,11 @@
 	 */
 	for (i = 0; i < queue_nr_requests; i++) {
 		rq = kmem_cache_alloc(request_cachep, SLAB_KERNEL);
+		if (rq == NULL) {
+			/* We'll get a `leaked requests' message from blk_cleanup_queue */
+			printk(KERN_EMERG "blk_init_free_list: error allocating requests\n");
+			break;
+		}
 		memset(rq, 0, sizeof(struct request));
 		rq->rq_status = RQ_INACTIVE;
 		list_add(&rq->table, &q->request_freelist[i & 1]);
drivers/char/pc_keyb.c +2 -0
@@ -1016,6 +1016,8 @@
 
 	misc_register(&psaux_mouse);
 	queue = (struct aux_queue *) kmalloc(sizeof(*queue), GFP_KERNEL);
+	if (queue == NULL)
+		panic("psaux_init(): out of memory");
 	memset(queue, 0, sizeof(*queue));
 	queue->head = queue->tail = 0;
 	init_waitqueue_head(&queue->proc_list);
drivers/char/rio/rio_linux.c +4 -2
@@ -1031,8 +1031,10 @@
  free2:kfree (p->RIOHosts);
  free1:kfree (p);
  free0:
-  rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p %p %p\n", 
-               p, p->RIOHosts, p->RIOPortp, rio_termios, rio_termios);
+  if (p) {
+	rio_dprintk (RIO_DEBUG_INIT, "Not enough memory! %p %p %p %p %p\n", 
+        	       p, p->RIOHosts, p->RIOPortp, rio_termios, rio_termios);
+  }
   return -ENOMEM;
 }
 
drivers/message/i2o/i2o_core.c +4 -0
@@ -933,6 +933,10 @@
 					kmalloc(sizeof(struct i2o_device), GFP_KERNEL);
 				int i;
 
+				if (d == NULL) {
+					printk(KERN_EMERG "i2oevtd: out of memory\n");
+					break;
+				}
 				memcpy(&d->lct_data, &msg[5], sizeof(i2o_lct_entry));
 	
 				d->next = NULL;