lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 27 Sep 2019 18:59:40 +0200
From:   Pavel Machek <pavel@...x.de>
To:     Akinobu Mita <akinobu.mita@...il.com>
Cc:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-leds@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Jacek Anaszewski <jacek.anaszewski@...il.com>,
        Dan Murphy <dmurphy@...com>
Subject: Re: [PATCH v2 1/1] leds: remove PAGE_SIZE limit of
 /sys/class/leds/<led>/trigger

Hi!

> > >       down_read(&triggers_list_lock);
> > >       down_read(&led_cdev->trigger_lock);
> > >
> > > -     if (!led_cdev->trigger)
> > > -             len += scnprintf(buf+len, PAGE_SIZE - len, "[none] ");
> > > +     len = led_trigger_format(NULL, 0, true, led_cdev);
> > > +     data = kvmalloc(len + 1, GFP_KERNEL);
> >
> > Why kvmalloc() and not just kmalloc()?  How big is this buffer you are
> > expecting to have here?
> 
> The ledtrig-cpu supports upto 9999 cpus.  If all these cpus were available,
> the buffer size would be 78,890 bytes.
> (for i in `seq 0 9999`;do echo -n " cpu$i"; done | wc -c)
> 
> The intention of this kvmalloc() allocation is to avoid costly allocation
> if possible.

Sounds good.

> > > -             else
> > > -                     len += scnprintf(buf+len, PAGE_SIZE - len, "%s ",
> > > -                                      trig->name);
> > > -     }
> > >       up_read(&led_cdev->trigger_lock);
> > >       up_read(&triggers_list_lock);
> >
> > Two locks?  Why not 3?  5?  How about just 1?  :)
> 
> I don't touch these locks in this patch :)

Nor should you :-).

> > Just return -ENOMEM above if !data, which makes this much simpler.
> 
> We are holding the two locks, so we need to release them before return.
> Which one do you prefer?
> 
>         ...
>         data = kvmalloc(len + 1, GFP_KERNEL);
>         if (data)
>                 len = led_trigger_format(data, len + 1, false, led_cdev);
>         else
>                 len = -ENOMEM;
> 
>         up_read(&led_cdev->trigger_lock);
>         up_read(&triggers_list_lock);
> 
>         if (len < 0)
>                 return len;
> 
> vs.
> 
>         ...
>         data = kvmalloc(len + 1, GFP_KERNEL);
>         if (!data) {
>                 up_read(&led_cdev->trigger_lock);
>                 up_read(&triggers_list_lock);
>                 return -ENOMEM;
>         }
>         len = led_trigger_format(data, len + 1, false, led_cdev);
> 
>         up_read(&led_cdev->trigger_lock);
>         up_read(&triggers_list_lock);

Second one is better. Using goto to jump to error path doing cleanups
is also acceptable. 

Thanks,
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ