sock filter: fix copy of filter from userspace
Subsystems (4)
PATCH 1/1 sock filter: fix copy of filter from userspace
The sk_unattached_filter_create function is passed a socket filter structure and the copies the contents of the filter from userspace. Sparse detected that this code was incorrectly using memcpy when it needed to use copy_from_user instead.
The only use of sk_unattached_filter_create at present is in the team driver.
net/core/filter.c +3 -1
@@ -666,7 +666,9 @@ int sk_unattached_filter_create(struct s fp =kmalloc (fsize +sizeof (*fp),GFP_KERNEL );if (!fp)return -ENOMEM ; -memcpy (fp->insns, fprog->filter, fsize); + +if (copy_from_user (fp->insns, fprog->filter, fsize)) +return -EFAULT ;atomic_set (&fp->refcnt,1 ); fp->len = fprog->len;
Quoted 4 lines · Sat, Oct 13, 2012 at 08:40:32PM CEST, [email protected] wrote:
The
sk_unattached_filter_createfunction is passed a socket filter structure and the copies the contents of the filter from userspace. Sparse detected that this code was incorrectly using memcpy when it needed to usecopy_from_userinstead.
Hmm. fprog->filter is in this case allocated and filled in kernel. So memcpy is good.
Not sure how to handle this correctly. Either we remove "__user" or we redefine "struct sock_fprog" for sk_unattached_filter_create() use.
Any thoughts?
Quoted 24 lines
The only use of
sk_unattached_filter_createat present is in the team driver.Signed-off-by Stephen Hemminger <[email protected]>net/core/filter.c +3
-2@@ -666,7 +666,9 @@ int sk_unattached_filter_create(struct s fp =kmalloc (fsize +sizeof (*fp),GFP_KERNEL );if (!fp)return -ENOMEM ; -memcpy (fp->insns, fprog->filter, fsize); + +if (copy_from_user (fp->insns, fprog->filter, fsize)) +return -EFAULT ;atomic_set (&fp->refcnt,1 ); fp->len = fprog->len; --To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · On Sat, 13 Oct 2012 21:19:49 +0200 Jiri Pirko <[email protected]> wrote:
Quoted 4 lines · Sat, Oct 13, 2012 at 08:40:32PM CEST, [email protected] wrote:
The
sk_unattached_filter_createfunction is passed a socket filter structure and the copies the contents of the filter from userspace. Sparse detected that this code was incorrectly using memcpy when it needed to usecopy_from_userinstead.
Quoted 7 lines
Hmm.
fprog->filteris in this case allocated and filled in kernel. So memcpy is good.Not sure how to handle this correctly. Either we remove "
__user" or we redefine "structsock_fprog" forsk_unattached_filter_create()use.Any thoughts?
Or define a different structure for kernel usage versus userspace API.