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] [day] [month] [year] [list]
Message-ID: 
 <PH0PR18MB44748039C05AE91AAD2DB514DEE32@PH0PR18MB4474.namprd18.prod.outlook.com>
Date: Tue, 14 May 2024 09:26:07 +0000
From: Hariprasad Kelam <hkelam@...vell.com>
To: Wei Fang <wei.fang@....com>, "davem@...emloft.net" <davem@...emloft.net>,
        "edumazet@...gle.com" <edumazet@...gle.com>,
        "kuba@...nel.org"
	<kuba@...nel.org>,
        "pabeni@...hat.com" <pabeni@...hat.com>,
        Shenwei Wang
	<shenwei.wang@....com>,
        Clark Wang <xiaoning.wang@....com>,
        "richardcochran@...il.com" <richardcochran@...il.com>,
        "andrew@...n.ch"
	<andrew@...n.ch>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "imx@...ts.linux.dev" <imx@...ts.linux.dev>
Subject: RE: [PATCH net] net: fec: avoid lock evasion when reading pps_enable


> > -----Original Message-----
> > From: Hariprasad Kelam <hkelam@...vell.com>
> > Sent: 2024年5月13日 17:27
> > To: Wei Fang <wei.fang@....com>; davem@...emloft.net;
> > edumazet@...gle.com; kuba@...nel.org; pabeni@...hat.com; Shenwei
> Wang
> > <shenwei.wang@....com>; Clark Wang <xiaoning.wang@....com>;
> > richardcochran@...il.com; andrew@...n.ch; netdev@...r.kernel.org
> > Cc: linux-kernel@...r.kernel.org; imx@...ts.linux.dev
> > Subject: [PATCH net] net: fec: avoid lock evasion when reading
> > pps_enable
> >
> > See inline,
> >
> > > The assignment of pps_enable is protected by tmreg_lock, but the
> > > read operation of pps_enable is not. So the Coverity tool reports a
> > > lock evasion warning which may cause data race to occur when running
> > > in a multithread environment. Although this issue is almost
> > > impossible to occur, we'd better fix it, at least it seems more
> > > logically reasonable, and it also prevents Coverity from continuing to issue
> warnings.
> > >
> > > Fixes: 278d24047891 ("net: fec: ptp: Enable PPS output based on ptp
> > > clock")
> > > Signed-off-by: Wei Fang <wei.fang@....com>
> > > ---
> > >  drivers/net/ethernet/freescale/fec_ptp.c | 8 +++++---
> > >  1 file changed, 5 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/freescale/fec_ptp.c
> > > b/drivers/net/ethernet/freescale/fec_ptp.c
> > > index 181d9bfbee22..8d37274a3fb0 100644
> > > --- a/drivers/net/ethernet/freescale/fec_ptp.c
> > > +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> > > @@ -104,14 +104,16 @@ static int fec_ptp_enable_pps(struct
> > > fec_enet_private *fep, uint enable)
> > >  	struct timespec64 ts;
> > >  	u64 ns;
> > >
> > > -	if (fep->pps_enable == enable)
> > > -		return 0;
> > > -
> > >  	fep->pps_channel = DEFAULT_PPS_CHANNEL;
> > >  	fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
> > >
> > >  	spin_lock_irqsave(&fep->tmreg_lock, flags);
> > >
> > > +	if (fep->pps_enable == enable) {
> >
> > Can we atomic_set/get instead of spin_lock here.
> >
> I'm afraid that cannot eliminate the lock evasion warning, because it's still
> possible that multithreads take the false branch of "if (fep->pps_enable ==
> enable)" before pps_enable is updated.
> 
> Since  in fec_ptp_enable_pps(), value of pps_enable is checked before entering the actual code changes,
  Better approach is to use atomic_read/write. This is not only for reading but for assigning the values as well.
  This way covertity wont complain.


> > Thanks,
> > Hariprasad k
> > > +		spin_unlock_irqrestore(&fep->tmreg_lock, flags);
> > > +		return 0;
> > > +	}
> > > +
> > >  	if (enable) {
> > >  		/* clear capture or output compare interrupt status if have.
> > >  		 */
> > > --
> > > 2.34.1
> > >


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ