2.1.11 breaks module support (long)

Ion Badulescu (ionut@moisil.wal.rhno.columbia.edu)
Tue, 19 Nov 1996 01:41:31 -0500 (EST)


Several functions throughout kernel/module.c expect get_mod_name() to
return 0 on success, while it in fact returns the length of the name or
-EFAULT if the pointer is bogus. The result is funny messages from
insmod, like:

init_module: Bad font file format

The fix is obvious, simply change `!= 0' to `< 0' wherever the result of
get_mod_name() is being tested in module.c

HOWEVER, this does not fix the modules on my system, and I'd like to know
why, as it doesn't make any sense. get_mod_name() supposedly returns a
number between 0 and 64 on success; how in the *** can it return the
number of characters in the name minus 64?!?! I tested it by changing the
function to:

inline int
get_mod_name(char *user_name, char *buf)
{
/* Should return -EBIG instead of -EFAULT when the name
is too long, but that we couldn't detect real faults then.
Maybe strncpy_from_user() should return -EBIG, when
the source string is too long. */
int result;
result = strncpy_from_user(buf, user_name, MOD_MAX_NAME);
printk("Module name: %s, result: %d", buf, result);
return result;
}

and this is what I get in the logs:

Nov 19 00:42:24 moisil kernel: Module name: floppy, result: 6
Nov 19 00:42:24 moisil kernel: Module name: floppy, result: -58
Nov 19 00:42:24 moisil kernel: Module name: floppy, result: 6
Nov 19 00:42:24 moisil kernel: Module name: floppy, result: 6
Nov 19 00:42:24 moisil kernel: Module name: floppy, result: -58
Nov 19 00:42:24 moisil kernel: Module name: floppy, result: 6
Nov 19 00:42:25 moisil kernel: Module name: sound, result: 5
Nov 19 00:42:25 moisil kernel: Module name: sound, result: -59
Nov 19 00:42:25 moisil kernel: Module name: sound, result: 5
Nov 19 00:42:25 moisil last message repeated 2 times
Nov 19 00:42:25 moisil kernel: Module name: sound, result: -59
Nov 19 00:42:25 moisil kernel: Module name: sound, result: 5

Moreover, it does not appear to be a gcc/as bug, as the code dissasembled
from vmlinux looks ok to me (this is get_mod_name with the inlined
strncpy_from_user):

c0114800 <get_mod_name> pushl %ebp
c0114801 <get_mod_name+1> pushl %edi
c0114802 <get_mod_name+2> pushl %esi
c0114803 <get_mod_name+3> pushl %ebx
c0114804 <get_mod_name+4> movl 0x14(%esp,1),%ecx
c0114808 <get_mod_name+8> movl 0x18(%esp,1),%ebp
c011480c <get_mod_name+c> movl $0x40,%edx
c0114811 <get_mod_name+11> movl $0xfffffff2,%ebx
c0114816 <get_mod_name+16> movl 0xc01a815c,%eax
c011481b <get_mod_name+1b> testb $0x3,0x314(%eax)
c0114822 <get_mod_name+22> je c011482c <get_mod_name+2c>
c0114824 <get_mod_name+24> cmpl $0xbfffffff,%ecx
c011482a <get_mod_name+2a> ja c0114841 <get_mod_name+41>
c011482c <get_mod_name+2c> movl %edx,%ebx
c011482e <get_mod_name+2e> movl %ecx,%esi
c0114830 <get_mod_name+30> movl %ebp,%edi
c0114832 <get_mod_name+32> testl %edx,%edx
c0114834 <get_mod_name+34> je c0114841 <get_mod_name+41>
c0114836 <get_mod_name+36> lodsb %ds:(%esi),%al
c0114837 <get_mod_name+37> stosb %al,%es:(%edi)
c0114838 <get_mod_name+38> testb %al,%al
c011483a <get_mod_name+3a> je c011483f <get_mod_name+3f>
c011483c <get_mod_name+3c> decl %edx
c011483d <get_mod_name+3d> jne c0114836 <get_mod_name+36>
c011483f <get_mod_name+3f> subl %edx,%ebx
c0114841 <get_mod_name+41> pushl %ebx
c0114842 <get_mod_name+42> pushl %ebp
c0114843 <get_mod_name+43> pushl $0xc0181de7
c0114848 <get_mod_name+48> call c0112d30 <printk>
c011484d <get_mod_name+4d> movl %ebx,%eax
c011484f <get_mod_name+4f> addl $0xc,%esp
c0114852 <get_mod_name+52> popl %ebx
c0114853 <get_mod_name+53> popl %esi
c0114854 <get_mod_name+54> popl %edi
c0114855 <get_mod_name+55> popl %ebp
c0114856 <get_mod_name+56> ret
c0114857 <get_mod_name+57> nop

How can ebx be -58 or -59 at the time printk gets called remains a mistery
to me...

Now the funny part: inserting a printk into strncpy_from_user (a painful
thing to do, since the function is called _a_lot_), which basically
duplicates the sequence calling printk (yes, I did disassemble it) makes
everything work just fine! Modules get inserted and removed like a charm..

Ionut

--
Ionut Badulescu - Columbia College '98	    E-mail:ib42@columbia.edu
Phone: (212)853-7875			    Snail mail: 4A4 Wallach Hall
Fax: (212)695-5560					1116 Amsterdam Ave
PGP key available on request				New York, NY 10027
  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.