[{"id":1772928,"web_url":"http://patchwork.ozlabs.org/comment/1772928/","msgid":"<alpine.DEB.2.20.1709211009400.14427@nuc-kabylake>","list_archive_url":null,"date":"2017-09-21T15:21:16","subject":"Re: [PATCH v3 01/31] usercopy: Prepare for usercopy whitelisting","submitter":{"id":2224,"url":"http://patchwork.ozlabs.org/api/people/2224/","name":"Christoph Lameter (Ampere)","email":"cl@linux.com"},"content":"On Wed, 20 Sep 2017, Kees Cook wrote:\n\n> diff --git a/include/linux/stddef.h b/include/linux/stddef.h\n> index 9c61c7cda936..f00355086fb2 100644\n> --- a/include/linux/stddef.h\n> +++ b/include/linux/stddef.h\n> @@ -18,6 +18,8 @@ enum {\n>  #define offsetof(TYPE, MEMBER)\t((size_t)&((TYPE *)0)->MEMBER)\n>  #endif\n>\n> +#define sizeof_field(structure, field) sizeof((((structure *)0)->field))\n> +\n>  /**\n>   * offsetofend(TYPE, MEMBER)\n>   *\n\nHmmm.. Is that really necessary? Code knows the type of field and can\nuse sizeof type.\n\nAlso this is a non slab change hidden in the patchset.\n\n> diff --git a/mm/slab_common.c b/mm/slab_common.c\n> index 904a83be82de..36408f5f2a34 100644\n> --- a/mm/slab_common.c\n> +++ b/mm/slab_common.c\n> @@ -272,6 +272,9 @@ int slab_unmergeable(struct kmem_cache *s)\n>  \tif (s->ctor)\n>  \t\treturn 1;\n>\n> +\tif (s->usersize)\n> +\t\treturn 1;\n> +\n>  \t/*\n>  \t * We may have set a slab to be unmergeable during bootstrap.\n>  \t */\n\nThis will ultimately make all slabs unmergeable at the end of your\npatchset? Lots of space will be wasted. Is there any way to make this\nfeature optional?\n\n#ifdef CONFIG_HARDENED around this?\n\n\n> @@ -491,6 +509,15 @@ kmem_cache_create(const char *name, size_t size, size_t align,\n>  \t}\n>  \treturn s;\n>  }\n> +EXPORT_SYMBOL(kmem_cache_create_usercopy);\n> +\n> +struct kmem_cache *\n> +kmem_cache_create(const char *name, size_t size, size_t align,\n> +\t\tunsigned long flags, void (*ctor)(void *))\n> +{\n> +\treturn kmem_cache_create_usercopy(name, size, align, flags, 0, size,\n> +\t\t\t\t\t  ctor);\n> +}\n>  EXPORT_SYMBOL(kmem_cache_create);\n\nWell this makes the slab created unmergeable.\n\n> @@ -897,7 +927,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,\n>  \tif (!s)\n>  \t\tpanic(\"Out of memory when creating slab %s\\n\", name);\n>\n> -\tcreate_boot_cache(s, name, size, flags);\n> +\tcreate_boot_cache(s, name, size, flags, 0, size);\n\nOk this makes the kmalloc array unmergeable.\n\n> @@ -5081,6 +5081,12 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)\n>  SLAB_ATTR_RO(cache_dma);\n>  #endif\n>\n> +static ssize_t usersize_show(struct kmem_cache *s, char *buf)\n> +{\n> +\treturn sprintf(buf, \"%zu\\n\", s->usersize);\n> +}\n> +SLAB_ATTR_RO(usersize);\n> +\n>  static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)\n>  {\n>  \treturn sprintf(buf, \"%d\\n\", !!(s->flags & SLAB_TYPESAFE_BY_RCU));\n> @@ -5455,6 +5461,7 @@ static struct attribute *slab_attrs[] = {\n>  #ifdef CONFIG_FAILSLAB\n>  \t&failslab_attr.attr,\n>  #endif\n> +\t&usersize_attr.attr,\n\nSo useroffset is not exposed?","headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xygWt1mZpz9t4B\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri, 22 Sep 2017 01:29:30 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751809AbdIUP32 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tThu, 21 Sep 2017 11:29:28 -0400","from resqmta-po-06v.sys.comcast.net ([96.114.154.165]:36576 \"EHLO\n\tresqmta-po-06v.sys.comcast.net\" rhost-flags-OK-OK-OK-OK)\n\tby vger.kernel.org with ESMTP id S1751734AbdIUP31 (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Thu, 21 Sep 2017 11:29:27 -0400","from resomta-po-19v.sys.comcast.net ([96.114.154.243])\n\tby resqmta-po-06v.sys.comcast.net with ESMTP\n\tid v3HxdhBB7k8ktv3HzdGSDj; Thu, 21 Sep 2017 15:21:19 +0000","from gentwo.org ([98.222.162.64])\n\tby resomta-po-19v.sys.comcast.net with SMTP\n\tid v3HwdQ9v1IVAUv3HxdMAL8; Thu, 21 Sep 2017 15:21:18 +0000","by gentwo.org (Postfix, from userid 1001)\n\tid 95E3711627C8; Thu, 21 Sep 2017 10:21:16 -0500 (CDT)","from localhost (localhost [127.0.0.1])\n\tby gentwo.org (Postfix) with ESMTP id 934D711602E4;\n\tThu, 21 Sep 2017 10:21:16 -0500 (CDT)"],"Date":"Thu, 21 Sep 2017 10:21:16 -0500 (CDT)","From":"Christopher Lameter <cl@linux.com>","X-X-Sender":"cl@nuc-kabylake","To":"Kees Cook <keescook@chromium.org>","cc":"linux-kernel@vger.kernel.org, David Windsor <dave@nullcore.net>,\n\tPekka Enberg <penberg@kernel.org>, David Rientjes <rientjes@google.com>,\n\tJoonsoo Kim <iamjoonsoo.kim@lge.com>,\n\tAndrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org,\n\tlinux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,\n\tnetdev@vger.kernel.org, kernel-hardening@lists.openwall.com","Subject":"Re: [PATCH v3 01/31] usercopy: Prepare for usercopy whitelisting","In-Reply-To":"<1505940337-79069-2-git-send-email-keescook@chromium.org>","Message-ID":"<alpine.DEB.2.20.1709211009400.14427@nuc-kabylake>","References":"<1505940337-79069-1-git-send-email-keescook@chromium.org>\n\t<1505940337-79069-2-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":"MS4wfKH8NELh7QQfD08/82e65RLw3jwm1AQoxMmTP75DSM6TPp7AO4/GUTusOeClfFTRuM5p5WW3dAY80YWzCRqNxZ5WnhTAGVNHlptouBgcooh9zqIBXGCU\n\tWf1lnWWoI2jxBOCmC+gBYY3AIFAUeXwD7UHIikSozSiwrR9x4i3MYiDxN0plYQNL2rMzg5qHxL42LteWtWiiX3qfIls4pgTYVZy/5U3kp31THVOK6GWaYCRf\n\tHq2C+5vIg6uZt+wcMzn7GKkJEBNxSDNi02yAlKUzaEVK/MkpJqG+FdX12qH8vRVreBOTPZADA5heWaynE5YypVmo+QDUwM7Xsi9tyNANy/GfqlDRL3MEMZ0T\n\txWJnTYxQXkwF4D2tMNfj+Ahmc+wvhvnu75Q5q9nk5xxoSvCfCqhOJUvv6MOT+mIUGykOyZjHo7pk0kYWI0ME50e1JbqmxSwZ8YkosmCRtWMHaQRS05mnT9y7\n\t7Myf+1bv+xfukBGKsMqshpQCK6lW8O93EYeuwPcULlYkMwJoqXhF9oJdQrPy/jxU4GaxzWNIojbP1ktoIXLVYu9Clbivpi3E5P9z7g==","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"}}]