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]
Date:   Fri, 20 May 2022 14:40:59 +0200
From:   Andrew Lunn <andrew@...n.ch>
To:     Pavel Skripkin <paskripkin@...il.com>
Cc:     vladimir.oltean@....com, claudiu.manoil@....com,
        alexandre.belloni@...tlin.com, UNGLinuxDriver@...rochip.com,
        davem@...emloft.net, kuba@...nel.org, pabeni@...hat.com,
        dan.carpenter@...cle.com, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: ocelot: fix wront time_after usage

On Thu, May 19, 2022 at 11:40:17PM +0300, Pavel Skripkin wrote:
> Accidentally noticed, that this driver is the only user of
> while (timer_after(jiffies...)).
> 
> It looks like typo, because likely this while loop will finish after 1st
> iteration, because time_after() returns true when 1st argument _is after_
> 2nd one.
> 
> Fix it by negating time_after return value inside while loops statement

A better fix would be to use one of the helpers in linux/iopoll.h.

There is a second bug in the current code:

static int ocelot_fdma_wait_chan_safe(struct ocelot *ocelot, int chan)
{
	unsigned long timeout;
	u32 safe;

	timeout = jiffies + usecs_to_jiffies(OCELOT_FDMA_CH_SAFE_TIMEOUT_US);
	do {
		safe = ocelot_fdma_readl(ocelot, MSCC_FDMA_CH_SAFE);
		if (safe & BIT(chan))
			return 0;
	} while (time_after(jiffies, timeout));

	return -ETIMEDOUT;
}

The scheduler could put the thread to sleep, and it does not get woken
up for OCELOT_FDMA_CH_SAFE_TIMEOUT_US. During that time, the hardware
has done its thing, but you exit the while loop and return -ETIMEDOUT.

linux/iopoll.h handles this correctly by testing the state one more
time after the timeout has expired.

  Andrew

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ