Re: user pointers and race conditions

From: David Miller
Date: Thu May 17 2007 - 01:06:41 EST


From: sk b <skb300@xxxxxxxxxxx>
Date: Wed, 16 May 2007 22:56:22 -0600

> 3: if (!access_ok(VERIFY_READ,stp,sizeof(struct st)))
> 4: return;
> 5: if (!access_ok(VERIFY_WRITE,stp->u,sizeof(int)))
> 6: return;

This code would not exist in the kernel, the kernel cannot dereference
stp->u. The stp->u dereference would silently work on x86 and x86_64
but it would generate an exception on sparc64 and other platforms.

User space accesses must go through the proper copy_from_user(),
copy_to_user, get_user(), and put_user() interfaces.

It must first copy stp into a local kernel space copy, then it may
inspect the value of stp->u.

And yes sparse would catch this problem in your code, because the
"__user" annotations would catch the illegal "stp->u" dereference.
-
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/