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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200107074414.GA1015576@kroah.com>
Date:   Tue, 7 Jan 2020 08:44:14 +0100
From:   Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To:     Uwe Kleine-König 
        <u.kleine-koenig@...gutronix.de>
Cc:     Pavel Machek <pavel@...x.de>,
        Jacek Anaszewski <jacek.anaszewski@...il.com>,
        Dan Murphy <dmurphy@...com>, Jiri Slaby <jslaby@...e.com>,
        kernel@...gutronix.de, linux-kernel@...r.kernel.org,
        linux-leds@...r.kernel.org, linux-serial@...r.kernel.org
Subject: Re: [PATCH v5 3/3] leds: trigger: implement a tty trigger

On Tue, Jan 07, 2020 at 08:29:42AM +0100, Uwe Kleine-König wrote:
> On Mon, Jan 06, 2020 at 07:59:18PM +0100, Greg Kroah-Hartman wrote:
> > On Mon, Dec 23, 2019 at 11:08:28AM +0100, Uwe Kleine-König wrote:
> > > Hello Pavel,
> > > 
> > > On Sat, Dec 21, 2019 at 07:40:47PM +0100, Pavel Machek wrote:
> > > > > +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-tty
> > > > > @@ -0,0 +1,6 @@
> > > > > +What:		/sys/class/leds/<led>/dev
> > > > > +Date:		Dec 2019
> > > > > +KernelVersion:	5.6
> > > > > +Contact:	linux-leds@...r.kernel.org
> > > > > +Description:
> > > > > +		Specifies $major:$minor of the triggering tty
> > > > 
> > > > Ok, sounds reasonable.
> > > > 
> > > > > +static ssize_t dev_store(struct device *dev,
> > > > > +			 struct device_attribute *attr, const char *buf,
> > > > > +			 size_t size)
> > > > > +{
> > > > > +	struct ledtrig_tty_data *trigger_data = led_trigger_get_drvdata(dev);
> > > > > +	struct tty_struct *tty;
> > > > > +	unsigned major, minor;
> > > > > +	int ret;
> > > > > +
> > > > > +	if (size == 0 || (size == 1 && buf[0] == '\n')) {
> > > > > +		tty = NULL;
> > > > > +	} else {
> > > > > +		ret = sscanf(buf, "%u:%u", &major, &minor);
> > > > > +		if (ret < 2)
> > > > > +			return -EINVAL;
> > > > 
> > > > If user writes 1:2:badparsingofdata into the file, it will pass, right?
> > > 
> > > Yes, and it will have the same effect as writing 1:2. I wonder if this
> > > is bad.
> > > 
> > > > > +		tty = tty_kopen_shared(MKDEV(major, minor));
> > > > > +		if (IS_ERR(tty))
> > > > > +			return PTR_ERR(tty);
> > > > > +	}
> > > > 
> > > > Do you need to do some kind of tty_kclose()? What happens if the
> > > > device disappears, for example because the USB modem is unplugged?
> > > 
> > > Only tty_kref_put is needed to close.
> > > 
> > > > > +static void ledtrig_tty_work(struct work_struct *work)
> > > > > +{
> > > > > +	struct ledtrig_tty_data *trigger_data =
> > > > > +		container_of(work, struct ledtrig_tty_data, dwork.work);
> > > > > +	struct serial_icounter_struct icount;
> > > > > +	int ret;
> > > > > +
> > > > > +	if (!trigger_data->tty) {
> > > > > +		led_set_brightness(trigger_data->led_cdev, LED_OFF);
> > > > > +		return;
> > > > > +	}
> > > > > +
> > > > > +	ret = tty_get_icount(trigger_data->tty, &icount);
> > > > > +	if (ret)
> > > > > +		return;
> > > > > +
> > > > > +	if (icount.rx != trigger_data->rx ||
> > > > > +	    icount.tx != trigger_data->tx) {
> > > > > +		unsigned long delay_on = 100, delay_off = 100;
> > > > > +
> > > > > +		led_blink_set_oneshot(trigger_data->led_cdev,
> > > > > +				      &delay_on, &delay_off, 0);
> > > > > +
> > > > > +		trigger_data->rx = icount.rx;
> > > > > +		trigger_data->tx = icount.tx;
> > > > > +	}
> > > > 
> > > > Since you are polling this, anyway, can you just manipulate brightness
> > > > directly instead of using _oneshot()? _oneshot() will likely invoke
> > > > another set of workqueues.
> > > 
> > > I copied that from the netdev trigger. I failed to find a suitable
> > > helper function, did I miss that or does it need creating?
> > >  
> > > > LED triggers were meant to operate directly from the events, not based
> > > > on statistics like this.
> > > 
> > > Ditto; just copied from the netdev trigger. I tried to find a suitable
> > > place to add a trigger in the core, but this is hard without having to
> > > modify all drivers; additionally this is in thier hot path. So I
> > > considered using statistics a good idea. Greg also liked it and someone
> > > before us for the network trigger, too ...
> > 
> > This still looks ok to me, any objections to me merging it in my tty
> > tree?
> 
> Thanks for caring. If Pavel objects in principle to using statistics to
> trigger the trigger, there will be no user of the new tty functions. I
> don't care much about this, so feel free to apply the tty part, but I
> would have expected that "no user" would be a stopper.

Yes, "no user" would prevent me from merging this series, but I like the
"user" of this api, so would be glad to merge it at the same time.

thanks,

greg k-h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ