Re: [PATCH v3] kernel/module: Fix mem leak in module_add_modinfo_attrs

From: Miroslav Benes
Date: Tue Jun 04 2019 - 10:19:37 EST


> >> -static void module_remove_modinfo_attrs(struct module *mod)
> >> +static void module_remove_modinfo_attrs(struct module *mod, int end)
> >> {
> >> struct module_attribute *attr;
> >> int i;
> >>
> >> for (i = 0; (attr = &mod->modinfo_attrs[i]); i++) {
> >> + if (end >= 0 && i > end)
> >> + break;
> >
> > If end == 0, you break the loop without calling sysfs_remove_file(), which
> > is a bug if you called module_remove_modinfo_attrs(mod, 0).
>
> If end == 0 and i == 0, if statement is false, it won't break the loop.

Eh, you're right of course.

Miroslav