[BusyBox] insmod with uClibc mystery bugs

Erik Andersen andersen at lineo.com
Wed Apr 25 16:30:39 UTC 2001


On Tue Apr 24, 2001 at 03:26:06PM -0700, Larry Doolittle wrote:
> Erik -
> 
> > Regardless, ending up with an xmalloc(0) is sloppy.  I'll change 
> > insmod.c to do 'if (nks <= 0) ' instead to avoid the issue.
> 
> That's not exactly right, either.  The system call did not
> fail (according to the API), so errno will not be set, and
> perror_msg will give a useless and/or incorrect message.

Hmm.  I suppose we could add in an extra
        if (nks == 0) return 0;
in to cover this case.

> > > In new_get_kernel_symbols, would it be worth checking for a
> > > double-fault on query_module?  Something like
> > > 	if (errno == ENOSPC && bufsize == 256) {
> > 
> > i.e. so we only pass the goto once? [ chop ]
> > I think it should be safe as is.
> 
> I was more concerned that we or the kernel might have an
> off-by-one error (if not now, at some future patch level),
> and insmod would loop forever waiting for one more byte
> to magically appear.

Ok.  This seems more plausible

> How about
> 	if (errno == ENOSPC && bufsize < ret) {
> ?

This looks fairly pain free.  So something like:

--- insmod.c	2001/04/24 21:41:41	1.58
+++ insmod.c	2001/04/25 16:30:07
@@ -1787,6 +1787,7 @@ static int old_get_kernel_symbols(const 
 
 	nks = get_kernel_syms(NULL);
 	if (nks <= 0) {
+		if (nks)
 		perror_msg("get_kernel_syms: %s", m_name);
 		return 0;
 	}
@@ -2277,7 +2278,7 @@ static int new_get_kernel_symbols(void)
 	module_names = xmalloc(bufsize = 256);
   retry_modules_load:
 	if (query_module(NULL, QM_MODULES, module_names, bufsize, &ret)) {
-		if (errno == ENOSPC) {
+		if (errno == ENOSPC && bufsize < ret) {
 			module_names = xrealloc(module_names, bufsize = ret);
 			goto retry_modules_load;
 		}
@@ -2338,7 +2339,7 @@ static int new_get_kernel_symbols(void)
 	syms = xmalloc(bufsize = 16 * 1024);
   retry_kern_sym_load:
 	if (query_module(NULL, QM_SYMBOLS, syms, bufsize, &ret)) {
-		if (errno == ENOSPC) {
+		if (errno == ENOSPC && bufsize < ret) {
 			syms = xrealloc(syms, bufsize = ret);
 			goto retry_kern_sym_load;
 		}

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--





More information about the busybox mailing list