Update the patch per Michal's suggestion: Mark Hatle ran into a random segfault using the module-init-tools 3.12 and finally trace back to depmod.c:grab_module, which appears that the new malloc(...) setups up things, but never clears the memory that was just allocated. So this patch fix this issue by clear the newly allocated memory. Signed-off-by: Mark Hatle <mark.hatle@xxxxxxxxxxxxx> Signed-off-by: Yu Ke <ke.yu@xxxxxxxxx> >From Yocto Project (www.yoctoproject.org), project for embedded linux. diff --git a/depmod.c b/depmod.c index 647e5e6..46e03e0 100644 --- a/depmod.c +++ b/depmod.c @@ -428,8 +428,8 @@ static struct module *grab_module(const char *dirname, const char *filename) { struct module *new; - new = NOFAIL(malloc(sizeof(*new) - + strlen(dirname?:"") + 1 + strlen(filename) + 1)); + new = NOFAIL(calloc(sizeof(*new) + + strlen(dirname?:"") + 1 + strlen(filename) + 1, 1)); if (dirname) sprintf(new->pathname, "%s/%s", dirname, filename); else -----Original Message----- From: Michal Marek [mailto:mmarek@xxxxxxx] Sent: Monday, June 13, 2011 5:09 PM To: Yu, Ke Cc: linux-modules@xxxxxxxxxxxxxxx; jcm@xxxxxxxxxxxxxx; 'mark.hatle@xxxxxxxxxxxxx' Subject: Re: [PATCH] depmod: clear allocated memory to avoid random segfault On 13.6.2011 10:55, Yu, Ke wrote: > Mark Hatle ran into a random segfault using the module-init-tools > 3.12 and finally trace back to depmod.c:grab_module, which appears > that the new malloc(...) setups up things, but never clears the memory that was just allocated. > > So this patch fix this issue by clear the newly allocated memory. > > Signed-off-by: Mark Hatle<mark.hatle@xxxxxxxxxxxxx> > Signed-off-by: Yu Ke<ke.yu@xxxxxxxxx> > > From Yocto Project (www.yoctoproject.org), project for embedded linux. > > diff --git a/depmod.c b/depmod.c > index a1d2f8c..b450808 100644 > --- a/depmod.c > +++ b/depmod.c > @@ -430,6 +430,7 @@ static struct module *grab_module(const char > *dirname, const char *filename) > > new = NOFAIL(malloc(sizeof(*new) > + strlen(dirname?:"") + 1 + strlen(filename) + 1)); > + memset(new, 0x00, sizeof(*new) + strlen(dirname?:"") + 1 + > +strlen(filename) + 1); If you change the malloc() to calloc(), then you won't have to write the lengthy sum twice. Michal
Attachment:
module-init.patch
Description: module-init.patch