Re: [PATCH][2/2] - catch ignored copy_*_user() - fs/compat_ioctl.c

From: Ingo Oeser
Date: Sat Dec 25 2004 - 13:38:39 EST


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Jeremy,

On Saturday 25 December 2004 13:04, Jeremy Huddleston wrote:
> And one more...

Patch attached not inlined, so you have to figure yourself :-(

Could you do the "binary OR trick"?

Such that

if (__put_user() || __put_user() || __put_user()) return -EFAULT;

becomes:

err = __put_user();
err |= __put_user();
err |= __put_user();
if (err) return -EFAULT;

This saves branches, which speeds up code for the common case
and reduces size. Downside is more faults, but this hurts only for
broken software, which deserves this behavior ;-)

This optimization works only if:
- function returns either zero or exact the same value.
- we don't mind having all these other calls executed,
even if the first failed already.

Which is true for __put_user() and __get_user(),
but works the other way around for __copy_{from,to}_user().
But since 0 is succes on __copy_{from,to}_user(), you
can even do this trick there and have only ONE branch instead
of 3-6 in your code.

You'll find this pattern in many places in the Kernel.


Regards

Ingo Oeser

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBzbLGU56oYWuOrkARAlGkAJ4nm909AVDY96Q9PKE92tbGKbAUygCfT+64
oRC6L0uwFbL14o0ThhGnMY0=
=Mj1F
-----END PGP SIGNATURE-----
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/