Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751738AbdIUPXt (ORCPT ); Thu, 21 Sep 2017 11:23:49 -0400 Received: from resqmta-po-08v.sys.comcast.net ([96.114.154.167]:35678 "EHLO resqmta-po-08v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751652AbdIUPXs (ORCPT ); Thu, 21 Sep 2017 11:23:48 -0400 Date: Thu, 21 Sep 2017 10:23:45 -0500 (CDT) From: Christopher Lameter X-X-Sender: cl@nuc-kabylake To: Kees Cook cc: linux-kernel@vger.kernel.org, David Windsor , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Laura Abbott , Ingo Molnar , Mark Rutland , linux-mm@kvack.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, kernel-hardening@lists.openwall.com Subject: Re: [PATCH v3 02/31] usercopy: Enforce slab cache usercopy region boundaries In-Reply-To: <1505940337-79069-3-git-send-email-keescook@chromium.org> Message-ID: References: <1505940337-79069-1-git-send-email-keescook@chromium.org> <1505940337-79069-3-git-send-email-keescook@chromium.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-CMAE-Envelope: MS4wfFn7AqO6rWFW6ppxsCVMoLxVfkDALygboEJgOJpCzPopLlB+ixGyoo9yTAbC6sMC6npdq40qXy0lXXeqHnsCmOAUnaHEJ0+8uxq40Esjyxs3EdKxtBgW 328YlSD+agDN2i2a/p19lAFf4jy83glxWdU/0cN0L6ZiFHnEF3NOFT1+OM75XJ4vAwHYvqXUGAYLC3r/ilAzDEdjrUNVL7uLs67ff8X9PyIgg5TCnPdEZuNv pLrfyeJsxbVW3XXnB2wL4/FJqAnfDG8Br/eSW79pH1g2qpkSEegfu4HKnccryIJe3JWJS6g9tAOenjtPeiX1jkyH6LrZoIcirGDeX3eAYjYnOjxROGSSuPGq b+8Hclcjy0O1Fiuu+6XCkhIkJio5j8C9uSEloIjD+sBOMjwK1lKGcGShTnGJ8DxaYM+WWk97/Gk2dKJe3phL75pwGeMvkJrCSCI5mncIJUOK8MOAUr/cuK7e uopi9dTLhaaGdRP90aqiz4fr5933iJ0wxqEUG9MiUwPZMAGPgEaaniNb7/HTre1nMBL12CMQsLPOzDBpsH5kIv/gJGh+BaYlSNVPhOV0ArCpYAuKudG08c1H i9N3iI6p1Zb/kigeSaZbaatSTxPVVT4GVleIlxAPBTVkRmvljI/jHsh+ydjS0w66Ywo= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1448 Lines: 39 On Wed, 20 Sep 2017, Kees Cook wrote: > diff --git a/mm/slab.c b/mm/slab.c > index 87b6e5e0cdaf..df268999cf02 100644 > --- a/mm/slab.c > +++ b/mm/slab.c > @@ -4408,7 +4408,9 @@ module_init(slab_proc_init); > > #ifdef CONFIG_HARDENED_USERCOPY > /* > - * Rejects objects that are incorrectly sized. > + * Rejects incorrectly sized objects and objects that are to be copied > + * to/from userspace but do not fall entirely within the containing slab > + * cache's usercopy region. > * > * Returns NULL if check passes, otherwise const char * to name of cache > * to indicate an error. > @@ -4428,11 +4430,15 @@ const char *__check_heap_object(const void *ptr, unsigned long n, > /* Find offset within object. */ > offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep); > > - /* Allow address range falling entirely within object size. */ > - if (offset <= cachep->object_size && n <= cachep->object_size - offset) > - return NULL; > + /* Make sure object falls entirely within cache's usercopy region. */ > + if (offset < cachep->useroffset) > + return cachep->name; > + if (offset - cachep->useroffset > cachep->usersize) > + return cachep->name; > + if (n > cachep->useroffset - offset + cachep->usersize) > + return cachep->name; > > - return cachep->name; > + return NULL; > } > #endif /* CONFIG_HARDENED_USERCOPY */ Looks like this is almost the same for all allocators. Can we put this into mm/slab_common.c?