{"id":816481,"url":"http://patchwork.ozlabs.org/api/patches/816481/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1505940337-79069-17-git-send-email-keescook@chromium.org/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1505940337-79069-17-git-send-email-keescook@chromium.org>","list_archive_url":null,"date":"2017-09-20T20:45:22","name":"[v3,16/31] cifs: Define usercopy region in cifs_request slab cache","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":true,"hash":"acd253379fe4bf82e17987aee1cad14fcc959903","submitter":{"id":10641,"url":"http://patchwork.ozlabs.org/api/people/10641/?format=json","name":"Kees Cook","email":"keescook@chromium.org"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1505940337-79069-17-git-send-email-keescook@chromium.org/mbox/","series":[{"id":4231,"url":"http://patchwork.ozlabs.org/api/series/4231/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4231","date":"2017-09-20T20:45:22","name":"Hardened usercopy whitelisting","version":3,"mbox":"http://patchwork.ozlabs.org/series/4231/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816481/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816481/checks/","tags":{},"related":[],"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>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"a0KHLHew\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyBcT58M4z9s83\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 06:46:49 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751964AbdITUqT (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 20 Sep 2017 16:46:19 -0400","from mail-pg0-f41.google.com ([74.125.83.41]:55226 \"EHLO\n\tmail-pg0-f41.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751937AbdITUqP (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Wed, 20 Sep 2017 16:46:15 -0400","by mail-pg0-f41.google.com with SMTP id c137so2324312pga.11\n\tfor <netdev@vger.kernel.org>; Wed, 20 Sep 2017 13:46:15 -0700 (PDT)","from www.outflux.net\n\t(173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133])\n\tby smtp.gmail.com with ESMTPSA id\n\tp127sm8724757pfp.168.2017.09.20.13.46.02\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tWed, 20 Sep 2017 13:46:08 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=chromium.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=ErIxzF/Xu/2NZZKnHLK0hzq0ZrhO56rwZ77Q2c+O7Y8=;\n\tb=a0KHLHewgT3WMj4ycgRnE/k4/SnM1DN8iHVua9lmyyHKvZ0A41xXzJ4aN8Zybd+z9B\n\tvoMVpMmg5CmTprSBa456YJEm+i4GnjCaLuVcs5pvUjdiZROiM9dEYXNVnBr3S1PXpSEm\n\tdmEo6KYNAY9j7H0b5BbXlxAwUPpYZRoPf7sNE=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=ErIxzF/Xu/2NZZKnHLK0hzq0ZrhO56rwZ77Q2c+O7Y8=;\n\tb=BMlYMwy2J0yxj60r6APUkQ8WYnM5GC1s2kpmoQ+kuntq7UpgWZquvuhcA1aCBcNGyc\n\taOdHtmClCx0+b9z11PHNH9UMQbRCgIUBG3VENPZd8X+5MhafajGz3XC0DOpc0I8St1Ae\n\tM3vaiOvWHHU/vfAvPpniTHb7ZVaVZFNg5NIdnBIcvZvG810qExlEUj9GgyTnkUFJNdgZ\n\tBfzaVj0AdK4qxkdmVW9Yq4T0DTznN/dMSq5jMCIWfz0lKo6upStgFbLloInStJy67/WR\n\t6bvwp2zfFzoiOeLeAUxvRRgkK2fTeYY1t+wtOZFowkkBPzjUQaHhzvUejDMLBCPggeqw\n\t7dGg==","X-Gm-Message-State":"AHPjjUh54zBCoNY7oEH4GkLMbCn472i6bCCU0lCS32rsrgI1ke6zjA1X\n\tYJmJ9Zbmv0yV7eJy+IRImgNsAQ==","X-Google-Smtp-Source":"AOwi7QC3SBQuv5ScYeh+3sjLv1sAEPGXdjl2npvnYqsvYMcxH4GB0t5MmaaOjcYnGDvYZKxczcEhFg==","X-Received":"by 10.84.248.144 with SMTP id q16mr3313921pll.345.1505940374877; \n\tWed, 20 Sep 2017 13:46:14 -0700 (PDT)","From":"Kees Cook <keescook@chromium.org>","To":"linux-kernel@vger.kernel.org","Cc":"Kees Cook <keescook@chromium.org>, David Windsor <dave@nullcore.net>,\n\tSteve French <sfrench@samba.org>, linux-cifs@vger.kernel.org,\n\tlinux-fsdevel@vger.kernel.org, netdev@vger.kernel.org,\n\tlinux-mm@kvack.org, kernel-hardening@lists.openwall.com","Subject":"[PATCH v3 16/31] cifs: Define usercopy region in cifs_request slab\n\tcache","Date":"Wed, 20 Sep 2017 13:45:22 -0700","Message-Id":"<1505940337-79069-17-git-send-email-keescook@chromium.org>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1505940337-79069-1-git-send-email-keescook@chromium.org>","References":"<1505940337-79069-1-git-send-email-keescook@chromium.org>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"From: David Windsor <dave@nullcore.net>\n\nCIFS request buffers, stored in the cifs_request slab cache, need to be\ncopied to/from userspace.\n\ncache object allocation:\n    fs/cifs/cifsfs.c:\n        cifs_init_request_bufs():\n            ...\n            cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,\n                                                      cifs_req_cachep);\n\n    fs/cifs/misc.c:\n        cifs_buf_get():\n            ...\n            ret_buf = mempool_alloc(cifs_req_poolp, GFP_NOFS);\n            ...\n            return ret_buf;\n\nIn support of usercopy hardening, this patch defines a region in the\ncifs_request slab cache in which userspace copy operations are allowed.\n\nThis region is known as the slab cache's usercopy region.  Slab\ncaches can now check that each copy operation involving cache-managed\nmemory falls entirely within the slab's usercopy region.\n\nThis patch is verbatim from Brad Spengler/PaX Team's PAX_USERCOPY\nwhitelisting code in the last public patch of grsecurity/PaX based on my\nunderstanding of the code. Changes or omissions from the original code are\nmine and don't reflect the original grsecurity/PaX code.\n\nSigned-off-by: David Windsor <dave@nullcore.net>\n[kees: adjust commit log, provide usage trace]\nCc: Steve French <sfrench@samba.org>\nCc: linux-cifs@vger.kernel.org\nSigned-off-by: Kees Cook <keescook@chromium.org>\n---\nI wasn't able to actually track down the _usage_ of the cifs_request where\nit is copied to userspace. If any CIFS folks could help point that out, it\nwould be very welcome. :) I suspect it might be part of the debug routines,\nbut I never managed to exercise them.\n---\n fs/cifs/cifsfs.c | 10 ++++++----\n 1 file changed, 6 insertions(+), 4 deletions(-)","diff":"diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c\nindex 180b3356ff86..09dfdf76c738 100644\n--- a/fs/cifs/cifsfs.c\n+++ b/fs/cifs/cifsfs.c\n@@ -1229,9 +1229,11 @@ cifs_init_request_bufs(void)\n \tcifs_dbg(VFS, \"CIFSMaxBufSize %d 0x%x\\n\",\n \t\t CIFSMaxBufSize, CIFSMaxBufSize);\n */\n-\tcifs_req_cachep = kmem_cache_create(\"cifs_request\",\n+\tcifs_req_cachep = kmem_cache_create_usercopy(\"cifs_request\",\n \t\t\t\t\t    CIFSMaxBufSize + max_hdr_size, 0,\n-\t\t\t\t\t    SLAB_HWCACHE_ALIGN, NULL);\n+\t\t\t\t\t    SLAB_HWCACHE_ALIGN, 0,\n+\t\t\t\t\t    CIFSMaxBufSize + max_hdr_size,\n+\t\t\t\t\t    NULL);\n \tif (cifs_req_cachep == NULL)\n \t\treturn -ENOMEM;\n \n@@ -1257,9 +1259,9 @@ cifs_init_request_bufs(void)\n \tmore SMBs to use small buffer alloc and is still much more\n \tefficient to alloc 1 per page off the slab compared to 17K (5page)\n \talloc of large cifs buffers even when page debugging is on */\n-\tcifs_sm_req_cachep = kmem_cache_create(\"cifs_small_rq\",\n+\tcifs_sm_req_cachep = kmem_cache_create_usercopy(\"cifs_small_rq\",\n \t\t\tMAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,\n-\t\t\tNULL);\n+\t\t\t0, MAX_CIFS_SMALL_BUFFER_SIZE, NULL);\n \tif (cifs_sm_req_cachep == NULL) {\n \t\tmempool_destroy(cifs_req_poolp);\n \t\tkmem_cache_destroy(cifs_req_cachep);\n","prefixes":["v3","16/31"]}