From patchwork Wed Sep 20 20:45:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9962545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 113BB60208 for ; Wed, 20 Sep 2017 20:55:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 027AC29224 for ; Wed, 20 Sep 2017 20:55:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8ABA2923B; Wed, 20 Sep 2017 20:55:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, URIBL_BLACK autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id DEE4929224 for ; Wed, 20 Sep 2017 20:55:02 +0000 (UTC) Received: (qmail 1812 invoked by uid 550); 20 Sep 2017 20:53:20 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 1501 invoked from network); 20 Sep 2017 20:53:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CXYChwRknSCs7CNYF3vt55npuxJ+mFEcectRpftsX+k=; b=Ox1qkWJHCDDvhDF2qFJICNHntgkb5UFIB1ItmTDC8fB/vmMpLpQQKAfQpxHmOwaSMs zAeU5gJrvRbH11lARg7B4aYwSyi+WMg9iG4djNvZpIKX1vvmHXQI+Dp6bg56n9p9+dWj UQOeM+P+GmT2Jb/W0ktxFxuPn7yLHqh0gNGUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CXYChwRknSCs7CNYF3vt55npuxJ+mFEcectRpftsX+k=; b=r5lr0DbV/YlN+OJH5qxRyfbHocM9KwNkyTizLHebZ/18iHZ61ptSPE+xjSslL9iM5w O5y9jz/AzMrZ+lgPlCxNeloYOia6kPGF57HhMPr5nE81RpFtMnMNqHCl1sXxAzL9YoEB xSlABbqzjxNOKagsUVYdtxf6TYgkfqCuFhmwJFLdwoZ7rfMz9j2JYwg7uIaOG10gLvKW MUoRPn6Hk6XAAXeTVqchyvJycPJBJORofocIsGYUz9nY1cIX9VPrAMo2LGYLXbCe/4Jy zq+YUgcEqqsCC26+ySusP6rP2334tkbLrdsx5PQDbR1VlMrxMu3ymx7CUVN/rTAxRDsH EJZA== X-Gm-Message-State: AHPjjUh6Ij9PI6lP0/HmYVLM/oEqriISubY/MJfb6ibBsxCSIDUYYsRD kssz8ylnfoy9JKR1I/eRLUYlDQ== X-Google-Smtp-Source: AOwi7QAqNQqFrIuTc2L/sXMwEanj7/7DWgD7cUTumvj6ZrVjFDk+jZ72o1cx/d7EwJjiofv3fkmvLQ== X-Received: by 10.99.186.74 with SMTP id l10mr3503035pgu.355.1505940778988; Wed, 20 Sep 2017 13:52:58 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , David Windsor , "David S. Miller" , Eric Dumazet , Paolo Abeni , David Howells , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Date: Wed, 20 Sep 2017 13:45:24 -0700 Message-Id: <1505940337-79069-19-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> Subject: [kernel-hardening] [PATCH v3 18/31] net: Define usercopy region in struct proto slab cache X-Virus-Scanned: ClamAV using ClamSMTP From: David Windsor In support of usercopy hardening, this patch defines a region in the struct proto slab cache in which userspace copy operations are allowed. Some protocols need to copy objects to/from userspace, and they can declare the region via their proto structure with the new usersize and useroffset fields. Initially, if no region is specified (usersize == 0), the entire field is marked as whitelisted. This allows protocols to be whitelisted in subsequent patches. Once all protocols have been annotated, the full-whitelist default can be removed. This region is known as the slab cache's usercopy region. Slab caches can now check that each copy operation involving cache-managed memory falls entirely within the slab's usercopy region. This patch is modified from Brad Spengler/PaX Team's PAX_USERCOPY whitelisting code in the last public patch of grsecurity/PaX based on my understanding of the code. Changes or omissions from the original code are mine and don't reflect the original grsecurity/PaX code. Signed-off-by: David Windsor [kees: adjust commit log, split off per-proto patches] [kees: add logic for by-default full-whitelist] Cc: "David S. Miller" Cc: Eric Dumazet Cc: Paolo Abeni Cc: David Howells Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- include/net/sock.h | 2 ++ net/core/sock.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/net/sock.h b/include/net/sock.h index 03a362568357..13c2d1b48c86 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1106,6 +1106,8 @@ struct proto { struct kmem_cache *slab; unsigned int obj_size; int slab_flags; + size_t useroffset; /* Usercopy region offset */ + size_t usersize; /* Usercopy region size */ struct percpu_counter *orphan_count; diff --git a/net/core/sock.c b/net/core/sock.c index 9b7b6bbb2a23..832dfb03102e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -3165,8 +3165,12 @@ static int req_prot_init(const struct proto *prot) int proto_register(struct proto *prot, int alloc_slab) { if (alloc_slab) { - prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, + prot->slab = kmem_cache_create_usercopy(prot->name, + prot->obj_size, 0, SLAB_HWCACHE_ALIGN | prot->slab_flags, + prot->usersize ? prot->useroffset : 0, + prot->usersize ? prot->usersize + : prot->obj_size, NULL); if (prot->slab == NULL) {