Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Oct 2003 10:30:59 +0200
From:      Pawel Jakub Dawidek <nick@garage.freebsd.pl>
To:        freebsd-hackers@freebsd.org
Cc:        rwatson@freebsd.org
Subject:   Dynamic reads without locking.
Message-ID:  <20031008083059.GA520@garage.freebsd.pl>

next in thread | raw e-mail | index | archive | help

--JAtnJwvplI04zgov
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello hackers...

I'm wondering...
Jeffrey Hsu was talking about this at BSDCon03.
There is no need to lock data when we just made simple read, for example:

	mtx_lock(&foo_mtx);
	foo =3D 5;
	mtx_unlock(&foo_mtx);
but only:
	bar =3D foo;

IMHO this is quite dangerous.
Let's see:

	thread1			thread2
	mtx_lock(&foo_mtx);
	foo =3D data_from_user;
				bar =3D foo;
	foo &=3D MASK;
	mtx_unlock(&foo_mtx);

In this case we have really dangerous race if data from user are
safe only when we made 'and' operation on them.
OR of course we can just store wrong value in 'bar' and this could
be case of different problems.

So I'm not sure now if I understand everything well. We can't just say
'We never split such writes. We always do: foo =3D (data_from_user & MASK)',
because author of some 3rd party kernel module will be sure that when
he locks writes to some variable this operation is safe and he could
split such writes and in kernel could be dynamic read without lock.

Does this make any sense?

--=20
Pawel Jakub Dawidek                       pawel@dawidek.net
UNIX Systems Programmer/Administrator     http://garage.freebsd.pl
Am I Evil? Yes, I Am!                     http://cerber.sourceforge.net

--JAtnJwvplI04zgov
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (FreeBSD)

iQCVAwUBP4PLQz/PhmMH/Mf1AQGI2AP+L4sKXqGib5doLjD3Q326HpaXW7IB8nSE
PwX73LSV0TWtIHKLkidGr7JifOnk5TWmdkKJtKYu2nNkX28zUCanIzvlFi24r98q
l8dtHmNzTpkZKyPlMwafDMo0CwQqLJS/Bvvgu3PYnTyshFuMYW5WLolueB5ORrFg
YRC/o414IIg=
=srlU
-----END PGP SIGNATURE-----

--JAtnJwvplI04zgov--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031008083059.GA520>