cpuset: zero malloc - revert the old cpuset fix
cpuset: zero malloc - revert the old cpuset fix

The cpuset code to present a list of tasks using a cpuset to user space could
write to an array that it had kmalloc'd, after a kmalloc request of zero size.

The problem was that the code didn't check for writes past the allocated end
of the array until -after- the first write.

This is a race condition that is likely rare -- it would only show up if a
cpuset went from being empty to having a task in it, during the brief time
between the allocation and the first write.

Prior to roughly 2.6.22 kernels, this was also a benign problem, because a
zero kmalloc returned a few usable bytes anyway, and no harm was done with the
bogus write.

With the 2.6.22 kernel changes to make issue a warning if code tries to write
to the location returned from a zero size allocation, this problem is no
longer benign.  This cpuset code would occassionally trigger that warning.

The fix is trivial -- check before storing into the array, not after, whether
the array is big enough to hold the store.

Cc: "Eric W. Biederman" <8a741aa8cbd77ebc4a56ddb528ce9fd15d42f034@xmission.com>
Cc: "Serge E. Hallyn" <dd6cacb2d07f0aa354aa6e74c149a3580e5a1db1@us.ibm.com>
Cc: Balbir Singh <65a1aed538f36fed73d8c45e9ddfc585ce9f4abf@in.ibm.com>
Cc: Dave Hansen <e169c2064f54e292652f83bb35eed10e1aa33f38@us.ibm.com>
Cc: Herbert Poetzl <ef65de1c7be0aa837fe7b25ba9a7739905af6a55@13thfloor.at>
Cc: Kirill Korotaev <34c6fceca75e456f25e7e99531e2425c6c1de443@openvz.org>
Cc: Paul Menage <a4e32ff3ad614f63c49bddfcf4b7598c6857b687@google.com>
Cc: Srivatsa Vaddagiri <69d4c67d027719823df1f8f9226c47bc05dc8998@in.ibm.com>
Cc: Christoph Lameter <a2610c5c148280bb6730402b12a8276c2f194fbe@sgi.com>
Signed-off-by: Paul Jackson <223b7f0fa34cb01a774d1d81d388f8c5f831b7fc@sgi.com>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs,TeamVee-Kanas/android_kernel_samsung_kanas,KristFoundation/Programs