2.4.18/2.5.24 kernel/module.c - minor bugs

2.4.18/2.5.24 kernel/module.c - minor bugs

Post by Peter Oberparleite » Tue, 09 Jul 2002 17:40:07



Hi,

this patch fixes two minor bugs in kernel/module.c in current linux
kernel versions (2.4.18/2.5.24) which could cause problems in some
rare situations:

1. A size-check in sys_create_module is off by one. The check reads

        if (size < sizeof(struct module)+namelen) {
                error = -EINVAL;
                goto err1;
        }

while a subsequent write to a "size"-long buffer expects one more
byte ("mod" being the buffer pointer of type struct module*):

        memcpy((char*)(mod+1), name, namelen+1);

2. In case "struct module" used by insmod is larger than the one used
by the kernel (e.g. newer version), module loading will fail.

This is because sys_create_module initializes the module buffer with

                      0:  struct module
  sizeof(struct module):  char[] module_name

while sys_init_module copies the insmod-provided "struct module" data into
this buffer, overwriting the adjacent module name with the extra "struct
module" fields. As a result, the following sanity check will fail

        if (namelen != n_namelen || strcmp(n_name, mod_tmp.name) != 0) {
                printk(KERN_ERR "init_module: changed module name to "
                                "%s' from %s'\n",
                       n_name, mod_tmp.name);
                goto err3;
        }

because mod_tmp.name points to the overwritten module name.

This can be easily fixed using the already existing copy of the module name
in "name_tmp".

Following is the patch implementing these two fixes (diff against 2.4.17,
works for 2.4.18, 2.5.24):

========================================
--- linux-2.4.17/kernel/module.c        Sun Nov 11 20:23:14 2001

                error = namelen;
                goto err0;
        }
-       if (size < sizeof(struct module)+namelen) {
+       if (size < sizeof(struct module)+namelen+1) {
                error = -EINVAL;
                goto err1;

                error = n_namelen;
                goto err2;
        }
-       if (namelen != n_namelen || strcmp(n_name, mod_tmp.name) != 0) {
+       if (namelen != n_namelen || strcmp(n_name, name_tmp) != 0) {
                printk(KERN_ERR "init_module: changed module name to "
                                "`%s' from `%s'\n",
-                      n_name, mod_tmp.name);
+                      n_name, name_tmp);
                goto err3;
        }

========================================

Regards,
  Peter Oberparleiter
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

2.4.18/2.5.24 kernel/module.c - minor bugs

Post by Keith Owen » Tue, 09 Jul 2002 20:10:06


On Mon, 8 Jul 2002 10:27:50 +0200,


>this patch fixes two minor bugs in kernel/module.c in current linux
>kernel versions (2.4.18/2.5.24) which could cause problems in some
>rare situations:
>1. A size-check in sys_create_module is off by one. The check reads
>2. In case "struct module" used by insmod is larger than the one used
>by the kernel (e.g. newer version), module loading will fail.

Looks good.  Linus/Marcelo, please apply.

========================================
--- linux-2.4.17/kernel/module.c        Sun Nov 11 20:23:14 2001

                error = namelen;
                goto err0;
        }
-       if (size < sizeof(struct module)+namelen) {
+       if (size < sizeof(struct module)+namelen+1) {
                error = -EINVAL;
                goto err1;

                error = n_namelen;
                goto err2;
        }
-       if (namelen != n_namelen || strcmp(n_name, mod_tmp.name) != 0) {
+       if (namelen != n_namelen || strcmp(n_name, name_tmp) != 0) {
                printk(KERN_ERR "init_module: changed module name to "
                                "`%s' from `%s'\n",
-                      n_name, mod_tmp.name);
+                      n_name, name_tmp);
                goto err3;
        }

========================================

Quote:>Regards,
>  Peter Oberparleiter

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

1. khttpd module compile error with kernel 2.5.24

HI,

make[2]: Entering directory `/usr/src/linux-2.5.24/net/khttpd'
  gcc -Wp,-MD,./.rfc_time.o.d -D__KERNEL__ -I/usr/src/linux-2.5.24/include
-Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fomit-frame-pointer
-fno-strict-aliasing -fno-common -pipe -mpreferred-stack-boundary=2
-march=pentium3 -nostdinc -iwithprefix include -DMODULE
-DKBUILD_BASENAME=rfc_time   -c -o rfc_time.o rfc_time.c
rfc_time.c: In function `time_Unix2RFC':
rfc_time.c:73: `KHTTPD_NUMYEARS' undeclared (first use in this function)
rfc_time.c:73: (Each undeclared identifier is reported only once
rfc_time.c:73: for each function it appears in.)
rfc_time.c:75: `TimeDays' undeclared (first use in this function)
rfc_time.c:97: `WeekDays' undeclared (first use in this function)
rfc_time.c:109: `KHTTPD_YEAROFFSET' undeclared (first use in this
function)
rfc_time.c: In function `mimeTime_to_UnixTime':
rfc_time.c:220: `KHTTPD_YEAROFFSET' undeclared (first use in this
function)
rfc_time.c:223: `TimeDays' undeclared (first use in this function)
make[2]: *** [rfc_time.o] Error 1

Hope this helps.

Luigi

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. Ready For Linux? Read

3. Linux Kernel Crash - Vanilla 2.4.18/Redhat 2.4.18-5

4. ipchains-firewall 1.6 problem

5. Linux Kernel Crash - Vanilla 2.4.18/Redhat 2.4.18-5 (2nd try =) )

6. loopback virtual filesystem?

7. nvidia 2960 kernel driver and kernel 2.5.24

8. pthread, need help

9. bug in 2.4.18 (xfs tree), kernel BUG at page_alloc.c:82!

10. writting kernel modules on redhat 7.3 linux kernel 2.4.18-3

11. what is the difference between 2.4.18-14 and 2.4.18-17.8.0

12. Very High Load on Disk Activity in 2.4.18 (and 2.4.18-pre8)

13. Problem: SCSI (initio 9100u) and kernel 2.5.24