Skip to contentSkip to conversation

net/atm/clip.c: check kmem_cache_create() #1

Kernel-janitors Applied chas williams (contractor) 3 participants 6 messages Feb 4, 2004 – Feb 5, 2004 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

randy, i think it should probably return -ENOMEM instead of -1.

dave, please apply the following to both the 2.6 and 2.4 trees.

thanks!

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1548 -> 1.1549
# net/atm/clip.c 1.29 -> 1.30
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/02/04 [email protected] 1.1549
# [ATM]: [clip] check return code from kmem_cache_create (by "Randy.Dunlap" <[email protected]>) # --------------------------------------------
#

net/atm/clip.c +3 -0
diff -Nru a/net/atm/clip.c b/net/atm/clip.c
@@ -1021,6 +1021,9 @@
 	clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
 	    clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
 
+	if (!clip_tbl.kmem_cachep)
+		return -ENOMEM;
+
 	/* so neigh_ifdown() doesn't complain */
 	clip_tbl.proxy_timer.data = 0;
 	clip_tbl.proxy_timer.function = 0;
Quoted 49 lines · In message <[email protected]>,"Randy.Dunlap" writes:

Hi Chas-

What do you think of this patch?

ISTM that the result of kmem_cache_create() should be checked, and this patch looks OK to me for a loadable module (it will fail loading). But when this code is in the kernel image, will the rest of the code that depends on this kmem_cache_create() be OK, or will it try to use the kmem_cachep even though it is NULL?

Thanks,
~Randy
~~~~~~~~~~~~~~~~~~~~~~~

Begin forwarded message:

Date: Sun, 25 Jan 2004 15:07:41 +0100
From: <[email protected]>(Walter Harms)
To: <[email protected]>
Subject: [Kernel-janitors] net/atm/clip.c: check kmem_cache_create() #1

atm/clip.c 2004-01-24 12:27:57.074897464 +0100 renamed from atm/clip.c.org 2004-01-24 12:22:02.691771888 +0100 +3 -0
@@ -1026,6 +1026,9 @@
       clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
           clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
 
+       if (!clip_tbl.kmem_cachep)
+               return -1;
+
       /* so neigh_ifdown() doesn't complain */
       clip_tbl.proxy_timer.data = 0;
       clip_tbl.proxy_timer.function = 0;

_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors

--
~Randy
kernel-janitors project: http://janitor.kernelnewbies.org/

#2 lore raw

chas williams <[email protected]> :

Quoted 1 line

randy, i think it should probably return -ENOMEM instead of -1.

One should probably apply the following patch on top of it btw.

Unbalanced call to create_proc_entry() on error path.

 net/atm/clip.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)
net/atm/clip.c renamed from net/atm/clip.c~clip-procfs-leak +3 -1
diff -puN net/atm/clip.c~clip-procfs-leak net/atm/clip.c
@@ -1021,8 +1021,10 @@ static int __init atm_clip_init(void)
 	clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
 	    clip_tbl.entry_size, 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
 
-	if (!clip_tbl.kmem_cachep)
+	if (!clip_tbl.kmem_cachep) {
+		remove_proc_entry("arp", atm_proc_root);
 		return -ENOMEM;
+	}
 
 	/* so neigh_ifdown() doesn't complain */
 	clip_tbl.proxy_timer.data = 0;

_

#3 lore raw

In message <[email protected]>,Francois Romieu w rites:

Quoted 2 lines

One should probably apply the following patch on top of it btw. Unbalanced call to create_proc_entry() on error path.

how about the following instead? we probably shouldnt register the proc entry until clip_tbl is going to be ready for use anyway (the arp table iterators should probably also use clip_tbl instead of clip_tbl_hook).

===== net/atm/clip.c 1.30 vs edited =====

net/atm/clip.c +10 -8
@@ -1008,14 +1008,6 @@
 
 static int __init atm_clip_init(void)
 {
-#ifdef CONFIG_PROC_FS
-	struct proc_dir_entry *p;
-
-	p = create_proc_entry("arp", S_IRUGO, atm_proc_root);
-	if (p)
-		p->proc_fops = &arp_seq_fops;
-#endif
-
 	/* we should use neigh_table_init() */
 	clip_tbl.lock = RW_LOCK_UNLOCKED;
 	clip_tbl.kmem_cachep = kmem_cache_create(clip_tbl.id,
@@ -1032,6 +1024,16 @@
 
 	clip_tbl_hook = &clip_tbl;
 	register_atm_ioctl(&clip_ioctl_ops);
+
+#ifdef CONFIG_PROC_FS
+{
+	struct proc_dir_entry *p;
+
+	p = create_proc_entry("arp", S_IRUGO, atm_proc_root);
+	if (p)
+		p->proc_fops = &arp_seq_fops;
+}
+#endif
 
 	return 0;
 }
#4 lore raw

chas williams <[email protected]> :
[...]

Quoted 1 line

how about the following instead? we probably shouldnt register the

As long as the ugly-ifdef patrol does not bite, it's fine with me. :o)

Quoted 3 lines

proc entry until clip_tbl is going to be ready for use anyway (the arp table iterators should probably also use clip_tbl instead of clip_tbl_hook).

It would not hurt. Do you have a specific race in mind before I send an update on top your patch for the clip_tbl_hook -> clip_tbl change ?

--
Ueimor

#5 lore raw

In message <[email protected]>,Francois Romieu wr ites:

Quoted 1 line

As long as the ugly-ifdef patrol does not bite, it's fine with me. :o)

it would less ugly if people could accept a possibly unused stack variable for the !CONFIG_PROC_FS case.

Quoted 2 lines

It would not hurt. Do you have a specific race in mind before I send an update on top your patch for the clip_tbl_hook -> clip_tbl change ?

no particular race. just that the arp /proc entry should not be available until clip gets initialized. clip_tbl_hook should only be used by net/ipv4/arp.c really.

#6 lore raw
In reply to chas williams (contractor)
Quoted 3 lines · On Wed, 04 Feb 2004 14:04:17 -0500 chas williams (contractor)…

randy, i think it should probably return -ENOMEM instead of -1.

dave, please apply the following to both the 2.6 and 2.4 trees.

Applied, thanks guys.